Build filters based on this model attributes and other query options.
Warning! Main table in the query should have the 't' alias set.
@param \yii\db\ActiveQuery $query
@return \yii\db\ActiveQuery
327317
public function addConditions(\yii\db\ActiveQuery $query)
    {
        if ($query instanceof ActiveQuery) {
            $this->addQuickSearchConditions($query);
        }
        $this->validate();
        $this->addAttributesSearchConditions($query);
        return $query;
    }
645476
public function buildQuery()
    {
        $model = $this->model;
        $query = $model::query();

        // perform joins
        if (is_array($this->join)) {
            foreach ($this->join as $condition) {
                list($joinModel, $column, $foreignKey) = $condition;
                $query->join($joinModel, $column, $foreignKey);
            }
        }

        // sanitze and set the filter
        $filter = $this->parseFilterInput($this->filter);
        $query->where($filter);

        // performs a search using LIKE queries
        // WARNING use sparingly, these queries are expensive
        if (!empty($this->search) && is_string($this->search) && property_exists($model, 'searchableProperties')) {
            $w = [];
            $search = addslashes($this->search);
            foreach ($model::$searchableProperties as $name) {
                $w[] = "`$name` LIKE '%$search%'";
            }

            if (count($w) > 0) {
                $query->where('('.implode(' OR ', $w).')');
            }
        }

        // eager loading
        foreach ($this->expand as $k) {
            $property = $model::getProperty($k);
            if ($property && isset($property['relation'])) {
                if (isset($property['id_property'])) {
                    $query->with($property['id_property']);
                } else {
                    $query->with($k);
                }
            }
        }

        if (isset($this->sort)) {
            $query->sort($this->sort);
        }

        // calculate limit and offset
        $start = ($this->page - 1) * $this->perPage;
        $query->start($start)->limit($this->perPage);

        return $query;
    }
1307949
public function scopeFiltersApply(Builder $query, array $filters = []): Builder
    {
        foreach ($filters as $filter) {
            if (! is_object($filter)) {
                $filter = app()->make($filter);
            }

            $query = $filter->filter($query);
        }

        return $query;
    }
254346
private static function getDataInstance(ActiveQuery $query)
    {
        $class = $query->modelClass;
        
        $keys = [$class];
        if ($query->where) {
            foreach ($query->where as $v) {
                if (is_scalar($v)) {
                    $keys[] = $v;
                }
            }
        }

        $instanceName = implode(",", $keys);
        
        if (!isset(static::$_dataInstance[$instanceName])) {
            $queryData = $query->all();
            static::$_dataInstance[$instanceName] = $queryData;
        }
        
        return static::$_dataInstance[$instanceName];
    }
301255
public function buildSelect(Query $query) {
        return $this->renderStatement(Query::SELECT, [
            'fields' => $this->formatFields($query),
            'table' => $this->formatTable($query->getTable(), $query->getAlias()),
            'joins' => $this->formatJoins($query->getJoins()),
            'where' => $this->formatWhere($query->getWhere()),
            'groupBy' => $this->formatGroupBy($query->getGroupBy()),
            'having' => $this->formatHaving($query->getHaving()),
            'compounds' => $this->formatCompounds($query->getCompounds()),
            'orderBy' => $this->formatOrderBy($query->getOrderBy()),
            'limit' => $this->formatLimitOffset($query->getLimit(), $query->getOffset()),
        ] + $this->formatAttributes($query->getAttributes()));
    }
903932
private function runQuery($query)
    {
        $resultSetMapping = (new ResultSetMapping())
                ->addScalarResult('id', 'id')
                ->addScalarResult('type', 'type')
                ->addScalarResult('date', 'date');
        
        return $this->em->createNativeQuery($query, $resultSetMapping)
                ->getArrayResult();
    }
498051
public function applyScopes(ActiveQuery $query) {
        $value = $this->getValue();
        if ($value) {
//            if ($this->isPartially) {
//                $value = '%' . $value . '%';
//            }

            $attribute = $this->attribute;
            if (($db = $this->model->getDb()) && ($schema = $db->getSchema()) && $schema instanceof Schema) {
                $operator = 'LIKE';
            } else {
                $operator = 'ILIKE';
            }

            $query->andWhere([
                $operator,
                $attribute,
                $value,
            ]);
        }

        return $query;
    }
235109
public function build($query, $filter)
    {
        $parser = $this->getParser();
        $builder = $this->getBuilder();

        try {
            $builder->build($query, $parser->parse($filter));
        } catch (\Railken\SQ\Exceptions\QuerySyntaxException $e) {
            throw new \Railken\SQ\Exceptions\QuerySyntaxException($filter);
        }
    }
91161
public function query($query)
    {
        $results = $this->connection->{$this->type}(
            $this->getDn(),
            $query,
            $this->getSelects(),
            $onlyAttributes = false,
            $this->limit
        );

        return $this->newProcessor()->process($results);
    }
1295282
public function setQueries(array $query = []) : self
    {
        if (sizeof($query) == 0) {
            $this->uri['query'] = [];
        } else {
            $this->uri['query'] = $query;
        }

        return $this;
    }
755313
protected function _callQuery($query)
    {
        $query->contain($this->type['contain']);
        $extQuery = $this->type['query'];
        return $extQuery($query);
    }
68485
protected function applyFilter($query)
    {
        if ($this->getModelInformation()->list->disable_filters) {
            return $this;
        }

        $filter = $this->makeFilter();

        if ($filter) {
            $filter->apply($query);
        }

        return $this;
    }
954330
public function getSortConfig(\yii\db\ActiveQuery $query, array $attributes)
    {
        $defaults = $query instanceof ActiveQuery ? $query->getDefaultOrderColumns() : [];
        $sort = [
            'enableMultiSort' => true,
            'attributes' => [],
            'defaultOrder' => $defaults,
        ];

        /** @var TableSchema $tableSchema */
        $tableSchema = $this->getTableSchema();
        foreach ($attributes as $attribute) {
            if ($tableSchema->getColumn($attribute) === null) {
                continue;
            }
            $sort['attributes'][$attribute] = [
                'asc' => array_merge([$attribute => SORT_ASC], $defaults),
                'desc' => array_merge([$attribute => SORT_DESC], $defaults),
            ];
        }
        return $sort;
    }
652338
protected function prepareItems($activeQuery)
    {
        $items = [];
        foreach ($activeQuery->all() as $model) {
            $name = ArrayHelper::getValue($this->modelOptions, 'name', 'name');
            $items[] = [
                'id'       => $model->getPrimaryKey(),
                'content'  => (is_callable($name) ? call_user_func($name, $model) : $model->{$name}),
                'children' => $this->prepareItems($model->children(1)),
            ];
        }
        return $items;
    }
156857
public function filter(Query $query)
    {
        $min = $this->lower->getNewValue();
        $max = $this->upper->getNewValue();

        if (is_empty_string($min) && is_empty_string($max)) {
            return $query;
        }

        $query->whereBetween($this->name(), $min, $max);

        return $query;
    }
1344348
public function setQuery($query)
    {
        $this->query = $query;
        parse_str($this->query, $this->query_array);
        return $this;
    }
1110223
public function union(\pwf\components\querybuilder\interfaces\QueryBuilder $query)
    {
        $this->union[] = $query;
        return $this;
    }