/** * Modifies the query criteria by changing its {@link CDbCriteria::order} property. * This method will use {@link directions} to determine which columns need to be sorted. * They will be put in the ORDER BY clause. If the criteria already has non-empty {@link CDbCriteria::order} value, * the new value will be appended to it. * @param MongoDbCriteria $criteria the query criteria */ public function applyOrder($criteria) { if (!isset($_GET[$this->sortVar])) { return; } $temp = explode('.', $_GET[$this->sortVar]); $field = $temp[0]; if (isset($temp[1]) && $temp[1] == self::SORT_ASC) { $arrow = 'ASC'; } else { if (isset($temp[1]) && $temp[1] == self::SORT_DESC) { $arrow = 'DESC'; } else { $arrow = 'ASC'; } } $criteria->orderBy($field, $arrow, $this->multiSort); }
/** * @param MongoDbCriteria|array|null $query * @return int */ public function count($query = null) { if ($query instanceof MongoDbCriteria) { return $this->getCollection()->count($query->getConditions()); } else { if (is_array($query) && sizeof($query) > 0) { return $this->getCollection()->count($query); } else { return $this->getCollection()->count(); } } }
/** * @param \MongoDbCriteria $builder * @return $this */ public function mergeWithBuilder(MongoDbCriteria $builder) { $this->query = array_merge_recursive($this->query, $builder->getQuery()); if (is_array($this->query['limit']) && sizeof($this->query['limit']) > 0) { $this->query['limit'] = $this->query['limit'][0]; } if (is_array($this->query['offset']) && sizeof($this->query['offset']) > 0) { $this->query['offset'] = $this->query['offset'][0]; } $this->checkTopLevelOperators(); return $this; }