Esempio n. 1
0
 /**
  * @see CActiveDataProvider::fetchData()
  * @return array
  */
 public function fetchData()
 {
     $criteria = $this->getCriteria();
     // I have not refactored this line considering that the condition may have changed from total item count to here, maybe.
     $this->_cursor = $this->model->find(isset($criteria['condition']) && is_array($criteria['condition']) ? $criteria['condition'] : array(), isset($criteria['project']) && !empty($criteria['project']) ? $criteria['project'] : array());
     // If we have sort and limit and skip setup within the incoming criteria let's set it
     if (isset($criteria['sort']) && is_array($criteria['sort'])) {
         $this->_cursor->sort($criteria['sort']);
     }
     if (isset($criteria['skip']) && is_int($criteria['skip'])) {
         $this->_cursor->skip($criteria['skip']);
     }
     if (isset($criteria['limit']) && is_int($criteria['limit'])) {
         $this->_cursor->limit($criteria['limit']);
     }
     if (isset($criteria['hint']) && (is_array($criteria['hint']) || is_string($criteria['hint']))) {
         $this->_cursor->hint($criteria['hint']);
     }
     if (($pagination = $this->getPagination()) !== false) {
         $pagination->setItemCount($this->getTotalItemCount());
         $this->_cursor->limit($pagination->getLimit());
         $this->_cursor->skip($pagination->getOffset());
     }
     if (($sort = $this->getSort()) !== false) {
         $sort = $sort->getOrderBy();
         if (count($sort) > 0) {
             $this->_cursor->sort($sort);
         }
     }
     return iterator_to_array($this->_cursor, false);
 }
Esempio n. 2
0
 /**
  * @see CActiveDataProvider::fetchData()
  * @return array
  */
 public function fetchData()
 {
     $criteria = $this->getCriteria();
     // I have not refactored this line considering that the condition may have changed from total item count to here, maybe.
     $this->_builder = new EMongoQueryBuilder($this->model, isset($criteria['condition']) && is_array($criteria['condition']) ? $criteria['condition'] : [], isset($criteria['project']) && !empty($criteria['project']) ? $criteria['project'] : []);
     $this->options['condition'] = isset($criteria['condition']) && is_array($criteria['condition']) ? $criteria['condition'] : [];
     $this->options['projection'] = isset($criteria['project']) && !empty($criteria['project']) ? $criteria['project'] : [];
     // If we have sort and limit and skip setup within the incoming criteria let's set it
     if (isset($criteria['sort']) && is_array($criteria['sort'])) {
         $this->_builder->sort($criteria['sort']);
     }
     if (isset($criteria['skip']) && is_int($criteria['skip'])) {
         $this->_builder->skip($criteria['skip']);
     }
     if (isset($criteria['limit']) && is_int($criteria['limit'])) {
         $this->_builder->limit($criteria['limit']);
     }
     if (isset($criteria['hint']) && (is_array($criteria['hint']) || is_string($criteria['hint']))) {
         $this->_builder->hint($criteria['hint']);
     }
     if (($pagination = $this->getPagination()) !== false) {
         $pagination->setItemCount($this->getTotalItemCount());
         $this->_builder->limit($pagination->getLimit());
         $this->_builder->skip($pagination->getOffset());
     }
     if (($sort = $this->getSort()) !== false) {
         $sort = $sort->getOrderBy();
         if (count($sort) > 0) {
             $this->_builder->sort($sort);
         }
     }
     //                var_dump(iterator_to_array($this->_builder->find()));die;
     return $this->_builder->queryAll(true);
 }