cfmgrv4/app/Controllers/Admin/Cloudflare/AuthController.php
2024-10-04 11:50:44 +09:00

107 lines
3.9 KiB
PHP

<?php
namespace App\Controllers\Admin\Cloudflare;
use App\Libraries\MySocket\Cloudflare\AccountSocket;
use App\Models\Cloudflare\AuthModel;
use CodeIgniter\HTTP\DownloadResponse;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
use Psr\Log\LoggerInterface;
class AuthController extends CloudflareController
{
private $_model = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->class_name = "Auth";
$this->class_path = $this->root . $this->class_name;
$this->title = lang("{$this->class_path}.title");
helper($this->class_path);
}
final protected function getModel(): AuthModel
{
if ($this->_model === null) {
$this->_model = new AuthModel();
}
return $this->_model;
}
private function init(string $action): void
{
$this->action = $action;
$this->fields = [$this->getModel()::TITLE, 'authkey', 'status'];
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
$this->filter_fields = ['status'];
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
}
//생성
public function create_form(): RedirectResponse|string
{
$this->init('create');
return $this->create_form_procedure();
}
public function create(): RedirectResponse|string
{
$this->init(__FUNCTION__);
return $this->create_procedure($this->action_form);
}
//수정
public function modify_form(string $uid): RedirectResponse|string
{
$this->init('modify');
return $this->modify_form_procedure($uid);
}
public function modify(string $uid): RedirectResponse|string
{
$this->init(__FUNCTION__);
return $this->modify_procedure($uid, $this->action_form);
}
//일괄처리작업
public function batcjob(): RedirectResponse
{
$this->action = __FUNCTION__;
$this->fields = ['status'];
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
return $this->batcjob_procedure();
}
// 리스트
public function index(): string
{
$this->action = __FUNCTION__;
$this->fields = [$this->getModel()::TITLE, 'oldkey', 'status', 'updated_at', 'created_at'];
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
$this->filter_fields = ['status'];
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
$this->batchjob_fields = ['status'];
return $this->list_procedure();
}
// Download
public function download(string $output_type, $uid = false): DownloadResponse|string
{
$this->action = __FUNCTION__;
$this->fields = [$this->getModel()::TITLE, 'oldkey', 'status', 'updated_at', 'created_at'];
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
$this->filter_fields = ['status'];
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
$this->batchjob_fields = ['status'];
return $this->download_procedure($output_type, $uid);
}
//Account Reload by Auth
protected function reload_process(mixed $uid = false): void
{
if ($uid && intval($uid) > 0) {
$this->getModel()->where($this->getModel()::PK, intval($uid));
}
foreach ($this->getModel()->getEntitys() as $entity) {
$account_socket = new AccountSocket($entity);
$account_socket->reload();
}
}
public function reload(mixed $uid = false): RedirectResponse
{
return $this->reload_procedure($uid);
}
}