70 lines
1.9 KiB
PHP
70 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Mangboard;
|
|
|
|
use App\Models\CommonModel;
|
|
use App\Entities\Mangboard\BoardEntity;
|
|
|
|
abstract class BoardModel extends CommonModel
|
|
{
|
|
protected $primaryKey = 'pid';
|
|
protected $returnType = BoardEntity::class;
|
|
|
|
protected function __construct(array $fields = [])
|
|
{
|
|
$fields = ["title", "data_type", "editor_type", "content", ...$fields];
|
|
parent::__construct($fields);
|
|
}
|
|
public function getTitleField(): string
|
|
{
|
|
return 'title';
|
|
}
|
|
public function getFieldRule(string $field, array $rules): array
|
|
{
|
|
switch ($field) {
|
|
case 'gid':
|
|
$rules[$field] = "required|numeric";
|
|
break;
|
|
case "data_type":
|
|
$rules[$field] = "if_exist|trim|in_list[html,text]";
|
|
break;
|
|
case "editor_type":
|
|
$rules[$field] = "if_exist|trim|in_list[N,S]";
|
|
break;
|
|
case "content":
|
|
$rules[$field] = "required|trim|string";
|
|
break;
|
|
default:
|
|
$rules = parent::getFieldRule($field, $rules);
|
|
break;
|
|
}
|
|
return $rules;
|
|
}
|
|
|
|
public function getEntityByPK(int $uid): null | BoardEntity
|
|
{
|
|
$this->where($this->getPKField(), $uid);
|
|
return $this->getEntity();
|
|
}
|
|
public function getEntityByID(string $id): null | BoardEntity
|
|
{
|
|
$this->where('user_id', $id);
|
|
return $this->getEntity();
|
|
}
|
|
|
|
//create용
|
|
public function create(BoardEntity $entity): BoardEntity
|
|
{
|
|
$entity = $this->create_process($entity);
|
|
//GID값이 PK랑 같은 값 전달 후 Entity 수정
|
|
$entity->gid = $entity->getPK();
|
|
return $this->modify_process($entity);
|
|
}
|
|
|
|
//modify용
|
|
public function modify(BoardEntity $entity): BoardEntity
|
|
{
|
|
return $this->modify_process($entity);
|
|
}
|
|
}
|