That are methods for either normal queries that return active records but also relational queries in which the query represents a relation between two active record classes and will return related records only. A class implementing this interface should also use ActiveQueryTrait and ActiveRelationTrait.
Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Author: Carsten Brandt (mail@cebe.cc)
Inheritance: extends yii\db\QueryInterface
Exemplo n.º 1
0
 protected function addCondition(ActiveQueryInterface $query, $tableName, $attribute, $partialMatch = false)
 {
     $value = $this->{$attribute};
     if ($partialMatch) {
         $query->andFilterWhere(['like', $tableName . '.' . $attribute, $value]);
     } else {
         $query->andFilterWhere([$tableName . '.' . $attribute => $value]);
     }
 }
 /**
  * Add filter to query (if any exists).
  *
  * @param ActiveQueryInterface $query
  */
 protected function addFilterToQuery(ActiveQueryInterface $query)
 {
     if (!$this->filter) {
         return;
     }
     if ($this->filter instanceof Closure) {
         call_user_func_array($this->filter, [$query]);
     } else {
         $query->andWhere($this->filter);
     }
 }
Exemplo n.º 3
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     if (is_callable($this->query)) {
         $this->query = call_user_func($this->query, $this->model);
     }
     if ($this->query instanceof ActiveQueryInterface) {
         if (!$this->labelAttribute) {
             throw new InvalidConfigException('Parameter "labelAttribute" is required');
         }
         $this->items = $this->query->all();
         foreach ($this->items as $i => $model) {
             $this->items[$i] = AdminHelper::resolveAttribute($this->labelAttribute, $model);
         }
     }
     if ($this->allowEmpty) {
         $this->items = ArrayHelper::merge([null => Yii::t('yii', '(not set)')], $this->items);
     }
     parent::init();
 }
 /**
  * Paginate the results of the query.
  *
  * @param ActiveQueryInterface $query
  * @param int $pageNumber
  * @param int $count
  *
  * @return ActiveQueryInterface
  */
 private function paginateRecords(ActiveQueryInterface $query, $pageNumber, $count)
 {
     $offset = ($pageNumber - 1) * $count;
     $limit = $count;
     return $query->offset($offset)->limit($limit);
 }