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; }
/** * * @param \Qcore\Controller\Abstraction\EnmMysqlCondition $filter * @param \Qcore\Controller\Abstraction\PrmPagination $pagination * @param type $orderBy * @param type $WithPrimaryKey * @param type $withDefaultLang * @return \Qcore\Controller\Base\DataResult|boolean */ public function findAll(EnmMysqlCondition $filter = null, PrmPagination $pagination = null, $orderBy = null, $WithPrimaryKey = false, $withDefaultLang = true) { $limit = null; if ($pagination !== null) { $sql = "select SQL_CALC_FOUND_ROWS "; $limit = $pagination->getLimit(); $Start = (int) $pagination->getCurrentPage(); } else { $Start = 1; $sql = "select "; } $sql .= "* from " . $this->getTable(); if ($filter != null && $filter->getSql() != "") { $sql .= " where " . $filter->getSql(); } if ($orderBy != null) { $sql .= " order by " . $orderBy; } if ($limit != null) { $sql .= " limit " . $pagination->getLimit()->end * (int) ($Start - 1) . "," . $pagination->getLimit()->end; } $result = $this->executeQuery($sql); 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; }