ADD filtering and searching 0.9.7

This commit is contained in:
2023-10-29 21:48:49 +01:00
parent 372fdada98
commit 6d03c99a34
26 changed files with 884 additions and 53 deletions

View File

@ -0,0 +1,64 @@
<?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.7
*/
namespace KW4NZ\Component\Depot\Administrator\Model;
use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\AdminModel;
\defined('_JEXEC') or die;
class PackageModel extends AdminModel
{
public function getForm($data = [], $loadData = true)
{
$form = $this->loadForm('com_depot.package', 'package', ['control' => 'jform', 'load_data' => $loadData]);
if (empty($form)) {
return false;
}
return $form;
}
protected function loadFormData()
{
$app = Factory::getApplication();
$data = $app->getUserState('com_depot.edit.package.data', []);
if (empty($data)) {
$data = $this->getItem();
}
return $data;
}
public function save($data)
{
/* Add code to modify data before saving */
// if (Factory::getConfig()->get('unicodeslugs') == 1) {
// $data['alias'] = OutputFilter::stringURLUnicodeSlug($data['component_name']);
// } else {
// $data['alias'] = OutputFilter::stringURLSafe($data['component_name']);
// }
/* replaced by: */
if (empty($data['alias'])) {
$data['alias'] = ApplicationHelper::stringURLSafe($data['name']);
}
$result = parent::save($data);
// if ($result) {
// $this->getTable('', 'Administrator')->rebuild(1);
// }
return $result;
}
}

View File

@ -0,0 +1,86 @@
<?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.7
*/
namespace KW4NZ\Component\Depot\Administrator\Model;
use Joomla\CMS\MVC\Model\ListModel;
// use Joomla\CMS\Table\Table;
use Joomla\Database\ParameterType;
\defined('_JEXEC') or die;
class PackagesModel extends ListModel
{
/**
* Build an SQL query to load the list data.
*
* @return \Joomla\Database\DatabaseQuery
*
* @since 1.6
*/
protected function getListQuery()
{
$db = $this->getDatabase();
$query = $db->getQuery(true);
// $query->select('*')
// ->from($db->quoteName('#__depot', 'd'));
// order by
// $query->order('d.id ASC');
// if (true) {
// return $query;
// }
// select the required fields from the table
$query->select(
$this->getState(
'list.select',
[
$db->quoteName('p.id'),
$db->quoteName('p.name'),
$db->quoteName('p.alias'),
$db->quoteName('p.description'),
$db->quoteName('p.image'),
$db->quoteName('p.state'),
]
)
)
->select(
[
$db->quoteName('u.name', 'creator'),
$db->quoteName('ms.title', 'mounting_style'),
]
)
->from($db->quoteName('#__depot_package', 'p'))
->join('LEFT', $db->quoteName('#__users', 'u'), $db->quoteName('u.id') . ' = ' . $db->quoteName('p.checked_out'))
->join('LEFT', $db->quoteName('#__depot_mounting_style', 'ms'), $db->quoteName('ms.id') . ' = ' . $db->quoteName('p.mounting_style_id'));
// filter: like / search
$search = $this->getState('filter.search');
if (!empty($search)) {
$like = $db->quote('%' . $search . '%');
$query->where($db->quoteName('p.name') . ' LIKE ' . $like);
}
// Filter by published state
$published = (string) $this->getState('filter.published');
if (is_numeric($published)) {
$published = (int) $published;
$query->where($db->quoteName('p.state') . ' = :published')
->bind(':published', $published, ParameterType::INTEGER);
} elseif ($published === '') {
$query->where($db->quoteName('p.state') . ' IN (0, 1)');
}
return $query;
}
}

View File

@ -52,6 +52,7 @@ class PartsModel extends ListModel
$db->quoteName('d.quantity'),
$db->quoteName('d.quantity_exp'),
$db->quoteName('d.ordering'),
$db->quoteName('d.package_id'),
]
)
)
@ -61,13 +62,17 @@ class PartsModel extends ListModel
$db->quoteName('m.name_short', 'manufacturer'),
$db->quoteName('m.name_long', 'manufacturer_long'),
$db->quoteName('s.name', 'stock_name'),
$db->quoteName('p.name', 'package_name'),
$db->quoteName('p.description', 'package_description'),
$db->quoteName('ms.title', 'mounting_style'),
]
)
->from($db->quoteName('#__depot', 'd'))
->join('LEFT', $db->quoteName('#__depot_manufacturer', 'm'), $db->quoteName('m.id') . ' = ' . $db->quoteName('d.manufacturer_id'))
->join('LEFT', $db->quoteName('#__depot_stock', 's'), $db->quoteName('s.id') . ' = ' . $db->quoteName('d.stock_id'))
->join('LEFT', $db->quoteName('#__users', 'u'), $db->quoteName('u.id') . ' = ' . $db->quoteName('d.checked_out'));
->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'));
// filter: like / search
$search = $this->getState('filter.search');
if (!empty($search)) {