Elgg  Version 3.0
GroupByClause.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Database\Clauses;
4 
5 use Closure;
8 
12 class GroupByClause implements Clause {
13 
17  public $expr;
18 
24  public function __construct($expr) {
25  $this->expr = $expr;
26  }
27 
31  public function prepare(QueryBuilder $qb, $table_alias = null) {
32  $group_by = $this->expr;
33 
34  if ($this->expr instanceof Closure) {
35  $group_by = call_user_func($this->expr, $qb, $table_alias);
36  }
37 
38  if ($group_by instanceof CompositeExpression || is_string($group_by)) {
39  $qb->addGroupBy($group_by);
40  }
41  }
42 }
Database abstraction query builder.
Extends QueryBuilder with GROUP BY statements.
Interface that allows resolving statements and/or extending query builder.
Definition: Clause.php:11
prepare(QueryBuilder $qb, $table_alias=null)
{Build an expression and/or apply it to an instance of query builder.Query builder Table aliasComposi...