table = 'tw_board_config'; $this->useAutoIncrement = false; $this->allowedFields = [ ...$this->allowedFields, 'uid', 'name', 'isaccess', 'isread', 'iswrite', 'isreply', 'isupload', 'isdownload', 'status', 'head', 'tail' ]; $this->validationRules = [ ...$this->validationRules, ...$this->getFieldRules($this->getFields()), ]; } public function getFields(array $fields = array(), array $skips = array()): array { $fields = [...$this->allowedFields, ...$fields]; return parent::getFields($fields, ['uid', ...$skips]); } public function getFieldFilters(array $fields = array(), array $skips = array()): array { $skips = ['name', 'head', 'tail', ...$skips]; return parent::getFieldFilters($fields, $skips); } protected function getFieldRule(string $field, array $rules): array { switch ($field) { case 'uid': $rules[$field] = 'required|regex_match[/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/]'; break; case 'name': $rules[$field] = 'required|trim|string'; break; case 'isaccess': case 'isread': case 'iswrite': case 'isreply': case 'isupload': case 'isdownload': $rules[$field] = 'required'; break; default: $rules = parent::getFieldRule($field, $rules); break; } return $rules; } public function getEntity($where): BoardConfigEntity { $entity = $this->asObject(BoardConfigEntity::class)->where($where)->first(); return $entity ?: throw new \Exception("{$where}의 해당 데이터가 없습니다.\n "); } public function getEntitys($where): array { return $this->asObject(BoardConfigEntity::class)->where($where)->findAll(); } protected function changeFormData(string $field, array $formDatas, $entity) { switch ($field) { case 'isaccess': case 'isread': case 'iswrite': case 'isreply': case 'isupload': case 'isdownload': case 'isaccess': if (array_key_exists($field, $formDatas) && $formDatas[$field]) { $entity->$field = is_array($formDatas[$field]) ? implode("|", $formDatas[$field]) : $formDatas[$field]; } break; case 'head': case 'tail': if (array_key_exists($field, $formDatas) && $formDatas[$field]) { $entity->$field = htmlentities($formDatas[$field]); } break; default: return parent::changeFormData($field, $formDatas, $entity); break; } return $entity; } public function create(array $formDatas): BoardConfigEntity { return $this->create_process(new BoardConfigEntity(), $formDatas); } public function modify(BoardConfigEntity $entity, array $formDatas): BoardConfigEntity { return $this->modify_process($entity, $formDatas); } //Index관련 public function setIndexWordFilter(string $word) { parent::setIndexWordFilter($word); $this->orLike('name', $word, 'both'); //befor , after , both $this->orLike('isaccess', $word, 'both'); //befor , after , both $this->orLike('isread', $word, 'both'); //befor , after , both $this->orLike('iswrite', $word, 'both'); //befor , after , both $this->orLike('isreply', $word, 'both'); //befor , after , both $this->orLike('isupload', $word, 'both'); //befor , after , both $this->orLike('isdownload', $word, 'both'); //befor , after , both } public function setIndexOrderBy($field, $order = 'ASC') { $this->orderBy("name", "ASC"); parent::setIndexOrderBy($field, $order); } }