예제 #1
0
 public function RunPaginationQuery($SelectQuery, PrmPagination $pagination, $DataObject = null, $WithPrimaryKey = false)
 {
     $sql = preg_replace("/^select /i", "select SQL_CALC_FOUND_ROWS ", $SelectQuery);
     $Start = (int) $pagination->getCurrentPage();
     $sql .= " limit " . $pagination->getLimit()->end * (int) ($Start - 1) . "," . $pagination->getLimit()->end;
     $db = new CntDatabase();
     $result = $db->executeQuery($sql);
     if (mysqli_num_rows($result) < 1) {
         return false;
     }
     while ($row = mysqli_fetch_object($result)) {
         if ($DataObject != null) {
             $countries = new $DataObject();
             foreach ($row as $key => $value) {
                 $countries->{"_" . $key} = $value;
             }
             if ($WithPrimaryKey) {
                 $ReturnList[$countries->{"_" . $this->getPrimaryKey()}] = $countries;
             } else {
                 $ReturnList[] = $countries;
             }
         } else {
             /*
                             foreach ($row as $key => $value) {
                $countries->{$key} = $value;
                             }
             */
             $ReturnList[] = $row;
         }
         unset($countries);
     }
     $returnObject = new DataResult();
     if ($pagination !== null) {
         $countSql = "select FOUND_ROWS() as cnt";
         $countResult = $db->executeQuery($countSql);
         $row = mysqli_fetch_assoc($countResult);
         $pagination->setMaxRow($row["cnt"]);
         $pgInfo = new PaginationController();
         $returnObject->Pagination = (string) $pgInfo->pagination($pagination);
     }
     $returnObject->List = $ReturnList;
     return $returnObject;
 }
예제 #2
0
파일: AbsModel.php 프로젝트: makinuk/Qcore
 private function queryToObject($query, PrmPagination $pagination = null, $WithPrimaryKey = false)
 {
     if ($pagination != null) {
         $query = preg_replace("/^select /", "select SQL_CALC_FOUND_ROWS ", $query);
     }
     $result = $this->executeQuery($query);
     if (mysqli_num_rows($result) < 1) {
         return false;
     }
     while ($row = mysqli_fetch_object($result)) {
         $Obj = new $this();
         if (count($this->getCompressedFields()) > 0) {
             foreach ($row as $key => $value) {
                 if (property_exists($this, '_' . $key)) {
                     if (in_array($key, $this->getCompressedFields())) {
                         $Obj->{"_" . $key} = $row->{"UnCompressed" . $key};
                     } else {
                         $Obj->{"_" . $key} = $value;
                     }
                 }
             }
         } else {
             foreach ($row as $key => $value) {
                 $Obj->{"_" . $key} = $value;
             }
         }
         if ($WithPrimaryKey) {
             $keys = $this->getPrimaryKey();
             $ReturnList[$Obj->{"_" . array_shift($keys)}] = $Obj;
         } else {
             $ReturnList[] = $Obj;
         }
         unset($Obj);
     }
     $returnObject = new \Qcore\Controller\Base\DataResult();
     if ($pagination !== null) {
         $countSql = "select FOUND_ROWS()";
         $countResult = $this->executeQuery($countSql);
         $maxRow = mysqli_fetch_assoc($countResult);
         $pagination->setMaxRow(array_shift($maxRow));
         $pgInfo = new PaginationController();
         $returnObject->Pagination = $pgInfo->pagination($pagination);
     }
     $returnObject->List = $ReturnList;
     return $returnObject;
 }