mirror of
https://github.com/Karaka-Management/oms-Auditor.git
synced 2026-02-10 02:58:41 +00:00
update settings
This commit is contained in:
parent
b11dd9821f
commit
6750e1caba
|
|
@ -11,7 +11,7 @@
|
|||
"create_collection": true,
|
||||
"name": "Default",
|
||||
"virtualPath": "/Modules/Auditor",
|
||||
"path": "/Modules/Media/Files/Modules/Auditor",
|
||||
"path": "/Modules/Auditor",
|
||||
"files": [
|
||||
"/Modules/Auditor/Admin/Install/Media/defaultReport.pdf.php"
|
||||
],
|
||||
|
|
|
|||
|
|
@ -61,7 +61,17 @@ final class ApiController extends Controller
|
|||
) : void
|
||||
{
|
||||
$newString = StringUtils::stringify($new, \JSON_PRETTY_PRINT);
|
||||
$audit = new Audit(new NullAccount($account), null, $newString, $type, $trigger, $module, $ref, $content, (int) \ip2long($ip ?? '127.0.0.1'));
|
||||
$audit = new Audit(
|
||||
new NullAccount($account),
|
||||
null,
|
||||
$newString,
|
||||
$type,
|
||||
$trigger,
|
||||
$module,
|
||||
$ref,
|
||||
$content,
|
||||
(int) \ip2long($ip ?? '127.0.0.1')
|
||||
);
|
||||
|
||||
AuditMapper::create()->execute($audit);
|
||||
}
|
||||
|
|
@ -104,7 +114,17 @@ final class ApiController extends Controller
|
|||
return;
|
||||
}
|
||||
|
||||
$audit = new Audit(new NullAccount($account), $oldString, $newString, $type, $trigger, $module, $ref, $content, (int) \ip2long($ip ?? '127.0.0.1'));
|
||||
$audit = new Audit(
|
||||
new NullAccount($account),
|
||||
$oldString,
|
||||
$newString,
|
||||
$type,
|
||||
$trigger,
|
||||
$module,
|
||||
$ref,
|
||||
$content,
|
||||
(int) \ip2long($ip ?? '127.0.0.1')
|
||||
);
|
||||
|
||||
AuditMapper::create()->execute($audit);
|
||||
}
|
||||
|
|
@ -141,7 +161,17 @@ final class ApiController extends Controller
|
|||
) : void
|
||||
{
|
||||
$oldString = StringUtils::stringify($old, \JSON_PRETTY_PRINT);
|
||||
$audit = new Audit(new NullAccount($account), $oldString, null, $type, $trigger, $module, $ref, $content, (int) \ip2long($ip ?? '127.0.0.1'));
|
||||
$audit = new Audit(
|
||||
new NullAccount($account),
|
||||
$oldString,
|
||||
null,
|
||||
$type,
|
||||
$trigger,
|
||||
$module,
|
||||
$ref,
|
||||
$content,
|
||||
(int) \ip2long($ip ?? '127.0.0.1')
|
||||
);
|
||||
|
||||
AuditMapper::create()->execute($audit);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,9 +14,11 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\Auditor\Controller;
|
||||
|
||||
use View\TableView;
|
||||
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;
|
||||
|
|
@ -50,22 +52,54 @@ final class BackendController extends Controller
|
|||
$view->setTemplate('/Modules/Auditor/Theme/Backend/audit-list');
|
||||
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1006201001, $request, $response));
|
||||
|
||||
if ($request->getData('ptype') === 'p') {
|
||||
$data = AuditMapper::getAll()->with('createdBy')->sort('id', OrderType::ASC)->where('id', (int) ($request->getData('id') ?? 0), '>')->limit(25)->execute();
|
||||
$pageLimit = 25;
|
||||
$view->addData('pageLimit', $pageLimit);
|
||||
|
||||
if (empty($data)) {
|
||||
$data = AuditMapper::getAll()->with('createdBy')->sort('id', OrderType::DESC)->where('id', 0, '>')->limit(25)->execute();
|
||||
} else {
|
||||
$data = \array_reverse($data);
|
||||
}
|
||||
$mapper = AuditMapper::getAll()->with('createdBy');
|
||||
$list = AuditMapper::getAuditList(
|
||||
$mapper,
|
||||
(int) ($request->getData('id') ?? 0),
|
||||
$request->getData('pType'),
|
||||
25
|
||||
);
|
||||
|
||||
$view->setData('audits', $data);
|
||||
} elseif ($request->getData('ptype') === 'n') {
|
||||
$view->setData('audits', AuditMapper::getAll()->with('createdBy')->sort('id', OrderType::DESC)->where('id', (int) ($request->getData('id') ?? 0), '<')->limit(25)->execute());
|
||||
} else {
|
||||
$view->setData('audits', AuditMapper::getAll()->with('createdBy')->sort('id', OrderType::DESC)->where('id', 0, '>')->limit(25)->execute());
|
||||
$view->setData('hasPrevious', $list['hasPrevious']);
|
||||
$view->setData('hasNext', $list['hasNext']);
|
||||
$view->setData('audits', $list['data']);
|
||||
|
||||
/** @var \Model\Setting[] $exportTemplates */
|
||||
$exportTemplates = $this->app->appSettings->get(
|
||||
names: [
|
||||
SettingsEnum::DEFAULT_PDF_EXPORT_TEMPLATE,
|
||||
SettingsEnum::DEFAULT_EXCEL_EXPORT_TEMPLATE,
|
||||
SettingsEnum::DEFAULT_CSV_EXPORT_TEMPLATE,
|
||||
SettingsEnum::DEFAULT_WORD_EXPORT_TEMPLATE,
|
||||
SettingsEnum::DEFAULT_EMAIL_EXPORT_TEMPLATE,
|
||||
],
|
||||
module: 'Admin'
|
||||
);
|
||||
|
||||
$templateIds = [];
|
||||
foreach ($exportTemplates as $template) {
|
||||
$templateIds[] = (int) $template->content;
|
||||
}
|
||||
|
||||
$mediaTemplates = MediaMapper::getAll()
|
||||
->where('id', $templateIds, 'in')
|
||||
->execute();
|
||||
|
||||
$tableView = new TableView($this->app->l11nManager, $request, $response);
|
||||
$tableView->module = 'Auditor';
|
||||
$tableView->theme = 'Backend';
|
||||
$tableView->setExportTemplate('/Web/Backend/Themes/popup-export-data');
|
||||
$tableView->setExportTemplates($mediaTemplates);
|
||||
$tableView->setColumnHeaderElementTemplate('/Web/Backend/Themes/header-element-table');
|
||||
$tableView->setFilterTemplate('/Web/Backend/Themes/popup-filter-table');
|
||||
$tableView->setSortTemplate('/Web/Backend/Themes/sort-table');
|
||||
$tableView->exportUri = '{/api}auditor/list/export';
|
||||
|
||||
$view->addData('tableView', $tableView);
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ namespace Modules\Auditor\Models;
|
|||
|
||||
use Modules\Admin\Models\AccountMapper;
|
||||
use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
|
||||
use phpOMS\DataStorage\Database\Query\OrderType;
|
||||
|
||||
/**
|
||||
* Mapper class.
|
||||
|
|
@ -91,4 +92,86 @@ 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
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,19 @@ use phpOMS\Uri\UriFactory;
|
|||
*/
|
||||
$audits = $this->getData('audits') ?? [];
|
||||
|
||||
$previous = empty($audits) ? '{/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=' . \end($audits)->getId() . '&ptype=n';
|
||||
$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';
|
||||
|
||||
echo $this->getData('nav')->render(); ?>
|
||||
|
||||
|
|
@ -34,108 +45,49 @@ echo $this->getData('nav')->render(); ?>
|
|||
<?= $this->getHtml('Audits'); ?>
|
||||
<a href="<?= UriFactory::build($next); ?>"><i class="fa fa-chevron-right btn"></i></a>
|
||||
</span>
|
||||
|
||||
<i class="fa fa-download floatRight download btn"></i></div>
|
||||
<?= $tableView->renderExport(); ?>
|
||||
</div>
|
||||
<div class="slider">
|
||||
<table id="auditList" class="default sticky">
|
||||
<table id="<?= $tableView->id; ?>" class="default sticky">
|
||||
<thead>
|
||||
<tr>
|
||||
<td><?= $this->getHtml('ID', '0', '0'); ?>
|
||||
<label for="auditList-sort-1">
|
||||
<input type="radio" name="auditList-sort" id="auditList-sort-1">
|
||||
<i class="sort-asc fa fa-chevron-up"></i>
|
||||
</label>
|
||||
<label for="auditList-sort-2">
|
||||
<input type="radio" name="auditList-sort" id="auditList-sort-2">
|
||||
<i class="sort-desc fa fa-chevron-down"></i>
|
||||
</label>
|
||||
<label>
|
||||
<i class="filter fa fa-filter"></i>
|
||||
</label>
|
||||
<td><?= $this->getHtml('Module'); ?>
|
||||
<label for="auditList-sort-3">
|
||||
<input type="radio" name="auditList-sort" id="auditList-sort-3">
|
||||
<i class="sort-asc fa fa-chevron-up"></i>
|
||||
</label>
|
||||
<label for="auditList-sort-4">
|
||||
<input type="radio" name="auditList-sort" id="auditList-sort-4">
|
||||
<i class="sort-desc fa fa-chevron-down"></i>
|
||||
</label>
|
||||
<label>
|
||||
<i class="filter fa fa-filter"></i>
|
||||
</label>
|
||||
<td><?= $this->getHtml('Action'); ?>
|
||||
<label for="auditList-sort-5">
|
||||
<input type="radio" name="auditList-sort" id="auditList-sort-5">
|
||||
<i class="sort-asc fa fa-chevron-up"></i>
|
||||
</label>
|
||||
<label for="auditList-sort-6">
|
||||
<input type="radio" name="auditList-sort" id="auditList-sort-6">
|
||||
<i class="sort-desc fa fa-chevron-down"></i>
|
||||
</label>
|
||||
<label>
|
||||
<i class="filter fa fa-filter"></i>
|
||||
</label>
|
||||
<td><?= $this->getHtml('Type'); ?>
|
||||
<label for="auditList-sort-7">
|
||||
<input type="radio" name="auditList-sort" id="auditList-sort-7">
|
||||
<i class="sort-asc fa fa-chevron-up"></i>
|
||||
</label>
|
||||
<label for="auditList-sort-8">
|
||||
<input type="radio" name="auditList-sort" id="auditList-sort-8">
|
||||
<i class="sort-desc fa fa-chevron-down"></i>
|
||||
</label>
|
||||
<label>
|
||||
<i class="filter fa fa-filter"></i>
|
||||
</label>
|
||||
<td class="wf-100"><?= $this->getHtml('Trigger'); ?>
|
||||
<label for="auditList-sort-9">
|
||||
<input type="radio" name="auditList-sort" id="auditList-sort-9">
|
||||
<i class="sort-asc fa fa-chevron-up"></i>
|
||||
</label>
|
||||
<label for="auditList-sort-10">
|
||||
<input type="radio" name="auditList-sort" id="auditList-sort-10">
|
||||
<i class="sort-desc fa fa-chevron-down"></i>
|
||||
</label>
|
||||
<label>
|
||||
<i class="filter fa fa-filter"></i>
|
||||
</label>
|
||||
<td><?= $this->getHtml('By'); ?>
|
||||
<label for="auditList-sort-13">
|
||||
<input type="radio" name="auditList-sort" id="auditList-sort-13">
|
||||
<i class="sort-asc fa fa-chevron-up"></i>
|
||||
</label>
|
||||
<label for="auditList-sort-14">
|
||||
<input type="radio" name="auditList-sort" id="auditList-sort-14">
|
||||
<i class="sort-desc fa fa-chevron-down"></i>
|
||||
</label>
|
||||
<label>
|
||||
<i class="filter fa fa-filter"></i>
|
||||
</label>
|
||||
<td><?= $this->getHtml('Ref'); ?>
|
||||
<label for="auditList-sort-15">
|
||||
<input type="radio" name="auditList-sort" id="auditList-sort-15">
|
||||
<i class="sort-asc fa fa-chevron-up"></i>
|
||||
</label>
|
||||
<label for="auditList-sort-16">
|
||||
<input type="radio" name="auditList-sort" id="auditList-sort-16">
|
||||
<i class="sort-desc fa fa-chevron-down"></i>
|
||||
</label>
|
||||
<label>
|
||||
<i class="filter fa fa-filter"></i>
|
||||
</label>
|
||||
<td><?= $this->getHtml('Date'); ?>
|
||||
<label for="auditList-sort-17">
|
||||
<input type="radio" name="auditList-sort" id="auditList-sort-17">
|
||||
<i class="sort-asc fa fa-chevron-up"></i>
|
||||
</label>
|
||||
<label for="auditList-sort-18">
|
||||
<input type="radio" name="auditList-sort" id="auditList-sort-18">
|
||||
<i class="sort-desc fa fa-chevron-down"></i>
|
||||
</label>
|
||||
<label>
|
||||
<i class="filter fa fa-filter"></i>
|
||||
</label>
|
||||
<td><?= $tableView->renderHeaderElement(
|
||||
$this->getHtml('ID', '0', '0'),
|
||||
'number'
|
||||
); ?>
|
||||
<td><?= $tableView->renderHeaderElement(
|
||||
$this->getHtml('Module'),
|
||||
'text'
|
||||
); ?>
|
||||
<td><?= $tableView->renderHeaderElement(
|
||||
$this->getHtml('Action'),
|
||||
'select',
|
||||
[
|
||||
'create' => $this->getHtml('CREATE'),
|
||||
'modify' => $this->getHtml('UPDATE'),
|
||||
'delete' => $this->getHtml('DELETE'),
|
||||
]
|
||||
); ?>
|
||||
<td><?= $tableView->renderHeaderElement(
|
||||
$this->getHtml('Type'),
|
||||
'number'
|
||||
); ?>
|
||||
<td class="wf-100"><?= $tableView->renderHeaderElement(
|
||||
$this->getHtml('Trigger'),
|
||||
'text'
|
||||
); ?>
|
||||
<td><?= $tableView->renderHeaderElement(
|
||||
$this->getHtml('By'),
|
||||
'text'
|
||||
); ?>
|
||||
<td><?= $tableView->renderHeaderElement(
|
||||
$this->getHtml('Ref'),
|
||||
'text'
|
||||
); ?>
|
||||
<td><?= $tableView->renderHeaderElement(
|
||||
$this->getHtml('Date'),
|
||||
'date'
|
||||
); ?>
|
||||
<tbody>
|
||||
<?php $count = 0;
|
||||
foreach ($audits as $key => $audit) : ++$count;
|
||||
|
|
@ -162,8 +114,8 @@ echo $this->getData('nav')->render(); ?>
|
|||
</table>
|
||||
</div>
|
||||
<div class="portlet-foot">
|
||||
<a tabindex="0" class="button" href="<?= UriFactory::build($previous); ?>"><?= $this->getHtml('Previous', '0', '0'); ?></a>
|
||||
<a tabindex="0" class="button" href="<?= UriFactory::build($next); ?>"><?= $this->getHtml('Next', '0', '0'); ?></a>
|
||||
<a tabindex="0" class="button" href="<?= UriFactory::build($previous); ?>"><i class="fa fa-chevron-left"></i></a>
|
||||
<a tabindex="0" class="button" href="<?= UriFactory::build($next); ?>"><i class="fa fa-chevron-right"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user