|
|
@ -60,12 +60,12 @@ class BaseQuery extends \yii\base\Object |
|
|
|
* @var string|array how to sort the query results. This refers to the ORDER BY clause in a SQL statement. |
|
|
|
* @var string|array how to sort the query results. This refers to the ORDER BY clause in a SQL statement. |
|
|
|
* It can be either a string (e.g. `'id ASC, name DESC'`) or an array (e.g. `array('id ASC', 'name DESC')`). |
|
|
|
* It can be either a string (e.g. `'id ASC, name DESC'`) or an array (e.g. `array('id ASC', 'name DESC')`). |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public $orderBy; |
|
|
|
public $order; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @var string|array how to group the query results. This refers to the GROUP BY clause in a SQL statement. |
|
|
|
* @var string|array how to group the query results. This refers to the GROUP BY clause in a SQL statement. |
|
|
|
* It can be either a string (e.g. `'company, department'`) or an array (e.g. `array('company', 'department')`). |
|
|
|
* It can be either a string (e.g. `'company, department'`) or an array (e.g. `array('company', 'department')`). |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public $groupBy; |
|
|
|
public $group; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @var string|array how to join with other tables. This refers to the JOIN clause in a SQL statement. |
|
|
|
* @var string|array how to join with other tables. This refers to the JOIN clause in a SQL statement. |
|
|
|
* It can either a string (e.g. `'LEFT JOIN tbl_user ON tbl_user.id=author_id'`) or an array (e.g. |
|
|
|
* It can either a string (e.g. `'LEFT JOIN tbl_user ON tbl_user.id=author_id'`) or an array (e.g. |
|
|
@ -329,11 +329,11 @@ class BaseQuery extends \yii\base\Object |
|
|
|
* The method will automatically quote the column names unless a column contains some parenthesis |
|
|
|
* The method will automatically quote the column names unless a column contains some parenthesis |
|
|
|
* (which means the column contains a DB expression). |
|
|
|
* (which means the column contains a DB expression). |
|
|
|
* @return BaseQuery the query object itself |
|
|
|
* @return BaseQuery the query object itself |
|
|
|
* @see addGroupBy() |
|
|
|
* @see addGroup() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function groupBy($columns) |
|
|
|
public function group($columns) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->groupBy = $columns; |
|
|
|
$this->group = $columns; |
|
|
|
return $this; |
|
|
|
return $this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -344,20 +344,20 @@ class BaseQuery extends \yii\base\Object |
|
|
|
* The method will automatically quote the column names unless a column contains some parenthesis |
|
|
|
* The method will automatically quote the column names unless a column contains some parenthesis |
|
|
|
* (which means the column contains a DB expression). |
|
|
|
* (which means the column contains a DB expression). |
|
|
|
* @return BaseQuery the query object itself |
|
|
|
* @return BaseQuery the query object itself |
|
|
|
* @see groupBy() |
|
|
|
* @see group() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function addGroupBy($columns) |
|
|
|
public function addGroup($columns) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (empty($this->groupBy)) { |
|
|
|
if (empty($this->group)) { |
|
|
|
$this->groupBy = $columns; |
|
|
|
$this->group = $columns; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (!is_array($this->groupBy)) { |
|
|
|
if (!is_array($this->group)) { |
|
|
|
$this->groupBy = preg_split('/\s*,\s*/', trim($this->groupBy), -1, PREG_SPLIT_NO_EMPTY); |
|
|
|
$this->group = preg_split('/\s*,\s*/', trim($this->group), -1, PREG_SPLIT_NO_EMPTY); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!is_array($columns)) { |
|
|
|
if (!is_array($columns)) { |
|
|
|
$columns = preg_split('/\s*,\s*/', trim($columns), -1, PREG_SPLIT_NO_EMPTY); |
|
|
|
$columns = preg_split('/\s*,\s*/', trim($columns), -1, PREG_SPLIT_NO_EMPTY); |
|
|
|
} |
|
|
|
} |
|
|
|
$this->groupBy = array_merge($this->groupBy, $columns); |
|
|
|
$this->group = array_merge($this->group, $columns); |
|
|
|
} |
|
|
|
} |
|
|
|
return $this; |
|
|
|
return $this; |
|
|
|
} |
|
|
|
} |
|
|
@ -427,11 +427,11 @@ class BaseQuery extends \yii\base\Object |
|
|
|
* The method will automatically quote the column names unless a column contains some parenthesis |
|
|
|
* The method will automatically quote the column names unless a column contains some parenthesis |
|
|
|
* (which means the column contains a DB expression). |
|
|
|
* (which means the column contains a DB expression). |
|
|
|
* @return BaseQuery the query object itself |
|
|
|
* @return BaseQuery the query object itself |
|
|
|
* @see addOrderBy() |
|
|
|
* @see addOrder() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function orderBy($columns) |
|
|
|
public function order($columns) |
|
|
|
{ |
|
|
|
{ |
|
|
|
$this->orderBy = $columns; |
|
|
|
$this->order = $columns; |
|
|
|
return $this; |
|
|
|
return $this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -442,20 +442,20 @@ class BaseQuery extends \yii\base\Object |
|
|
|
* The method will automatically quote the column names unless a column contains some parenthesis |
|
|
|
* The method will automatically quote the column names unless a column contains some parenthesis |
|
|
|
* (which means the column contains a DB expression). |
|
|
|
* (which means the column contains a DB expression). |
|
|
|
* @return BaseQuery the query object itself |
|
|
|
* @return BaseQuery the query object itself |
|
|
|
* @see orderBy() |
|
|
|
* @see order() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function addOrderBy($columns) |
|
|
|
public function addOrder($columns) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (empty($this->orderBy)) { |
|
|
|
if (empty($this->order)) { |
|
|
|
$this->orderBy = $columns; |
|
|
|
$this->order = $columns; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (!is_array($this->orderBy)) { |
|
|
|
if (!is_array($this->order)) { |
|
|
|
$this->orderBy = preg_split('/\s*,\s*/', trim($this->orderBy), -1, PREG_SPLIT_NO_EMPTY); |
|
|
|
$this->order = preg_split('/\s*,\s*/', trim($this->order), -1, PREG_SPLIT_NO_EMPTY); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!is_array($columns)) { |
|
|
|
if (!is_array($columns)) { |
|
|
|
$columns = preg_split('/\s*,\s*/', trim($columns), -1, PREG_SPLIT_NO_EMPTY); |
|
|
|
$columns = preg_split('/\s*,\s*/', trim($columns), -1, PREG_SPLIT_NO_EMPTY); |
|
|
|
} |
|
|
|
} |
|
|
|
$this->orderBy = array_merge($this->orderBy, $columns); |
|
|
|
$this->order = array_merge($this->order, $columns); |
|
|
|
} |
|
|
|
} |
|
|
|
return $this; |
|
|
|
return $this; |
|
|
|
} |
|
|
|
} |
|
|
@ -541,7 +541,7 @@ class BaseQuery extends \yii\base\Object |
|
|
|
* takes precedence over this query. |
|
|
|
* takes precedence over this query. |
|
|
|
* - [[where]], [[having]]: the new query's corresponding property value |
|
|
|
* - [[where]], [[having]]: the new query's corresponding property value |
|
|
|
* will be 'AND' together with the existing one. |
|
|
|
* will be 'AND' together with the existing one. |
|
|
|
* - [[params]], [[orderBy]], [[groupBy]], [[join]], [[union]]: the new query's |
|
|
|
* - [[params]], [[order]], [[group]], [[join]], [[union]]: the new query's |
|
|
|
* corresponding property value will be appended to the existing one. |
|
|
|
* corresponding property value will be appended to the existing one. |
|
|
|
* |
|
|
|
* |
|
|
|
* In general, the merging makes the resulting query more restrictive and specific. |
|
|
|
* In general, the merging makes the resulting query more restrictive and specific. |
|
|
@ -592,12 +592,12 @@ class BaseQuery extends \yii\base\Object |
|
|
|
$this->addParams($query->params); |
|
|
|
$this->addParams($query->params); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($query->orderBy !== null) { |
|
|
|
if ($query->order !== null) { |
|
|
|
$this->addOrderBy($query->orderBy); |
|
|
|
$this->addOrder($query->order); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($query->groupBy !== null) { |
|
|
|
if ($query->group !== null) { |
|
|
|
$this->addGroupBy($query->groupBy); |
|
|
|
$this->addGroup($query->group); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($query->join !== null) { |
|
|
|
if ($query->join !== null) { |
|
|
|