servermgrv2/app/Models/BoardModel.php
최준흠git config git config --helpgit config --global user.name 최준흠 69e9ac9295 servermgrv2 init...
2023-07-23 10:31:52 +09:00

62 lines
2.2 KiB
PHP

<?php
namespace App\Models;
use App\Entities\BoardEntity;
class BoardModel extends BaseHierarchyModel
{
public function __construct()
{
parent::__construct();
$this->table = 'tw_board';
$this->allowedFields = [...$this->allowedFields, 'board_config_uid', 'user_uid', 'title', 'content', 'passwd', 'view_cnt', 'status'];
$this->validationRules = [
...$this->validationRules,
'board_config_uid' => 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
'user_uid' => 'if_exist|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]',
'title' => 'required|string',
'content' => 'required|string',
'passwd' => 'if_exist|trim|string',
'view_cnt' => 'if_exist|numeric',
'status' => 'if_exist|string',
];
}
public function getEntity($uid): BoardEntity
{
$entity = $this->asObject(BoardEntity::class)->where([$this->primaryKey => $uid])->first();
return $entity ?: throw new \Exception("{$uid}의 해당 데이터가 없습니다.\n ");
}
public function getEntitys($where): array
{
return $this->asObject(BoardEntity::class)->where($where)->findAll();
}
public function create(array $formDatas): BoardEntity
{
return $this->create_process(new BoardEntity(), $formDatas);
}
public function modify(BoardEntity $entity, array $formDatas): BoardEntity
{
return $this->modify_process($entity, $formDatas);
}
public function reply($parent_entity, array $formDatas): BoardEntity
{
return $this->reply_process($parent_entity, new BoardEntity(), $formDatas);
}
//Index관련
public function setIndexWordFilter(string $word)
{
parent::setIndexWordFilter($word);
$this->orLike('title', $word, 'both');
$this->orLike('content', $word, 'both'); //befor , after , both
}
public function setIndexOrderBy($field, $order = 'DESC')
{
$this->orderBy("grpno", "DESC");
$this->orderBy("grporder", "ASC");
parent::setIndexOrderBy($field, $order);
}
}