88 lines
3.5 KiB
PHP
88 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers\Admin;
|
|
|
|
use App\DTOs\TrafficDTO;
|
|
use App\Entities\TrafficEntity;
|
|
use CodeIgniter\HTTP\RequestInterface;
|
|
use CodeIgniter\HTTP\ResponseInterface;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class TrafficController extends AdminController
|
|
{
|
|
public const PATH = 'traffic';
|
|
public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
|
|
{
|
|
parent::initController($request, $response, $logger);
|
|
if ($this->service === null) {
|
|
$this->service = service('trafficservice');
|
|
}
|
|
$this->addActionPaths($this::PATH);
|
|
}
|
|
protected function action_init_process(string $action): void
|
|
{
|
|
$fields = ['client', 'switch', 'ip', 'interface', 'status'];
|
|
$filters = ['status'];
|
|
parent::action_init_process($action);
|
|
switch ($action) {
|
|
case 'create':
|
|
case 'create_form':
|
|
case 'modify':
|
|
case 'modify_form':
|
|
break;
|
|
case 'view':
|
|
$fields = [...$fields, 'created_at'];
|
|
break;
|
|
case 'index':
|
|
$fields = [...$fields, 'created_at'];
|
|
$this->addViewDatas('index_batchjobFields', $this->service->getFormService()->getBatchjobFields($filters));
|
|
$this->addViewDatas('index_batchjobButtions', $this->service->getFormService()->getBatchjobButtons());
|
|
break;
|
|
default:
|
|
throw new \Exception("지원하지 않는 action입니다.({$action})");
|
|
// break;
|
|
}
|
|
$this->addViewDatas('helper', $this->service->getHelper());
|
|
$this->addViewDatas('formFields', $this->service->getFormService()->getFormFields($action, $fields));
|
|
$this->addViewDatas('formFilters', $this->service->getFormService()->getFormFilters($action, $filters));
|
|
$this->addViewDatas('formRules', $this->service->getFormService()->getFormRules($action, $fields));
|
|
$this->addViewDatas('formOptions', $this->service->getFormService()->getFormOptions($action, $filters));
|
|
}
|
|
//Action작업관련
|
|
protected function create_form_process(string $action): void
|
|
{
|
|
//Form Default값 설정
|
|
$formDatas = [];
|
|
$this->addViewDatas('formDatas', $formDatas);
|
|
}
|
|
protected function create_process(string $action): array
|
|
{
|
|
//요청 데이터를 DTO 객체로 변환
|
|
$dto = new TrafficDTO($this->request->getPost());
|
|
$entity = $this->service->create($dto);
|
|
return array($entity, "{$entity->getTitle()} 트래픽정보 생성이 완료되었습니다.");
|
|
}
|
|
protected function modify_form_process(string $action, $uid): void
|
|
{
|
|
if (!$uid) {
|
|
throw new \Exception("트래픽정보 번호가 정의 되지 않았습니다.");
|
|
}
|
|
$entity = $this->service->getEntity($uid);
|
|
if (!$entity instanceof TrafficEntity) {
|
|
throw new \Exception("{$uid}에 해당하는 트래픽정보를 찾을수 없습니다.");
|
|
}
|
|
$this->addViewDatas('entity', $entity);
|
|
}
|
|
protected function modify_process(string $action, $uid): array
|
|
{
|
|
//요청 데이터를 DTO 객체로 변환
|
|
$dto = new TrafficDTO($this->request->getPost());
|
|
$entity = $this->service->modify($uid, $dto);
|
|
return array($entity, "{$entity->getTitle()} 트래픽정보 수정이 완료되었습니다.");
|
|
}
|
|
protected function view_process($uid): TrafficEntity
|
|
{
|
|
return parent::view_process($uid);
|
|
}
|
|
}
|