예제 #1
0
 public function find(ComMongoDatabaseQueryDocument $query, $mode = KDatabase::FETCH_ROWSET)
 {
     $result = array();
     if (!empty($query->from)) {
         $collection = $this->_database->selectCollection($query->from);
         switch ($mode) {
             case KDatabase::FETCH_ROW:
                 // TODO: Support selecting specific fields
                 $result = $collection->findOne($query->build());
                 break;
             default:
                 $result = $collection->find($query->build());
                 if (!empty($query->sort)) {
                     $result = $result->sort($query->sort);
                 }
                 if ($query->limit) {
                     $result = $result->limit($query->limit)->skip($query->offset);
                 }
                 $result = iterator_to_array($result);
                 break;
         }
     }
     $query->reset();
     return $result;
 }
예제 #2
0
 public function getQuery($query = null)
 {
     static $instance;
     if ($query instanceof ComMongoDatabaseQueryDocument) {
         return $query;
     }
     if (is_null($instance)) {
         $instance = new ComMongoDatabaseQueryDocument();
     }
     if (is_array($query)) {
         foreach ($query as $key => $value) {
             $instance->where($key, '=', $value);
         }
     }
     return $instance;
 }
예제 #3
0
 /**
  * Builds a Order clause for the query
  */
 protected function _buildQueryOrder(ComMongoDatabaseQueryDocument $query)
 {
     if (!is_null($this->_state->sort)) {
         $query->sort($this->_state->sort, $this->_state->direction);
     }
 }