/** * Generates a SELECT SQL statement from a [[Query]] object. * @param Query $query the [[Query]] object from which the SQL statement will be generated. * @param array $params the parameters to be bound to the generated SQL statement. These parameters will * be included in the result with the additional parameters generated during the query building process. * @return array the generated SQL statement (the first array element) and the corresponding * parameters to be bound to the SQL statement (the second array element). The parameters returned * include those provided in `$params`. */ public function build($query) { $modelClass = $query->modelClass; $this->_baseUrl = $modelClass::getApiUrlBase(); $query->prepare($this); $clauses = ArrayHelper::merge($this->buildSelect($query->select, $query->distinct, $query->selectOption), $this->buildOrderByAndLimit($query->orderBy, $query->limit, $query->offset), $this->buildFilter($modelClass, $query->where), ['page' => Yii::$app->request->get('page')], $this->buildExpand($query->with)); if (!empty($query->orderBy)) { foreach ($query->orderBy as $expression) { if ($expression instanceof Expression) { $params = array_merge($params, $expression->params); } } } return [$this->_baseUrl, $clauses]; }
/** * Constructor. * @param string $modelClass the model class associated with this query * @param array $config configurations to be applied to the newly created query object */ public function __construct($modelClass, $config = []) { $this->modelClass = $modelClass; parent::__construct($config); }