From 19fe0c0d1157e11cabf00b43abfe28c9dccc6b19 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 15 May 2022 22:20:49 +0200 Subject: [PATCH] drafting table functions --- Controller/BackendController.php | 19 +++++--- Models/Audit.php | 14 +++--- Models/AuditMapper.php | 83 -------------------------------- Theme/Backend/audit-list.tpl.php | 51 ++++++++++++++------ 4 files changed, 57 insertions(+), 110 deletions(-) diff --git a/Controller/BackendController.php b/Controller/BackendController.php index e5b3678..5c89a34 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -18,10 +18,11 @@ use Modules\Admin\Models\SettingsEnum; use Modules\Auditor\Models\AuditMapper; use Modules\Media\Models\MediaMapper; use phpOMS\Contract\RenderableInterface; +use phpOMS\DataStorage\Database\Query\OrderType; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; use phpOMS\Views\View; -use View\TableView; +use Web\Backend\Views\TableView; /** * Calendar controller class. @@ -56,11 +57,16 @@ final class BackendController extends Controller $view->addData('pageLimit', $pageLimit); $mapper = AuditMapper::getAll()->with('createdBy'); - $list = AuditMapper::getAuditList( - $mapper, - (int) ($request->getData('id') ?? 0), - $request->getData('pType'), - 25 + $list = AuditMapper::getDataList( + mapper: $mapper, + id: (int) ($request->getData('id') ?? 0), + secondaryId: (string) ($request->getData('subid') ?? ''), + type: $request->getData('pType'), + pageLimit: empty((int) ($request->getData('limit') ?? 0)) ? 100 : ((int) $request->getData('limit')), + sortBy: $request->getData('sort_by') ?? '', + sortOrder: $request->getData('sort_order') ?? OrderType::DESC, + search: $request->getData('search'), + searchFields: $request->getDataList('search_fields') ); $view->setData('hasPrevious', $list['hasPrevious']); @@ -91,6 +97,7 @@ final class BackendController extends Controller $tableView = new TableView($this->app->l11nManager, $request, $response); $tableView->module = 'Auditor'; $tableView->theme = 'Backend'; + $tableView->setTitleTemplate('/Web/Backend/Themes/table-title'); $tableView->setExportTemplate('/Web/Backend/Themes/popup-export-data'); $tableView->setExportTemplates($mediaTemplates); $tableView->setColumnHeaderElementTemplate('/Web/Backend/Themes/header-element-table'); diff --git a/Models/Audit.php b/Models/Audit.php index f3005c1..ae4474c 100755 --- a/Models/Audit.php +++ b/Models/Audit.php @@ -41,7 +41,7 @@ class Audit * @var int * @since 1.0.0 */ - private int $type; + public int $type; /** * Audit trigger. @@ -49,7 +49,7 @@ class Audit * @var string * @since 1.0.0 */ - private string $trigger; + public string $trigger; /** * Audit module. @@ -57,7 +57,7 @@ class Audit * @var null|string * @since 1.0.0 */ - private ?string $module; + public ?string $module; /** * Audit reference. @@ -67,7 +67,7 @@ class Audit * @var null|string * @since 1.0.0 */ - private ?string $ref; + public ?string $ref; /** * Audit content. @@ -77,7 +77,7 @@ class Audit * @var null|string * @since 1.0.0 */ - private ?string $content; + public ?string $content; /** * Old value. @@ -85,7 +85,7 @@ class Audit * @var null|string * @since 1.0.0 */ - private ?string $old; + public ?string $old; /** * New value. @@ -93,7 +93,7 @@ class Audit * @var null|string * @since 1.0.0 */ - private ?string $new; + public ?string $new; /** * Account. diff --git a/Models/AuditMapper.php b/Models/AuditMapper.php index b8a8e8d..9681ac9 100755 --- a/Models/AuditMapper.php +++ b/Models/AuditMapper.php @@ -16,7 +16,6 @@ namespace Modules\Auditor\Models; use Modules\Admin\Models\AccountMapper; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory; -use phpOMS\DataStorage\Database\Query\OrderType; /** * Mapper class. @@ -92,86 +91,4 @@ final class AuditMapper extends DataMapperFactory * @since 1.0.0 */ public const CREATED_AT = 'auditor_audit_created_at'; - - public static function getAuditList(mixed $mapper, int $id, string $type = null, int $pageLimit) : array - { - /** @var \Modules\Auditor\Models\Audit[] $data */ - $data = []; - - $hasPrevious = false; - $hasNext = false; - - if ($type === 'p') { - $cloned = clone $mapper; - $data = $mapper->sort('id', OrderType::ASC) - ->where('id', $id, '>=') - ->limit($pageLimit + 2) - ->execute(); - - if (($count = \count($data)) < 2) { - $data = $cloned->sort('id', OrderType::DESC) - ->where('id', 0, '>') - ->limit($pageLimit + 1) - ->execute(); - - $hasNext = $count > $pageLimit; - if ($hasNext) { - \array_pop($data); - --$count; - } - } else { - if (\reset($data)->getId() === $id) { - \array_shift($data); - $hasNext = true; - --$count; - } - - if ($count > $pageLimit) { - \array_pop($data); - $hasNext = true; - --$count; - - if ($count > $pageLimit) { - $hasPrevious = true; - \array_pop($data); - } - } - - $data = \array_reverse($data); - } - } elseif ($type === 'n') { - $data = $mapper->sort('id', OrderType::DESC) - ->where('id', $id, '<=') - ->limit($pageLimit + 2) - ->execute(); - - if (!empty($data)) { - if (\reset($data)->getId() === $id) { - \array_shift($data); - $hasPrevious = true; - } - - if (\count($data) > $pageLimit) { - \array_pop($data); - $hasNext = true; - } - } - } else { - $data = $mapper->sort('id', OrderType::DESC) - ->where('id', 0, '>') - ->limit($pageLimit + 1) - ->execute(); - - $hasNext = ($count = \count($data)) > $pageLimit; - if ($hasNext) { - \array_pop($data); - } - } - - return [ - 'hasPrevious' => $hasPrevious, - 'hasNext' => $hasNext, - 'data' => $data, - ]; - } } diff --git a/Theme/Backend/audit-list.tpl.php b/Theme/Backend/audit-list.tpl.php index a5a2bfc..4866b38 100755 --- a/Theme/Backend/audit-list.tpl.php +++ b/Theme/Backend/audit-list.tpl.php @@ -20,20 +20,27 @@ use phpOMS\Uri\UriFactory; */ $audits = $this->getData('audits') ?? []; -$previous = empty($audits) || !$this->getData('hasPrevious') - ? '{/prefix}admin/audit/list' - : '{/prefix}admin/audit/list?{?}&id=' - . \reset($audits)->getId() - . '&ptype=p'; -$next = empty($audits) - ? '{/prefix}admin/audit/list' - : '{/prefix}admin/audit/list?{?}&id=' - . ($this->getData('hasNext') ? \end($audits)->getId() : $this->request->getData('id')) - . '&ptype=n'; - $tableView = $this->getData('tableView'); $tableView->id = 'auditList'; +$previous = $tableView->getPreviousLink( + '{/prefix}admin/audit/list', + $this->request, + empty($audits) || !$this->getData('hasPrevious') ? null : \reset($audits) +); + +$next = $tableView->getNextLink( + '{/prefix}admin/audit/list', + $this->request, + empty($audits) ? null : \end($audits), + $this->getData('hasNext') ?? false +); + +$search = $tableView->getSearchLink( + '{/prefix}admin/audit/list', + 'iSearchBoxTable' +); + echo $this->getData('nav')->render(); ?>
@@ -41,9 +48,16 @@ echo $this->getData('nav')->render(); ?>
- + getHtml('Audits'); ?> - + + + + + + + + renderExport(); ?>
@@ -52,39 +66,48 @@ echo $this->getData('nav')->render(); ?> renderHeaderElement( + 'id', $this->getHtml('ID', '0', '0'), 'number' ); ?> renderHeaderElement( + 'module', $this->getHtml('Module'), 'text' ); ?> renderHeaderElement( + 'action', $this->getHtml('Action'), 'select', [ 'create' => $this->getHtml('CREATE'), 'modify' => $this->getHtml('UPDATE'), 'delete' => $this->getHtml('DELETE'), - ] + ], + false // don't render sort ); ?> renderHeaderElement( + 'type', $this->getHtml('Type'), 'number' ); ?> renderHeaderElement( + 'trigger', $this->getHtml('Trigger'), 'text' ); ?> renderHeaderElement( + 'createdBy', $this->getHtml('By'), 'text' ); ?> renderHeaderElement( + 'ref', $this->getHtml('Ref'), 'text' ); ?> renderHeaderElement( + 'createdAt', $this->getHtml('Date'), 'date' ); ?>