示例#1
0
文件: base.php 项目: Klemart3D/COPS
 public static function executeQuery($query, $columns, $filter, $params, $n, $database = NULL, $numberPerPage = NULL)
 {
     $totalResult = -1;
     if (useNormAndUp()) {
         $query = preg_replace("/upper/", "normAndUp", $query);
         $columns = preg_replace("/upper/", "normAndUp", $columns);
     }
     if (is_null($numberPerPage)) {
         $numberPerPage = getCurrentOption("max_item_per_page");
     }
     if ($numberPerPage != -1 && $n != -1) {
         // First check total number of results
         $result = self::getDb($database)->prepare(str_format($query, "count(*)", $filter));
         $result->execute($params);
         $totalResult = $result->fetchColumn();
         // Next modify the query and params
         $query .= " limit ?, ?";
         array_push($params, ($n - 1) * $numberPerPage, $numberPerPage);
     }
     $result = self::getDb($database)->prepare(str_format($query, $columns, $filter));
     $result->execute($params);
     return array($totalResult, $result);
 }
示例#2
0
文件: book.php 项目: ha-y/cops
 public static function getBooksByQuery($query, $n, $database = NULL, $numberPerPage = NULL)
 {
     $i = 0;
     $critArray = array();
     foreach (array(PageQueryResult::SCOPE_AUTHOR, PageQueryResult::SCOPE_TAG, PageQueryResult::SCOPE_SERIES, PageQueryResult::SCOPE_PUBLISHER, PageQueryResult::SCOPE_BOOK) as $key) {
         if (in_array($key, getCurrentOption('ignored_categories')) || !array_key_exists($key, $query) && !array_key_exists("all", $query)) {
             $critArray[$i] = self::BAD_SEARCH;
         } else {
             if (array_key_exists($key, $query)) {
                 $critArray[$i] = $query[$key];
             } else {
                 $critArray[$i] = $query["all"];
             }
         }
         $i++;
     }
     return self::getEntryArray(self::SQL_BOOKS_QUERY, $critArray, $n, $database, $numberPerPage);
 }