Elgg  Version 6.0
OrderByClause.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Database\Clauses;
4 
7 
11 class OrderByClause extends Clause {
12 
16  public $expr;
17 
21  public $direction;
22 
29  public function __construct($expr = null, $direction = null) {
30  $this->expr = $expr;
31  $this->direction = $direction;
32  }
33 
37  public function prepare(QueryBuilder $qb, $table_alias = null) {
38  $order_by = $this->expr;
39 
40  if ($this->isCallable($order_by)) {
41  $order_by = $this->call($this->expr, $qb, $table_alias);
42  }
43 
44  if ($order_by instanceof CompositeExpression || is_string($order_by)) {
45  $qb->addOrderBy($order_by, $this->direction);
46  }
47  }
48 }
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
addOrderBy(string $sort,?string $order=null)
{}
$qb
Definition: queue.php:12