UPD version 0.9.12

This commit is contained in:
2023-11-12 22:56:20 +01:00
parent 616bf0ca31
commit f656fb70fa
15 changed files with 286 additions and 111 deletions

View File

@ -10,11 +10,14 @@
namespace KW4NZ\Component\Depot\Administrator\Model;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\MVC\Model\ListModel;
// use Joomla\CMS\Table\Table;
use Joomla\CMS\Table\Table;
use Joomla\Database\ParameterType;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
class PackagesModel extends ListModel
{
@ -36,6 +39,10 @@ class PackagesModel extends ListModel
'mounting_style',
'description',
'p.description',
'ordering',
'p.ordering',
'checked_out',
'p.checked_out',
];
parent::__construct($config);
}
@ -73,6 +80,12 @@ class PackagesModel extends ListModel
$db->quoteName('p.description'),
$db->quoteName('p.image'),
$db->quoteName('p.state'),
$db->quoteName('p.ordering'),
$db->quoteName('p.checked_out'),
$db->quoteName('p.checked_out_time'),
$db->quoteName('p.modified'),
$db->quoteName('p.modified_by'),
$db->quoteName('p.mounting_style_id'),
]
)
)
@ -104,10 +117,27 @@ class PackagesModel extends ListModel
}
// 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));
$query->order(
$db->quoteName($db->escape($this->getState('list.ordering', 'p.ordering'))) . ' ' .
$db->escape($this->getState('list.direction', 'ASC'))
);
return $query;
}
/**
* Returns a reference to the a Table object, always creating it.
*
* @param string $type The table type to instantiate
* @param string $prefix A prefix for the table class name. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return Table A Table object
*
* @since 1.6
*/
public function getTable($type = 'Package', $prefix = 'Administrator', $config = [])
{
return parent::getTable($type, $prefix, $config);
}
}

View File

@ -23,6 +23,8 @@ class PartsModel extends ListModel
$config['filter_fields'] = [
'id',
'd.id',
'state',
'd.state',
'component_name',
'd.component_name',
'alias',
@ -65,6 +67,7 @@ class PartsModel extends ListModel
'list.select',
[
$db->quoteName('d.id'),
$db->quoteName('d.state'),
$db->quoteName('d.component_name'),
$db->quoteName('d.alias'),
$db->quoteName('d.description'),

View File

@ -97,10 +97,10 @@ 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));
// Add the list ordering clause.
$query->order(
$db->quoteName($db->escape($this->getState('list.ordering', 'id'))) . ' ' . $db->escape($this->getState('list.direction', 'ASC'))
);
return $query;
}

View File

@ -26,6 +26,41 @@ class PackageTable extends Table
$this->setColumnAlias('published', 'state');
}
public function check()
{
try {
parent::check();
} catch (\Exception $e) {
$this->setError($e->getMessage());
return false;
}
// Set created date if not set.
if (!(int) $this->created) {
$this->created = Factory::getDate()->toSql();
}
// Set ordering
if ($this->state < 0) {
// Set ordering to 0 if state is archived or trashed
$this->ordering = 0;
} elseif (empty($this->ordering)) {
// Set ordering to last if ordering was 0
$this->ordering = self::getNextOrder($this->_db->quoteName('state') . ' >= 0');
}
// Set modified to created if not set
if ($this->modified) {
$this->modified = $this->created;
}
// Set modified_by to created_by if not set
if (empty($this->modified_by)) {
$this->modified_by = $this->created_by;
}
return true;
}
public function store($updateNulls = true)
{
$app = Factory::getApplication();
@ -56,18 +91,20 @@ class PackageTable extends Table
}
}
// Verify that the alias is unique
$table = $app->bootComponent('com_depot')->getMVCFactory()->createTable('Package', 'Administrator');
if ($table->load(['alias' => $this->alias]) && ($table->id != $this->id || $this->id == 0)) {
$this->setError('Alias is not unique.');
if ($table->state == -2) {
$this->setError('Alias is not unique. The item is in Trash.');
}
return false;
}
/***
if (!empty($this->alias)) {
// Verify that the alias is unique
$table = $app->bootComponent('com_depot')->getMVCFactory()->createTable('Package', 'Administrator');
if ($table->load(['alias' => $this->alias]) && ($table->id != $this->id || $this->id == 0)) {
$this->setError('Alias is not unique.');
if ($table->state == -2) {
$this->setError('Alias is not unique. The item is in Trash.');
}
return false;
}
}
*/
return parent::store($updateNulls);
}
}

View File

@ -10,35 +10,32 @@
namespace KW4NZ\Component\Depot\Administrator\View\Packages;
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
// use Joomla\CMS\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;
// use Joomla\CMS\Language\Text;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
class HtmlView extends BaseHtmlView
{
public function display($tpl = null)
{
// Get application
$app = Factory::getApplication();
/** @var PackagesModel $model */
$model = $this->getModel();
$this->items = $model->getItems();
$this->pagination = $model->getPagination();
$this->state = $model->getState();
$this->filterForm = $model->getFilterForm();
$this->activeFilters = $model->getActiveFilters();
$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'));
// add pagination
$this->pagination = $this->get('Pagination');
// adding filters
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) {
$this->setLayout('emptystate');
}
// set the toolbar
$this->addToolbar();

View File

@ -25,19 +25,13 @@ class HtmlView extends BaseHtmlView
{
public function display($tpl = null)
{
// Get application
$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'));
// add pagination
$this->pagination = $this->get('Pagination');
// adding filters
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
// Get model
$model = $this->getModel();
$this->items = $model->getItems();
$this->pagination = $model->getPagination();
$this->state = $model->getState();
$this->filterForm = $model->getFilterForm();
$this->activeFilters = $model->getActiveFilters();
// set the toolbar
$this->addToolbar();
@ -45,7 +39,7 @@ class HtmlView extends BaseHtmlView
parent::display($tpl);
}
protected function addToolbar()
protected function addToolbar(): void
{
ToolbarHelper::title(Text::_('COM_DEPOT_MANAGER_PARTS'));
ToolbarHelper::addNew('part.add');