コード例 #1
0
ファイル: Store.php プロジェクト: dw250100785/Octo
 /**
  * @param $page
  * @param $perPage
  * @param array $order
  * @param array $criteria
  * @param array $bind
  * @return Database\Query
  */
 public function query($page, $perPage, array $order = [], array $criteria = [], array $bind = [])
 {
     $query = new Database\Query($this->modelName, 'read');
     $query->select($this->tableName . '.*')->from($this->tableName);
     $page -= 1;
     // Make the pagination zero-indexed
     $offset = $page * $perPage;
     $query->offset($offset);
     $query->limit($perPage);
     // Handle WHERE criteria:
     if (count($criteria)) {
         $criteriaContainer = new Database\Query\Criteria();
         foreach ($criteria as $where) {
             if ($where instanceof Database\Query\Criteria) {
                 $criteriaContainer->add($where);
             } else {
                 $thisCriteria = new Database\Query\Criteria();
                 $thisCriteria->where($where);
                 $criteriaContainer->add($thisCriteria);
             }
         }
         $query->where($criteriaContainer);
     }
     // Handle ORDER BY:
     if (count($order)) {
         $query->order($order[0], $order[1]);
     }
     // Handle bound parameters:
     if (count($bind)) {
         $query->bindAll($bind);
     }
     return $query;
 }
コード例 #2
0
ファイル: Store.php プロジェクト: dw250100785/b8framework
 /**
  * @param Query $query
  * @param array $options
  */
 public function handleQueryOptions(Query &$query, array $options)
 {
     if (array_key_exists('limit', $options)) {
         $query->limit($options['limit']);
     }
     if (array_key_exists('offset', $options)) {
         $query->offset($options['offset']);
     }
     if (array_key_exists('order', $options)) {
         if (is_string($options['order'])) {
             $options['order'] = array($options['order']);
         }
         foreach ($options['order'] as $order) {
             $query->order($order[0], $order[1]);
         }
     }
 }