mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Update DboSource::group():
* Update documentation. * Add Model type hint. * Bail early when fields are empty.
This commit is contained in:
parent
5c595b90d2
commit
63a192ea39
1 changed files with 21 additions and 15 deletions
|
@ -2870,26 +2870,32 @@ class DboSource extends DataSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a GROUP BY SQL clause
|
* Create a GROUP BY SQL clause.
|
||||||
*
|
*
|
||||||
* @param string $group Group By Condition
|
* @param string|array $fields Group By fields
|
||||||
* @param Model $model
|
* @param Model $Model
|
||||||
* @return string string condition or null
|
* @return string Group By clause or null.
|
||||||
*/
|
*/
|
||||||
public function group($group, $model = null) {
|
public function group($fields, Model $Model = null) {
|
||||||
if ($group) {
|
if (empty($fields)) {
|
||||||
if (!is_array($group)) {
|
return null;
|
||||||
$group = array($group);
|
}
|
||||||
}
|
|
||||||
foreach ($group as $index => $key) {
|
if (!is_array($fields)) {
|
||||||
if (is_object($model) && $model->isVirtualField($key)) {
|
$fields = array($fields);
|
||||||
$group[$index] = '(' . $model->getVirtualField($key) . ')';
|
}
|
||||||
|
|
||||||
|
if (!empty($Model)) {
|
||||||
|
foreach ($fields as $index => $key) {
|
||||||
|
if ($Model->isVirtualField($key)) {
|
||||||
|
$fields[$index] = '(' . $Model->getVirtualField($key) . ')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$group = implode(', ', $group);
|
|
||||||
return ' GROUP BY ' . $this->_quoteFields($group);
|
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
$fields = implode(', ', $fields);
|
||||||
|
|
||||||
|
return ' GROUP BY ' . $this->_quoteFields($fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue