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

@ -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;
}
}