85 lines
3.2 KiB
PHP
85 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin\Cloudflare;
|
|
|
|
use App\Libraries\MySocket\Cloudflare\AccountSocket;
|
|
use App\Models\Cloudflare\AccountModel;
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class AccountController extends CloudflareController
|
|
{
|
|
private $_mySocket = null;
|
|
private $_model = null;
|
|
private $_email = "";
|
|
private $_auth_key = "";
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
$this->class_name = "Account";
|
|
$this->class_path .= $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->_email, $this->_auth_key);
|
|
}
|
|
return $this->_mySocket;
|
|
}
|
|
//생성
|
|
public function create_form(): RedirectResponse|string
|
|
{
|
|
$this->fields = ['id', 'authkey'];
|
|
$this->field_rules = $this->getModel()->getFieldRules(__FUNCTION__, $this->fields);
|
|
$this->filter_fields = [];
|
|
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
|
|
return $this->create_form_procedure();
|
|
}
|
|
protected function create_process(): void
|
|
{
|
|
parent::create_process();
|
|
$results = $this->getMySocket()->create();
|
|
$this->entitys = [];
|
|
foreach ($results as $result) {
|
|
$this->formDatas = $this->getMySocket()->getArrayByResult($result);
|
|
$entity = $this->getModel()->create($this->formDatas);
|
|
log_message("notice", "Account:" . __FUNCTION__ . "=> {$entity->getTitle()} 작업을 완료하였습니다.");
|
|
$this->entitys[] = $entity;
|
|
}
|
|
}
|
|
public function create(): RedirectResponse
|
|
{
|
|
$this->fields = ['id', 'authkey'];
|
|
$this->field_rules = $this->getModel()->getFieldRules(__FUNCTION__, $this->fields);
|
|
// $this->filter_fields = [];
|
|
// $this->field_options = $this->getFormFieldOptions($this->filter_fields);
|
|
$this->create_validate();
|
|
$this->formDatas = $this->getFormDatas();
|
|
//Socket 인증용
|
|
$this->_email = $this->formDatas['id'];
|
|
$this->auth_key = $this->formDatas['authkey'];
|
|
return $this->create_procedure();
|
|
}
|
|
// 리스트
|
|
public function index(): string
|
|
{
|
|
$this->fields = [$this->getModel()::TITLE, 'oldkey', 'type', 'status', 'updated_at', 'created_at'];
|
|
$this->field_rules = $this->getModel()->getFieldRules(__FUNCTION__, $this->fields);
|
|
$this->filter_fields = ['type', 'status'];
|
|
$this->batchjob_fields = ['status'];
|
|
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
|
|
return $this->list_procedure();
|
|
}
|
|
}
|