80 lines
2.6 KiB
PHP
80 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Cloudflare;
|
|
|
|
use App\Controllers\MVController;
|
|
use Psr\Log\LoggerInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
|
use App\Traits\AuthTrait;
|
|
|
|
use App\Models\Cloudflare\ZoneModel;
|
|
use App\Models\Cloudflare\AccountModel;
|
|
use App\Libraries\MyCloudflare\Zone;
|
|
use App\Entities\Cloudflare\ZoneEntity;
|
|
|
|
class ZoneController extends MVController
|
|
{
|
|
use AuthTrait;
|
|
private $_model = null;
|
|
private $_accountModel = null;
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
$this->session = $this->session_AuthTrait();
|
|
$this->class_name = 'Zone';
|
|
helper($this->class_name);
|
|
}
|
|
final protected function getModel(): ZoneModel
|
|
{
|
|
if ($this->_model === null) {
|
|
$this->_model = new ZoneModel();
|
|
}
|
|
return $this->_model;
|
|
}
|
|
final protected function getAccountModel(): AccountModel
|
|
{
|
|
if ($this->_accountModel === null) {
|
|
$this->_accountModel = new AccountModel();
|
|
}
|
|
return $this->_accountModel;
|
|
}
|
|
protected function getFormFieldOption(string $field, array $options = []): array
|
|
{
|
|
switch ($field) {
|
|
case ZoneModel::PARENT:
|
|
$options = [
|
|
DEFAULTS['EMPTY'] => lang($this->_className . '.label.' . $field) . ' 선택'
|
|
];
|
|
$options = $this->getAccountModel()->getFilterFieldOption($field, $options);
|
|
break;
|
|
default:
|
|
$options = parent::getFormFieldOption($field, $options);
|
|
break;
|
|
}
|
|
return $options;
|
|
}
|
|
protected function create_init(): void
|
|
{
|
|
$this->fields = [$this->getModel()::PARENT, $this->getModel()::TITLE, 'status', 'type'];
|
|
$this->filter_fields = [$this->getModel()::PARENT, 'status', 'type'];
|
|
$this->action = 'create';
|
|
$this->getModel()->setAction($this->action);
|
|
}
|
|
public function create_form(): RedirectResponse|string
|
|
{
|
|
return $this->create_form_process();
|
|
}
|
|
protected function create_process_submit(): ZoneEntity
|
|
{
|
|
$account_entity = $this->getAccountModel()->getEntityByPK($this->formDatas[$this->getModel()::PARENT]);
|
|
$zone = new Zone($account_entity);
|
|
return $zone->create($this->formDatas);
|
|
}
|
|
public function create(): RedirectResponse
|
|
{
|
|
return parent::create_process();
|
|
}
|
|
}
|