servermgrv2/app/Models/LoggerModel.php
최준흠git config git config --helpgit config --global user.name 최준흠 eaa3a76677 servermgrv2 init...
2023-07-23 23:26:19 +09:00

73 lines
2.2 KiB
PHP

<?php
namespace App\Models;
use App\Entities\LoggerEntity;
class LoggerModel extends BaseModel
{
public function __construct()
{
parent::__construct();
$this->table = 'tw_logger';
$this->allowedFields = [
...$this->allowedFields,
...$this->getFields(),
];
$this->validationRules = [
...$this->validationRules,
...$this->getFieldRules($this->getFields()),
];
}
public function getFields(array $fields = array(), array $skips = array()): array
{
$fields = ['user_uid', 'title', 'content', 'status', ...$fields];
return parent::getFields($fields, $skips);
}
public function getFieldFilters(array $fields = array(), array $skips = array()): array
{
$fields = ['user_uid', 'status', ...$fields];
return parent::getFieldFilters($fields, $skips);
}
protected function getFieldRule(string $field, array $rules): array
{
switch ($field) {
case 'title':
case 'content':
case 'status':
$rules[$field] = 'required|string';
break;
default:
$rules = parent::getFieldRule($field, $rules);
break;
}
return $rules;
}
public function getEntity($where): LoggerEntity
{
$entity = $this->asObject(LoggerEntity::class)->where($where)->first();
return $entity ?: throw new \Exception("{$where}의 해당 데이터가 없습니다.\n ");
}
public function getEntitys($where): array
{
return $this->asObject(LoggerEntity::class)->where($where)->findAll();
}
public function create(array $formDatas): LoggerEntity
{
return $this->create_process(new LoggerEntity(), $formDatas);
}
public function modify(LoggerEntity $entity, array $formDatas): LoggerEntity
{
return $this->modify_process($entity, $formDatas);
}
//Index관련
public function setIndexWordFilter(string $word)
{
parent::setIndexWordFilter($word);
$this->orLike('title', $word, 'both');
$this->orLike('content', $word, 'both'); //befor , after , both
}
}