68 lines
1.9 KiB
PHP
68 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Mangboard;
|
|
|
|
use App\Entities\Mangboard\FreeboardEntity;
|
|
use App\Models\CommonModel;
|
|
|
|
class FreeboardModel extends CommonModel
|
|
{
|
|
protected $table = 'mb_board_free';
|
|
protected $primaryKey = 'pid';
|
|
protected $returnType = FreeboardEntity::class;
|
|
|
|
public function __construct()
|
|
{
|
|
$fields = ["title", "text", "content"];
|
|
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 "text":
|
|
case "content":
|
|
$rules[$field] = "required|trim|string";
|
|
break;
|
|
default:
|
|
$rules = parent::getFieldRule($field, $rules);
|
|
break;
|
|
}
|
|
return $rules;
|
|
}
|
|
|
|
public function getEntityByPK(int $uid): null|FreeboardEntity
|
|
{
|
|
$this->where($this->getPKField(), $uid);
|
|
return $this->getEntity();
|
|
}
|
|
public function getEntityByID(string $id): null|FreeboardEntity
|
|
{
|
|
$this->where('user_id', $id);
|
|
return $this->getEntity();
|
|
}
|
|
|
|
//create용
|
|
public function create(FreeboardEntity $entity, array $formDatas = []): FreeboardEntity
|
|
{
|
|
$entity = $this->create_process($entity, $formDatas);
|
|
//GID값이 PK랑 같은 값 전달 후 Entity 수정
|
|
$this->setFields(["gid"]);
|
|
$this->setRules($this->getFields());
|
|
$entity->setGID($entity->getPK());
|
|
return $this->modify_process($entity, []);
|
|
}
|
|
|
|
//modify용
|
|
public function modify(FreeboardEntity $entity, array $formDatas = []): FreeboardEntity
|
|
{
|
|
return $this->modify_process($entity, $formDatas);
|
|
}
|
|
}
|