112 lines
4.0 KiB
PHP
112 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\DTOs\PaymentDTO;
|
|
use App\Entities\PaymentEntity;
|
|
use App\Forms\PaymentForm;
|
|
use App\Helpers\PaymentHelper;
|
|
use App\Models\PaymentModel;
|
|
use RuntimeException;
|
|
|
|
class PaymentService extends CommonService
|
|
{
|
|
private $_form = null;
|
|
private $_helper = null;
|
|
public function __construct(PaymentModel $model)
|
|
{
|
|
parent::__construct($model);
|
|
$this->addClassPaths('Payment');
|
|
}
|
|
public function createDTO(array $formDatas): PaymentDTO
|
|
{
|
|
return new PaymentDTO($formDatas);
|
|
}
|
|
public function getFormService(): PaymentForm
|
|
{
|
|
if ($this->_form === null) {
|
|
$this->_form = new PaymentForm();
|
|
$this->_form->setAttributes([
|
|
'pk_field' => $this->model->getPKField(),
|
|
'title_field' => $this->model->getTitleField(),
|
|
'table' => $this->model->getTable(),
|
|
'useAutoIncrement' => $this->model->useAutoIncrement(),
|
|
'class_path' => $this->getClassPaths(false)
|
|
]);
|
|
}
|
|
return $this->_form;
|
|
}
|
|
public function getHelper(): PaymentHelper
|
|
{
|
|
if ($this->_helper === null) {
|
|
$this->_helper = new PaymentHelper();
|
|
$this->_helper->setAttributes([
|
|
'pk_field' => $this->model->getPKField(),
|
|
'title_field' => $this->model->getTitleField(),
|
|
'table' => $this->model->getTable(),
|
|
'useAutoIncrement' => $this->model->useAutoIncrement(),
|
|
'class_path' => $this->getClassPaths(false)
|
|
]);
|
|
}
|
|
return $this->_helper;
|
|
}
|
|
//기본 기능부분
|
|
protected function getEntity_process(mixed $entity): PaymentEntity
|
|
{
|
|
return $entity;
|
|
}
|
|
protected function create_process(array $formDatas): PaymentEntity
|
|
{
|
|
//confirmpassword 필드는 Entity에 필요없으므로 제거
|
|
if (isset($formDatas['confirmpassword'])) {
|
|
unset($formDatas['confirmpassword']);
|
|
}
|
|
return new PaymentEntity($formDatas);
|
|
}
|
|
public function create(object $dto): PaymentEntity
|
|
{
|
|
if (!$dto instanceof PaymentDTO) {
|
|
throw new RuntimeException(__METHOD__ . "에서 오류발생:" . get_class($dto) . "는 사용할수 없습니다.");
|
|
}
|
|
return parent::create($dto);
|
|
}
|
|
protected function modify_process($uid, array $formDatas): PaymentEntity
|
|
{
|
|
//confirmpassword 필드는 Entity에 필요없으므로 제거
|
|
if (isset($formDatas['confirmpassword'])) {
|
|
unset($formDatas['confirmpassword']);
|
|
}
|
|
return parent::modify_process($uid, $formDatas);
|
|
}
|
|
public function modify($uid, object $dto): PaymentEntity
|
|
{
|
|
if (!$dto instanceof PaymentDTO) {
|
|
throw new RuntimeException(__METHOD__ . "에서 오류발생:" . get_class($dto) . "는 사용할수 없습니다.");
|
|
}
|
|
return parent::modify($uid, $dto);
|
|
}
|
|
//List 검색용
|
|
//FormFilter 조건절 처리
|
|
public function setFilter(string $field, mixed $filter_value): void
|
|
{
|
|
switch ($field) {
|
|
case 'role':
|
|
//FIND_IN_SET()은 MySQL 함수이므로 CodeIgniter가 이를 일반 컬럼명으로 착각하고 escape하게 되면 오류가 발생
|
|
// 따라서 ->where($sql, null, false)로 명시하여 escape를 꺼줘야 정상 작동
|
|
$where = "FIND_IN_SET(" . $this->model->escape($filter_value) . ", {$this->model->getTable()}.{$field}) > 0";
|
|
$this->model->where($where, null, false);
|
|
break;
|
|
default:
|
|
parent::setFilter($field, $filter_value);
|
|
break;
|
|
}
|
|
}
|
|
//검색어조건절처리
|
|
public function setSearchWord(string $word): void
|
|
{
|
|
$this->model->orLike($this->model->getTable() . '.id', $word, 'both');
|
|
$this->model->orLike($this->model->getTable() . '.email', $word, 'both');
|
|
parent::setSearchWord($word);
|
|
}
|
|
}
|