本文整理匯總了PHP中Propel\Runtime\ActiveQuery\Criteria::getGroupByColumns方法的典型用法代碼示例。如果您正苦於以下問題:PHP Criteria::getGroupByColumns方法的具體用法?PHP Criteria::getGroupByColumns怎麽用?PHP Criteria::getGroupByColumns使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Propel\Runtime\ActiveQuery\Criteria
的用法示例。
在下文中一共展示了Criteria::getGroupByColumns方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: mergeWith
/**
* Add the content of a Criteria to the current Criteria
* In case of conflict, the current Criteria keeps its properties
*
* @param Criteria $criteria The criteria to read properties from
* @param string $operator The logical operator used to combine conditions
* Defaults to Criteria::LOGICAL_AND, also accepts Criteria::LOGICAL_OR
* This parameter is deprecated, use _or() instead
*
* @return $this|Criteria The current criteria object
*/
public function mergeWith(Criteria $criteria, $operator = null)
{
// merge limit
$limit = $criteria->getLimit();
if (0 != $limit && -1 === $this->getLimit()) {
$this->limit = $limit;
}
// merge offset
$offset = $criteria->getOffset();
if (0 != $offset && 0 === $this->getOffset()) {
$this->offset = $offset;
}
// merge select modifiers
$selectModifiers = $criteria->getSelectModifiers();
if ($selectModifiers && !$this->selectModifiers) {
$this->selectModifiers = $selectModifiers;
}
// merge select columns
$this->selectColumns = array_merge($this->getSelectColumns(), $criteria->getSelectColumns());
// merge as columns
$commonAsColumns = array_intersect_key($this->getAsColumns(), $criteria->getAsColumns());
if (!empty($commonAsColumns)) {
throw new LogicException('The given criteria contains an AsColumn with an alias already existing in the current object');
}
$this->asColumns = array_merge($this->getAsColumns(), $criteria->getAsColumns());
// merge orderByColumns
$orderByColumns = array_merge($this->getOrderByColumns(), $criteria->getOrderByColumns());
$this->orderByColumns = array_unique($orderByColumns);
// merge groupByColumns
$groupByColumns = array_merge($this->getGroupByColumns(), $criteria->getGroupByColumns());
$this->groupByColumns = array_unique($groupByColumns);
// merge where conditions
if (Criteria::LOGICAL_OR === $operator) {
$this->_or();
}
$isFirstCondition = true;
foreach ($criteria->getMap() as $key => $criterion) {
if ($isFirstCondition && Criteria::LOGICAL_OR === $this->defaultCombineOperator) {
$this->addOr($criterion, null, null, false);
$this->defaultCombineOperator = Criteria::LOGICAL_AND;
} elseif ($this->containsKey($key)) {
$this->addAnd($criterion);
} else {
$this->add($criterion);
}
$isFirstCondition = false;
}
// merge having
$having = $criteria->getHaving();
if ($having) {
if ($this->getHaving()) {
$this->addHaving($this->getHaving()->addAnd($having));
} else {
$this->addHaving($having);
}
}
// merge alias
$commonAliases = array_intersect_key($this->getAliases(), $criteria->getAliases());
if (!empty($commonAliases)) {
throw new LogicException('The given criteria contains an alias already existing in the current object');
}
$this->aliases = array_merge($this->getAliases(), $criteria->getAliases());
// merge join
$this->joins = array_merge($this->getJoins(), $criteria->getJoins());
return $this;
}
示例2: applyGroupBy
/**
* @param string $sql
* @param Criteria $criteria
*/
public function applyGroupBy(&$sql, Criteria $criteria)
{
$groupBy = $criteria->getGroupByColumns();
if ($groupBy) {
$sql .= ' GROUP BY ' . implode(',', $groupBy);
}
}
示例3: testMergeWithGroupByColumns
public function testMergeWithGroupByColumns()
{
$c1 = new Criteria();
$c1->addGroupByColumn(BookTableMap::COL_TITLE);
$c1->addGroupByColumn(BookTableMap::COL_ID);
$c2 = new Criteria();
$c1->mergeWith($c2);
$this->assertEquals(array(BookTableMap::COL_TITLE, BookTableMap::COL_ID), $c1->getGroupByColumns(), 'mergeWith() does not remove an existing groupby columns');
$c1 = new Criteria();
$c2 = new Criteria();
$c2->addGroupByColumn(BookTableMap::COL_TITLE);
$c2->addGroupByColumn(BookTableMap::COL_ID);
$c1->mergeWith($c2);
$this->assertEquals(array(BookTableMap::COL_TITLE, BookTableMap::COL_ID), $c1->getGroupByColumns(), 'mergeWith() merges the select columns to an empty groupby');
$c1 = new Criteria();
$c1->addGroupByColumn(BookTableMap::COL_TITLE);
$c2 = new Criteria();
$c2->addGroupByColumn(BookTableMap::COL_ID);
$c1->mergeWith($c2);
$this->assertEquals(array(BookTableMap::COL_TITLE, BookTableMap::COL_ID), $c1->getGroupByColumns(), 'mergeWith() merges the select columns after the existing groupby columns');
$c1 = new Criteria();
$c1->addGroupByColumn(BookTableMap::COL_TITLE);
$c2 = new Criteria();
$c2->addGroupByColumn(BookTableMap::COL_TITLE);
$c1->mergeWith($c2);
$this->assertEquals(array(BookTableMap::COL_TITLE), $c1->getGroupByColumns(), 'mergeWith() does not merge duplicated groupby columns');
}
示例4: applyGroupBy
/**
* @param string $sql
* @param Criteria $criteria
*/
public function applyGroupBy(&$sql, Criteria $criteria)
{
$groupBy = $criteria->getGroupByColumns();
if ($groupBy) {
// check if all selected columns are groupBy'ed.
$selected = $this->getPlainSelectedColumns($criteria);
$asSelects = $criteria->getAsColumns();
foreach ($selected as $colName) {
if (!in_array($colName, $groupBy)) {
// is a alias there that is grouped?
if ($alias = array_search($colName, $asSelects)) {
if (in_array($alias, $groupBy)) {
continue;
//yes, alias is selected.
}
}
$groupBy[] = $colName;
}
}
if ($groupBy) {
$sql .= ' GROUP BY ' . implode(',', $groupBy);
}
}
}
示例5: getGroupBy
/**
* @param Criteria $criteria
*
* @return string
*/
public function getGroupBy(Criteria $criteria)
{
$groupBy = $criteria->getGroupByColumns();
if ($groupBy) {
return ' GROUP BY ' . implode(',', $groupBy);
}
}