Elgg  Version 3.0
JoinClause.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Database\Clauses;
4 
5 use Closure;
8 
12 class JoinClause implements Clause {
13 
17  public $joined_table;
18 
22  public $joined_alias;
23 
27  public $condition;
28 
32  public $join_type;
33 
42  public function __construct($joined_table, $joined_alias = null, $condition = null, $join_type = 'inner') {
43  $this->joined_table = $joined_table;
44  $this->joined_alias = $joined_alias;
45  $this->condition = $condition;
46  $this->join_type = $join_type;
47  }
48 
52  public function prepare(QueryBuilder $qb, $table_alias = null) {
54  if (!isset($joined_alias)) {
56  }
57 
59  if ($condition instanceof Closure) {
60  $condition = call_user_func($condition, $qb, $joined_alias, $table_alias);
61  } else if ($condition === null) {
62  $condition = true;
63  }
64 
65  switch (strtolower($this->join_type)) {
66  case 'left' :
67  $qb->leftJoin($table_alias, $this->joined_table, $joined_alias, $condition);
68  break;
69 
70  case 'right' :
71  $qb->rightJoin($table_alias, $this->joined_table, $joined_alias, $condition);
72  break;
73 
74  default:
75  $qb->join($table_alias, $this->joined_table, $joined_alias, $condition);
76  break;
77  }
78 
79  return $joined_alias;
80  }
81 }
__construct($joined_table, $joined_alias=null, $condition=null, $join_type= 'inner')
Constructor.
Definition: JoinClause.php:42
Extends QueryBuilder with JOIN clauses.
Definition: JoinClause.php:12
Database abstraction query builder.
rightJoin($fromAlias, $join, $alias, $condition=null)
{}
join($fromAlias, $join, $alias, $condition=null)
{}
leftJoin($fromAlias, $join, $alias, $condition=null)
{}
getNextJoinAlias()
Get an index of the next available join alias.
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...
Definition: JoinClause.php:52