Elgg  Version 5.1
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 extends 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->isCallable($order_by)) {
42  $order_by = $this->call($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 }
call($callback, QueryBuilder $qb, $table_alias=null)
Call the expression for the clause.
Definition: Clause.php:48
Interface that allows resolving statements and/or extending query builder.
Definition: Clause.php:14
Database abstraction query builder.
__construct($expr=null, $direction=null)
Constructor.
prepare(QueryBuilder $qb, $table_alias=null)
{}
Extends QueryBuilder with ORDER BY clauses.
isCallable($callback)
Check if a clause expression is callable.
Definition: Clause.php:35
$qb
Definition: queue.php:11