Ordering and search, no pagination yet

This commit is contained in:
2023-10-31 23:25:42 +01:00
parent 6d03c99a34
commit 3f72ee89ca
30 changed files with 466 additions and 107 deletions

View File

@ -0,0 +1,31 @@
<?php
/**
* @package Depot.Administrator
* @subpackage com_depot
* @author Thomas Kuschel <thomas@kuschel.at>
* @copyright (C) 2023 KW4NZ, <https://www.kuschel.at>
* @license GNU General Public License version 2 or later; see LICENSE.md
* @since 0.9.9
*/
namespace KW4NZ\Component\Depot\Administrator\Controller;
use Joomla\CMS\MVC\Controller\AdminController;
defined('_JEXEC') or die;
class ManufacturersController extends AdminController
{
/**
* The prefix to use with controller messages.
*
* @var string
* @since 0.9.9
*/
protected $text_prefix = 'COM_DEPOT_MANUFACTURERS';
public function getModel($name = 'Manufacturer', $prefix = 'Administrator', $config = ['ignore_request' => true])
{
return parent::getModel($name, $prefix, $config);
}
}

View File

@ -16,4 +16,5 @@ defined('_JEXEC') or die;
class PackageController extends FormController
{
protected $text_prefix = 'COM_DEPOT_PACKAGE';
}

View File

@ -0,0 +1,31 @@
<?php
/**
* @package Depot.Administrator
* @subpackage com_depot
* @author Thomas Kuschel <thomas@kuschel.at>
* @copyright (C) 2023 KW4NZ, <https://www.kuschel.at>
* @license GNU General Public License version 2 or later; see LICENSE.md
* @since 0.9.9
*/
namespace KW4NZ\Component\Depot\Administrator\Controller;
use Joomla\CMS\MVC\Controller\AdminController;
defined('_JEXEC') or die;
class PackagesController extends AdminController
{
/**
* The prefix to use with controller messages.
*
* @var string
* @since 0.9.9
*/
protected $text_prefix = 'COM_DEPOT_PACKAGES';
public function getModel($name = 'Package', $prefix = 'Administrator', $config = ['ignore_request' => true])
{
return parent::getModel($name, $prefix, $config);
}
}

View File

@ -16,4 +16,5 @@ defined('_JEXEC') or die;
class StockController extends FormController
{
protected $text_prefix = 'COM_DEPOT_STOCK';
}

View File

@ -0,0 +1,31 @@
<?php
/**
* @package Depot.Administrator
* @subpackage com_depot
* @author Thomas Kuschel <thomas@kuschel.at>
* @copyright (C) 2023 KW4NZ, <https://www.kuschel.at>
* @license GNU General Public License version 2 or later; see LICENSE.md
* @since 0.9.9
*/
namespace KW4NZ\Component\Depot\Administrator\Controller;
use Joomla\CMS\MVC\Controller\AdminController;
defined('_JEXEC') or die;
class StocksController extends AdminController
{
/**
* The prefix to use with controller messages.
*
* @var string
* @since 0.9.9
*/
protected $text_prefix = 'COM_DEPOT_STOCKS';
public function getModel($name = 'Stock', $prefix = 'Administrator', $config = ['ignore_request' => true])
{
return parent::getModel($name, $prefix, $config);
}
}

View File

