/**
  * @see CActiveDataProvider::calculateTotalItemCount()
  * @return int
  */
 public function calculateTotalItemCount()
 {
     if (!$this->_cursor) {
         $criteria = $this->getCriteria();
         $this->_cursor = $this->model->find(isset($criteria['condition']) && is_array($criteria['condition']) ? $criteria['condition'] : array());
     }
     return $this->_cursor->count();
 }
示例#2
0
 /**
  * @see CActiveDataProvider::calculateTotalItemCount()
  * @return int
  */
 public function calculateTotalItemCount()
 {
     if (!$this->_builder) {
         $criteria = $this->getCriteria();
         $this->_builder = new EMongoQueryBuilder($this->model, isset($criteria['condition']) && is_array($criteria['condition']) ? $criteria['condition'] : []);
     }
     return $this->_builder->count();
 }
示例#3
0
 /**
  * Find some records
  * @param array|EMongoCriteria $criteria
  * @param array|string[] $fields
  * @return EMongoCursor|EMongoDocument[]
  */
 public function find($criteria = array(), $fields = array())
 {
     $this->trace(__FUNCTION__);
     $this->beforeFind();
     // Apparently this is applied before even scopes...
     if ($criteria instanceof EMongoCriteria) {
         $c = $criteria->mergeWith($this->getDbCriteria())->toArray();
         $criteria = array();
     } else {
         $c = $this->getDbCriteria();
     }
     $query = $this->mergeCriteria(isset($c['condition']) ? $c['condition'] : array(), $criteria);
     $project = $this->mergeCriteria(isset($c['project']) ? $c['project'] : array(), $fields);
     Yii::trace('Executing find: ' . '{$query:' . json_encode($query) . ',$project:' . json_encode($project) . (isset($c['sort']) ? ',$sort:' . json_encode($c['sort']) . ',' : '') . (isset($c['skip']) ? ',$skip:' . json_encode($c['skip']) . ',' : '') . (isset($c['limit']) ? ',$limit:' . json_encode($c['limit']) . ',' : '') . '}', 'extensions.MongoYii.EMongoDocument');
     if ($this->getDbConnection()->enableProfiling) {
         $token = 'extensions.MongoYii.EMongoDocument.query.' . $this->collectionName() . '.find(' . '{$query:' . json_encode($query) . ',$project:' . json_encode($project) . (isset($c['sort']) ? ',$sort:' . json_encode($c['sort']) . ',' : '') . (isset($c['skip']) ? ',$skip:' . json_encode($c['skip']) . ',' : '') . (isset($c['limit']) ? ',$limit:' . json_encode($c['limit']) . ',' : '') . '})';
         Yii::beginProfile($token, 'extensions.MongoYii.EMongoDocument.find');
     }
     if ($c !== array()) {
         $cursor = new EMongoCursor($this, $query, $project);
         if (isset($c['sort'])) {
             $cursor->sort($c['sort']);
         }
         if (isset($c['skip'])) {
             $cursor->skip($c['skip']);
         }
         if (isset($c['limit'])) {
             $cursor->limit($c['limit']);
         }
         $this->resetScope(false);
     } else {
         $cursor = new EMongoCursor($this, $criteria, $project);
     }
     if ($this->getDbConnection()->enableProfiling) {
         Yii::endProfile($token, 'extensions.MongoYii.EMongoDocument.find');
     }
     return $cursor;
 }
 /**
  * Find some records
  * @param array|EMongoCriteria $criteria
  * @param array|string[] $fields
  * @return EMongoCursor|EMongoDocument[]
  */
 public function find($criteria = array(), $fields = array())
 {
     $this->trace(__FUNCTION__);
     $this->beforeFind();
     // Apparently this is applied before even scopes...
     if ($criteria instanceof EMongoCriteria) {
         $c = $criteria->mergeWith($this->getDbCriteria())->toArray();
         $criteria = array();
     } else {
         $c = $this->getDbCriteria();
     }
     if ($c !== array()) {
         $cursor = new EMongoCursor($this, $this->mergeCriteria(isset($c['condition']) ? $c['condition'] : array(), $criteria), $this->mergeCriteria(isset($c['project']) ? $c['project'] : array(), $fields));
         if (isset($c['sort'])) {
             $cursor->sort($c['sort']);
         }
         if (isset($c['skip'])) {
             $cursor->skip($c['skip']);
         }
         if (isset($c['limit'])) {
             $cursor->limit($c['limit']);
         }
         $this->resetScope();
         return $cursor;
     }
     return new EMongoCursor($this, $criteria, $fields);
 }