67 lines
2.1 KiB
PHP
67 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Entities\UserEntity as Entity;
|
|
use App\Models\UserModel as Model;
|
|
use CodeIgniter\HTTP\IncomingRequest;
|
|
|
|
class UserService extends CommonService
|
|
{
|
|
protected ?IncomingRequest $request = null;
|
|
public function __construct(IncomingRequest $request)
|
|
{
|
|
parent::__construct($request);
|
|
}
|
|
final public function getClassName(): string
|
|
{
|
|
return "User";
|
|
}
|
|
final public function getClassPath(): string
|
|
{
|
|
return $this->getClassName();
|
|
}
|
|
public function getModelClass(): string
|
|
{
|
|
return Model::class;
|
|
}
|
|
public function getEntityClass(): string
|
|
{
|
|
return Entity::class;
|
|
}
|
|
public function getFormFieldOption(string $field, array $options = []): array
|
|
{
|
|
switch ($field) {
|
|
default:
|
|
$this->getModel()->orderBy($this->getModel()::TITLE, 'ASC');
|
|
$options = parent::getFormFieldOption($field, $options);
|
|
break;
|
|
}
|
|
return $options;
|
|
}
|
|
public function create(array $formDatas): Entity
|
|
{
|
|
$formDatas['role'] = implode(DEFAULTS["DELIMITER_ROLE"], $formDatas['role']);
|
|
return $this->getModel()->create($formDatas, new Entity());
|
|
}
|
|
public function modify(Entity $entity, array $formDatas): Entity
|
|
{
|
|
// die(var_export($formDatas, true));
|
|
//암호를 입력하지 않았을시는 변경하기 않게 하기위함
|
|
if (isset($formDatas['passwd']) && $formDatas['passwd'] == "") {
|
|
unset($formDatas['passwd']);
|
|
unset($formDatas['confirmpassword']);
|
|
}
|
|
//Role을 지정이 있을경우에만 , toggle이나 batcjhjob에서는 없을수도 있으므로
|
|
if (isset($formDatas['role'])) {
|
|
$formDatas['role'] = implode(DEFAULTS["DELIMITER_ROLE"], $formDatas['role']);
|
|
}
|
|
// die(var_export($formDatas, true));
|
|
return $this->getModel()->modify($entity, $formDatas);
|
|
}
|
|
public function delete(Entity $entity): bool
|
|
{
|
|
return $this->getModel()->delete($entity->getPK());
|
|
}
|
|
}
|