allowedFields = [...$this->allowedFields, ...$this->getFields(),]; $this->validationRules = [...$this->validationRules, ...$this->getFieldRules($this->allowedFields),]; } public function getTitleField(): string { return 'name'; } public function getContentField(): string { return 'head'; } public function getFields(string $action = ""): array { $fields = [$this->getTitleField(), "status", "head", "tail",]; switch ($action) { case "index": case "excel": return [$this->getTitleField(), "status", "created_at"]; break; case "view": return [$this->getTitleField(), "status", "created_at", "head", "tail",]; break; default: return $fields; break; } } public function getFieldFilters(): array { return ["status"]; } public function getFieldBatchFilters(): array { return parent::getFieldBatchFilters(); } protected function getFieldRule(string $field, array $rules, string $action = ""): array { switch ($field) { case $this->getTitleField(): $rules[$field] = "required|trim|string"; break; case "head": case "tail": $rules[$field] = "if_exist|string"; break; default: $rules = parent::getFieldRule($field, $rules, $action); break; } return $rules; } public function getEntity($conditions): CategoryEntity { return $this->where($conditions)->first() ?: throw new \Exception("해당 데이터가 없습니다.\n" . var_export($conditions, true)); } public function getFormOptions(array $conditions = array(), $options = array()): array { $old_title = ""; foreach ($this->where($conditions)->orderby("grpno DESC, grporder ASC")->findAll() as $entity) { if ($entity->getPrimaryKey() == $entity->getHierarchy_No()) { $options[$entity->getTitle()] = []; $old_title = $entity->getTitle(); } else { $options[$old_title][$entity->getPrimaryKey()] = $entity->getTitle(); } } return $options; } public function create(array $formDatas): CategoryEntity { return $this->create_process(new CategoryEntity(), $formDatas); } public function modify(CategoryEntity $entity, array $formDatas): CategoryEntity { return $this->modify_process($entity, $formDatas); } public function reply($parent_entity, array $formDatas): CategoryEntity { return $this->reply_process($parent_entity, new CategoryEntity(), $formDatas); } //Index관련 public function setIndexWordFilter(string $word) { parent::setIndexWordFilter($word); $this->orLike($this->getTitleField(), $word, "both"); $this->orLike("head", $word, "both"); //befor , after , both $this->orLike("tail", $word, "both"); //befor , after , both } }