table = 'tw_user_sns'; $this->allowedFields = [ ...$this->allowedFields, ...$this->getFields() ]; $this->validationRules = [ ...$this->validationRules, ...$this->getFieldRules($this->getFields()), ]; } public function getFields(array $fields = array(), array $skips = array()): array { $fields = ['user_uid', 'site', 'id', 'name', 'email', 'detail', 'status', ...$fields]; return parent::getFields($fields, $skips); } public function getFieldFilters(array $fields = array(), array $skips = array()): array { $fields = ['user_uid', 'status', ...$fields]; return parent::getFieldFilters($fields, $skips); } protected function getFieldRule(string $field, array $rules): array { switch ($field) { case 'id': case 'name': $rules[$field] = 'required|trim|string'; break; case 'email': $rules[$field] = 'required|valid_email'; break; case 'detail': $rules[$field] = 'if_exist|string'; break; case 'status': $rules[$field] = 'required|string'; break; default: $rules = parent::getFieldRule($field, $rules); break; } return $rules; } public function getEntity($where): UserSNSEntity { $entity = $this->asObject(UserSNSEntity::class)->where($where)->first(); return $entity ?: throw new \Exception("{$where}의 해당 데이터가 없습니다.\n "); } public function getEntitys($where): array { return $this->asObject(UserSNSEntity::class)->where($where)->findAll(); } public function create(array $formDatas): UserSNSEntity { return $this->create_process(new UserSNSEntity(), $formDatas); } public function modify(UserSNSEntity $entity, array $formDatas): UserSNSEntity { return $this->modify_process($entity, $formDatas); } //Index관련 public function setIndexWordFilter(string $word) { parent::setIndexWordFilter($word); $this->orLike('name', $word, 'both'); $this->orLike('email', $word, 'both'); //befor , after , both } public function setIndexOrderBy($field, $order = 'ASC') { $this->orderBy("name", "ASC"); parent::setIndexOrderBy($field, $order); } }