mirror of
https://github.com/Karaka-Management/oms-Auditor.git
synced 2026-02-16 13:38:41 +00:00
drafting table functions
This commit is contained in:
parent
382d2d72ec
commit
19fe0c0d11
|
|
@ -18,10 +18,11 @@ use Modules\Admin\Models\SettingsEnum;
|
||||||
use Modules\Auditor\Models\AuditMapper;
|
use Modules\Auditor\Models\AuditMapper;
|
||||||
use Modules\Media\Models\MediaMapper;
|
use Modules\Media\Models\MediaMapper;
|
||||||
use phpOMS\Contract\RenderableInterface;
|
use phpOMS\Contract\RenderableInterface;
|
||||||
|
use phpOMS\DataStorage\Database\Query\OrderType;
|
||||||
use phpOMS\Message\RequestAbstract;
|
use phpOMS\Message\RequestAbstract;
|
||||||
use phpOMS\Message\ResponseAbstract;
|
use phpOMS\Message\ResponseAbstract;
|
||||||
use phpOMS\Views\View;
|
use phpOMS\Views\View;
|
||||||
use View\TableView;
|
use Web\Backend\Views\TableView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calendar controller class.
|
* Calendar controller class.
|
||||||
|
|
@ -56,11 +57,16 @@ final class BackendController extends Controller
|
||||||
$view->addData('pageLimit', $pageLimit);
|
$view->addData('pageLimit', $pageLimit);
|
||||||
|
|
||||||
$mapper = AuditMapper::getAll()->with('createdBy');
|
$mapper = AuditMapper::getAll()->with('createdBy');
|
||||||
$list = AuditMapper::getAuditList(
|
$list = AuditMapper::getDataList(
|
||||||
$mapper,
|
mapper: $mapper,
|
||||||
(int) ($request->getData('id') ?? 0),
|
id: (int) ($request->getData('id') ?? 0),
|
||||||
$request->getData('pType'),
|
secondaryId: (string) ($request->getData('subid') ?? ''),
|
||||||
25
|
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']);
|
$view->setData('hasPrevious', $list['hasPrevious']);
|
||||||
|
|
@ -91,6 +97,7 @@ final class BackendController extends Controller
|
||||||
$tableView = new TableView($this->app->l11nManager, $request, $response);
|
$tableView = new TableView($this->app->l11nManager, $request, $response);
|
||||||
$tableView->module = 'Auditor';
|
$tableView->module = 'Auditor';
|
||||||
$tableView->theme = 'Backend';
|
$tableView->theme = 'Backend';
|
||||||
|
$tableView->setTitleTemplate('/Web/Backend/Themes/table-title');
|
||||||
$tableView->setExportTemplate('/Web/Backend/Themes/popup-export-data');
|
$tableView->setExportTemplate('/Web/Backend/Themes/popup-export-data');
|
||||||
$tableView->setExportTemplates($mediaTemplates);
|
$tableView->setExportTemplates($mediaTemplates);
|
||||||
$tableView->setColumnHeaderElementTemplate('/Web/Backend/Themes/header-element-table');
|
$tableView->setColumnHeaderElementTemplate('/Web/Backend/Themes/header-element-table');
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ class Audit
|
||||||
* @var int
|
* @var int
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private int $type;
|
public int $type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Audit trigger.
|
* Audit trigger.
|
||||||
|
|
@ -49,7 +49,7 @@ class Audit
|
||||||
* @var string
|
* @var string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private string $trigger;
|
public string $trigger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Audit module.
|
* Audit module.
|
||||||
|
|
@ -57,7 +57,7 @@ class Audit
|
||||||
* @var null|string
|
* @var null|string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private ?string $module;
|
public ?string $module;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Audit reference.
|
* Audit reference.
|
||||||
|
|
@ -67,7 +67,7 @@ class Audit
|
||||||
* @var null|string
|
* @var null|string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private ?string $ref;
|
public ?string $ref;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Audit content.
|
* Audit content.
|
||||||
|
|
@ -77,7 +77,7 @@ class Audit
|
||||||
* @var null|string
|
* @var null|string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private ?string $content;
|
public ?string $content;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Old value.
|
* Old value.
|
||||||
|
|
@ -85,7 +85,7 @@ class Audit
|
||||||
* @var null|string
|
* @var null|string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private ?string $old;
|
public ?string $old;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* New value.
|
* New value.
|
||||||
|
|
@ -93,7 +93,7 @@ class Audit
|
||||||
* @var null|string
|
* @var null|string
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
private ?string $new;
|
public ?string $new;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Account.
|
* Account.
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ namespace Modules\Auditor\Models;
|
||||||
|
|
||||||
use Modules\Admin\Models\AccountMapper;
|
use Modules\Admin\Models\AccountMapper;
|
||||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||||
use phpOMS\DataStorage\Database\Query\OrderType;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mapper class.
|
* Mapper class.
|
||||||
|
|
@ -92,86 +91,4 @@ final class AuditMapper extends DataMapperFactory
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public const CREATED_AT = 'auditor_audit_created_at';
|
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,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,20 +20,27 @@ use phpOMS\Uri\UriFactory;
|
||||||
*/
|
*/
|
||||||
$audits = $this->getData('audits') ?? [];
|
$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 = $this->getData('tableView');
|
||||||
$tableView->id = 'auditList';
|
$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(); ?>
|
echo $this->getData('nav')->render(); ?>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
@ -41,9 +48,16 @@ echo $this->getData('nav')->render(); ?>
|
||||||
<div class="portlet">
|
<div class="portlet">
|
||||||
<div class="portlet-head">
|
<div class="portlet-head">
|
||||||
<span>
|
<span>
|
||||||
<a href="<?= UriFactory::build($previous); ?>"><i class="fa fa-chevron-left btn"></i></a>
|
<a rel="prefetch" href="<?= UriFactory::build($previous); ?>"><i class="fa fa-chevron-left btn"></i></a>
|
||||||
<?= $this->getHtml('Audits'); ?>
|
<?= $this->getHtml('Audits'); ?>
|
||||||
<a href="<?= UriFactory::build($next); ?>"><i class="fa fa-chevron-right btn"></i></a>
|
<a rel="prefetch" href="<?= UriFactory::build($next); ?>"><i class="fa fa-chevron-right btn"></i></a>
|
||||||
|
<span role="search" class="inputWrapper">
|
||||||
|
<span class="textWrapper">
|
||||||
|
<input id="iSearchBoxTable" name="search" type="text" autocomplete="off" value="<?= $this->request->getData('search') ?? ''; ?>" autofocus>
|
||||||
|
<i class="endIcon fa fa-times fa-lg fa-fw" aria-hidden="true"></i>
|
||||||
|
</span>
|
||||||
|
<a class="button" href="<?= UriFactory::build($search); ?>&search={#iSearchBoxTable}"><i class="frontIcon fa fa-search fa-fw" aria-hidden="true"></i></a>
|
||||||
|
</span>
|
||||||
</span>
|
</span>
|
||||||
<?= $tableView->renderExport(); ?>
|
<?= $tableView->renderExport(); ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -52,39 +66,48 @@ echo $this->getData('nav')->render(); ?>
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?= $tableView->renderHeaderElement(
|
<td><?= $tableView->renderHeaderElement(
|
||||||
|
'id',
|
||||||
$this->getHtml('ID', '0', '0'),
|
$this->getHtml('ID', '0', '0'),
|
||||||
'number'
|
'number'
|
||||||
); ?>
|
); ?>
|
||||||
<td><?= $tableView->renderHeaderElement(
|
<td><?= $tableView->renderHeaderElement(
|
||||||
|
'module',
|
||||||
$this->getHtml('Module'),
|
$this->getHtml('Module'),
|
||||||
'text'
|
'text'
|
||||||
); ?>
|
); ?>
|
||||||
<td><?= $tableView->renderHeaderElement(
|
<td><?= $tableView->renderHeaderElement(
|
||||||
|
'action',
|
||||||
$this->getHtml('Action'),
|
$this->getHtml('Action'),
|
||||||
'select',
|
'select',
|
||||||
[
|
[
|
||||||
'create' => $this->getHtml('CREATE'),
|
'create' => $this->getHtml('CREATE'),
|
||||||
'modify' => $this->getHtml('UPDATE'),
|
'modify' => $this->getHtml('UPDATE'),
|
||||||
'delete' => $this->getHtml('DELETE'),
|
'delete' => $this->getHtml('DELETE'),
|
||||||
]
|
],
|
||||||
|
false // don't render sort
|
||||||
); ?>
|
); ?>
|
||||||
<td><?= $tableView->renderHeaderElement(
|
<td><?= $tableView->renderHeaderElement(
|
||||||
|
'type',
|
||||||
$this->getHtml('Type'),
|
$this->getHtml('Type'),
|
||||||
'number'
|
'number'
|
||||||
); ?>
|
); ?>
|
||||||
<td class="wf-100"><?= $tableView->renderHeaderElement(
|
<td class="wf-100"><?= $tableView->renderHeaderElement(
|
||||||
|
'trigger',
|
||||||
$this->getHtml('Trigger'),
|
$this->getHtml('Trigger'),
|
||||||
'text'
|
'text'
|
||||||
); ?>
|
); ?>
|
||||||
<td><?= $tableView->renderHeaderElement(
|
<td><?= $tableView->renderHeaderElement(
|
||||||
|
'createdBy',
|
||||||
$this->getHtml('By'),
|
$this->getHtml('By'),
|
||||||
'text'
|
'text'
|
||||||
); ?>
|
); ?>
|
||||||
<td><?= $tableView->renderHeaderElement(
|
<td><?= $tableView->renderHeaderElement(
|
||||||
|
'ref',
|
||||||
$this->getHtml('Ref'),
|
$this->getHtml('Ref'),
|
||||||
'text'
|
'text'
|
||||||
); ?>
|
); ?>
|
||||||
<td><?= $tableView->renderHeaderElement(
|
<td><?= $tableView->renderHeaderElement(
|
||||||
|
'createdAt',
|
||||||
$this->getHtml('Date'),
|
$this->getHtml('Date'),
|
||||||
'date'
|
'date'
|
||||||
); ?>
|
); ?>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user