@ -18,6 +18,30 @@ use Joomla\Database\ParameterType;
class ManufacturersModel extends ListModel
{
public function __construct($config = [])
{
$config['filter_fields'] = [
'id',
'm.id',
'name_short',
'm.name_short',
'name_long',
'm.name_long',
'alias',
'm.alias',
'state',
'm.state',
'published',
'm.published',
'description',
'm.descrition',
'image',
'm.image',
];
parent::__construct($config);
}
/**
* Build an SQL query to load the list data.
*
@ -79,6 +103,11 @@ class ManufacturersModel extends ListModel
$query->where($db->quoteName('m.state') . ' IN (0, 1)');
}
// add list ordering clause
$orderCol = $this->state->get('list.ordering', 'id');
$orderDirn = $this->state->get('list.direction', 'asc');
$query->order($db->escape($orderCol) . ' ' . $db->escape($orderDirn));
return $query;
}
}

View File

@ -18,6 +18,28 @@ use Joomla\Database\ParameterType;
class PackagesModel extends ListModel
{
public function __construct($config = [])
{
$config['filter_fields'] = [
'id',
'p.id',
'name',
'p.name',
'alias',
'p.alias',
'state',
'p.state',
'published',
'p.published',
'mounting_style_id',
'p.mounting_style_id',
'mounting_style',
'description',
'p.description',
];
parent::__construct($config);
}
/**
* Build an SQL query to load the list data.
*
@ -81,6 +103,11 @@ class PackagesModel extends ListModel
$query->where($db->quoteName('p.state') . ' IN (0, 1)');
}
// add list ordering clause
$orderCol = $this->state->get('list.ordering', 'id');
$orderDirn = $this->state->get('list.direction', 'asc');
$query->order($db->escape($orderCol) . ' ' . $db->escape($orderDirn));
return $query;
}
}

View File

@ -18,6 +18,25 @@ use Joomla\Database\ParameterType;
class PartsModel extends ListModel
{
public function __construct($config = [])
{
$config['filter_fields'] = [
'id',
'd.id',
'component_name',
'd.component_name',
'alias',
'd.alias',
'quantity',
'd.quantity',
'published',
'd.published',
'package',
'manufacturer',
'stock_name',
];
parent::__construct($config);
}
/**
* Build an SQL query to load the list data.
*
@ -65,6 +84,7 @@ class PartsModel extends ListModel
$db->quoteName('p.name', 'package_name'),
$db->quoteName('p.description', 'package_description'),
$db->quoteName('ms.title', 'mounting_style'),
$db->quoteName('v.name', 'owner'),
]
)
->from($db->quoteName('#__depot', 'd'))
@ -72,7 +92,8 @@ class PartsModel extends ListModel
->join('LEFT', $db->quoteName('#__depot_stock', 's'), $db->quoteName('s.id') . ' = ' . $db->quoteName('d.stock_id'))
->join('LEFT', $db->quoteName('#__depot_package', 'p'), $db->quoteName('p.id') . ' = ' . $db->quoteName('d.package_id'))
->join('LEFT', $db->quoteName('#__users', 'u'), $db->quoteName('u.id') . ' = ' . $db->quoteName('d.checked_out'))
->join('LEFT', $db->quoteName('#__depot_mounting_style', 'ms'), $db->quoteName('ms.id') . ' = ' . $db->quoteName('p.mounting_style_id'));
->join('LEFT', $db->quoteName('#__depot_mounting_style', 'ms'), $db->quoteName('ms.id') . ' = ' . $db->quoteName('p.mounting_style_id'))
->join('LEFT', $db->quoteName('#__users', 'v'), $db->quoteName('v.id') . ' = ' . $db->quoteName('s.owner_id'));
// filter: like / search
$search = $this->getState('filter.search');
if (!empty($search)) {
@ -86,10 +107,14 @@ class PartsModel extends ListModel
$query->where($db->quoteName('d.state') . ' = :published')
->bind(':published', $published, ParameterType::INTEGER);
} elseif ($published === '') {
//$query->where($db->quoteName('d.state') . ' IN (0, 1)');
$query->whereIn($db->quoteName('d.state'), [0, 1]);
}
// add list ordering clause
$orderCol = $this->state->get('list.ordering', 'id');
$orderDirn = $this->state->get('list.direction', 'desc');
$query->order($db->escape($orderCol) . ' ' . $db->escape($orderDirn));
return $query;
}
}

View File

@ -53,7 +53,7 @@ class StockModel extends AdminModel
/* replaced by: */
if (empty($data['alias'])) {
$data['alias'] = ApplicationHelper::stringURLSafe($data['name_short']);
$data['alias'] = ApplicationHelper::stringURLSafe($data['owner_id'] . '-' . $data['name']);
}
$result = parent::save($data);
// if ($result) {

View File

@ -18,6 +18,23 @@ use Joomla\Database\ParameterType;
class StocksModel extends ListModel
{
public function __construct($config = [])
{
$config['filter_fields'] = [
'id',
's.id',
's.name',
'name',
'alias',
's.alias',
's.description',
'description',
'published',
'd.published',
'owner',
];
parent::__construct($config);
}
/**
* Build an SQL query to load the list data.
*
@ -55,10 +72,13 @@ class StocksModel extends ListModel
->select(
[
$db->quoteName('u.name', 'creator'),
$db->quoteName('o.name', 'owner'),
$db->quoteName('o.username', 'owner_username'),
]
)
->from($db->quoteName('#__depot_stock', 's'))
->join('LEFT', $db->quoteName('#__users', 'u'), $db->quoteName('u.id') . ' = ' . $db->quoteName('s.checked_out'));
->join('LEFT', $db->quoteName('#__users', 'u'), $db->quoteName('u.id') . ' = ' . $db->quoteName('s.checked_out'))
->join('LEFT', $db->quoteName('#__users', 'o'), $db->quoteName('o.id') . ' = ' . $db->quoteName('s.owner_id'));
// filter: like / search
$search = $this->getState('filter.search');
if (!empty($search)) {
@ -77,6 +97,11 @@ class StocksModel extends ListModel
$query->where($db->quoteName('s.state') . ' IN (0, 1)');
}
// add list ordering clause
$orderCol = $this->state->get('list.ordering', 'id');
$orderDirn = $this->state->get('list.direction', 'asc');
$query->order($db->escape($orderCol) . ' ' . $db->escape($orderDirn));
return $query;
}
}

View File

@ -29,6 +29,10 @@ class HtmlView extends BaseHtmlView
$app = Factory::getApplication();
$this->items = $this->get('Items');
$this->state = $this->get('State');
// list order
$this->listOrder = $this->escape($this->state->get('list.ordering'));
$this->listDirn = $this->escape($this->state->get('list.direction'));
// adding filters
$this->filterForm = $this->get('FilterForm');

View File

@ -29,6 +29,10 @@ class HtmlView extends BaseHtmlView
$app = Factory::getApplication();
$this->items = $this->get('Items');
$this->state = $this->get('State');
// list order
$this->listOrder = $this->escape($this->state->get('list.ordering'));
$this->listDirn = $this->escape($this->state->get('list.direction'));
// adding filters
$this->filterForm = $this->get('FilterForm');

View File

@ -29,6 +29,10 @@ class HtmlView extends BaseHtmlView
$app = Factory::getApplication();
$this->items = $this->get('Items');
$this->state = $this->get('State');
// list order
$this->listOrder = $this->escape($this->state->get('list.ordering'));
$this->listDirn = $this->escape($this->state->get('list.direction'));
// adding filters
$this->filterForm = $this->get('FilterForm');

View File

@ -29,7 +29,10 @@ class HtmlView extends BaseHtmlView
$app = Factory::getApplication();
$this->items = $this->get('Items');
$this->state = $this->get('State');
// list order
$this->listOrder = $this->escape($this->state->get('list.ordering'));
$this->listDirn = $this->escape($this->state->get('list.direction'));
// adding filters
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');