cfmgrv4/app/Controllers/Admin/Cloudflare/AccountController.php
2024-09-30 19:25:19 +09:00

88 lines
3.4 KiB
PHP

<?php
namespace App\Controllers\Admin\Cloudflare;
use Psr\Log\LoggerInterface;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\RedirectResponse;
use App\Models\Cloudflare\AccountModel;
use App\Libraries\MySocket\Cloudflare\ZoneSocket;
use App\Libraries\MySocket\Cloudflare\AccountSocket;
class AccountController extends CloudflareController
{
private $_mySocket = null;
private $_model = null;
private $_auth_key = null;
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
{
parent::initController($request, $response, $logger);
$this->class_name = "Account";
$this->class_path = $this->root . $this->class_name;
$this->title = lang("{$this->class_path}.title");
helper($this->class_path);
}
final protected function getModel(): AccountModel
{
if ($this->_model === null) {
$this->_model = new AccountModel();
}
return $this->_model;
}
final protected function getMySocket(): AccountSocket
{
if ($this->_mySocket === null) {
$this->_mySocket = new AccountSocket($this->_auth_key);
}
return $this->_mySocket;
}
protected function getFormFieldOption(string $field, array $options = []): array
{
switch ($field) {
case $this->getModel()::PARENT:
$this->getAuthModel()->where('status', DEFAULTS['STATUS']);
$options[$field] = [
DEFAULTS['EMPTY'] => lang($this->class_path . '.label.' . $field) . ' 선택',
...$this->getAuthModel()->getFormFieldOption($field, $options),
];
// echo $this->getAuthModel()->getLastQuery();
// dd($options);
break;
default:
$options = parent::getFormFieldOption($field, $options);
break;
}
return $options;
}
// 리스트
public function index(): string
{
$this->action = __FUNCTION__;
$this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'type', 'status', 'updated_at', 'created_at'];
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
$this->filter_fields = [$this->getModel()::PARENT, 'type', 'status'];
$this->batchjob_fields = ['typep', 'status'];
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
return $this->list_procedure();
}
public function reload(): RedirectResponse
{
try {
//Transaction Start
$this->getModel()->transStart();
foreach ($this->getModel()->getEntitys as $entity) {
$zone_socket = new ZoneSocket($entity);
$zone_socket->reload();
}
return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
} catch (\Exception $e) {
//Transaction Rollback
$this->getModel()->transRollback();
log_message("error", $e->getMessage());
$this->session->setFlashdata(SESSION_NAMES['RETURN_MSG'], __FUNCTION__ . " 실패하였습니다.\n" . $e->getMessage());
return redirect()->to($this->session->getFlashdata(SESSION_NAMES['RETURN_URL']) ?: "/");
}
}
}