_model === null) { $modelClass = $this->getModelClass(); $this->_model = new $modelClass(); // $this->_model->setDebug(true); } return $this->_model; } final public function getEntity(): mixed { $result = $this->getModel()->first(); if (!$result) { //결과값이 없으면 null return $result; } $entityClass = $this->getEntityClass(); return new $entityClass($result); } final public function getEntities(): array { $entitys = []; foreach ($this->getModel()->get() as $result) { $entityClass = $this->getEntityClass(); $entity = new $entityClass($result); $pairField = $this->getModel()->getPairField(); $entitys[$entity->$pairField] = $entity; } return $entitys; } // final public function getCount(string $select = "COUNT(*) as cnt"): int { $count = $this->getModel()->count($select); // echo "
" . $this->getModel()->getLastQuery(); return $count; } final public function getList(int $curPage = 1, int $perPage = VIEW_LIST_PERPAGE): array { //Query문 Rest여부 -> 같은조건에 Count 받고, 결과값을 받고 싶을때는 continue() $this->getModel()->setContinue(true); $total = $this->getCount(); //limit, offset 설정 $this->getModel()->limit($perPage); $this->getModel()->offset(($curPage - 1) * $perPage); $entities = $this->getEntities(); return [$total, $entities]; } public function insert(array $formData): int { $insertId = $this->getModel()->insert($formData); if (!$insertId) { throw new \Exception("Insert Error : " . $this->getModel()->getLastError()); } return $insertId; } // //transaction관련련 final public function beginTransaction(): void { $this->getModel()->beginTransaction(); } final public function commit(): void { $this->getModel()->commit(); } final public function rollBack(): void { $this->getModel()->rollBack(); } } //Class