Elgg  Version 3.0
OrderByClause.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Database\Clauses;
4 
5 use Closure;
8 
12 class OrderByClause implements Clause {
13 
17  public $expr;
18 
22  public $direction;
23 
30  public function __construct($expr = null, $direction = null) {
31  $this->expr = $expr;
32  $this->direction = $direction;
33  }
34 
38  public function prepare(QueryBuilder $qb, $table_alias = null) {
39  $order_by = $this->expr;
40 
41  if ($this->expr instanceof Closure) {
42  $order_by = call_user_func($this->expr, $qb, $table_alias);
43  }
44 
45  if ($order_by instanceof CompositeExpression || is_string($order_by)) {
46  $qb->addOrderBy($order_by, $this->direction);
47  }
48  }
49 }
Database abstraction query builder.
__construct($expr=null, $direction=null)
Constructor.
prepare(QueryBuilder $qb, $table_alias=null)
{Build an expression and/or apply it to an instance of query builder.Query builder Table aliasComposi...
Extends QueryBuilder with ORDER BY clauses.
Interface that allows resolving statements and/or extending query builder.
Definition: Clause.php:11