cfmgrv4/app/Controllers/Admin/Cloudflare/AuditLogController.php
2024-10-25 17:31:16 +09:00

80 lines
2.8 KiB
PHP

<?php
namespace App\Controllers\Admin\Cloudflare;
use App\Helpers\Cloudflare\AuditLogHelper;
use App\Models\Cloudflare\AuditLogModel;
use App\Services\Cloudflare\AuditLogService;
use CodeIgniter\HTTP\DownloadResponse;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
class AuditLogController extends CloudflareController
{
private $_auth_entity = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->title = lang("{$this->getService()->class_path}.title");
$this->helper = new AuditLogHelper();
}
protected function getModel(): AuditLogModel
{
if ($this->_model === null) {
$this->_model = new AuditLogModel();
}
return $this->_model;
}
protected function getService(): AuditLogService
{
if ($this->service === null) {
$this->service = new AuditLogService();
}
return $this->service;
}
protected function getFormFieldOption(string $field, array $options = []): array
{
switch ($field) {
case $this->getModel()::PARENT:
// $this->getZoneModel()->where('status', 'active');
$options[$field] = $this->getZoneModel()->getFormFieldOption($field);
// echo $this->getAccountModel()->getLastQuery();
// dd($options);
break;
default:
$options = parent::getFormFieldOption($field, $options);
break;
}
return $options;
}
private function init(string $action, array $fields = []): void
{
$this->action = $action;
$this->fields = count($fields) ? $fields : [$this->getModel()::PARENT, $this->getModel()::TITLE, 'actor', 'interface', 'resource_id', 'resource_type', 'status', 'updated_at', 'created_at'];
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
$this->filter_fields = [$this->getModel()::PARENT, 'status'];
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
$this->batchjob_fields = [];
}
//View
public function view(string $uid): RedirectResponse|string
{
$this->init(__FUNCTION__);
return $this->view_procedure($uid);
}
// 리스트
public function index(): string
{
$this->init(__FUNCTION__);
return $this->list_procedure();
}
// Download
public function download(string $output_type, mixed $uid = false): DownloadResponse|string
{
$this->init(__FUNCTION__);
return $this->download_procedure($output_type, $uid);
}
}