Elgg  Version 6.1
JoinClause.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Database\Clauses;
4 
7 
11 class JoinClause extends Clause {
12 
16  public $joined_table;
17 
21  public $joined_alias;
22 
26  public $condition;
27 
31  public $join_type;
32 
41  public function __construct($joined_table, $joined_alias = null, $condition = null, $join_type = 'inner') {
42  $this->joined_table = $joined_table;
43  $this->joined_alias = $joined_alias;
44  $this->condition = $condition;
45  $this->join_type = $join_type;
46  }
47 
51  public function prepare(QueryBuilder $qb, $table_alias = null) {
53  if (!isset($joined_alias)) {
55  }
56 
58  if ($this->isCallable($condition)) {
59  $condition = $this->callJoin($condition, $qb, $joined_alias, $table_alias);
60  } else if ($condition === null) {
61  $condition = true;
62  }
63 
64  switch (strtolower($this->join_type ?? '')) {
65  case 'left':
66  $qb->leftJoin($table_alias, $this->joined_table, $joined_alias, $condition);
67  break;
68 
69  case 'right':
70  $qb->rightJoin($table_alias, $this->joined_table, $joined_alias, $condition);
71  break;
72 
73  default:
74  $qb->join($table_alias, $this->joined_table, $joined_alias, $condition);
75  break;
76  }
77 
78  return $joined_alias;
79  }
80 }
Interface that allows resolving statements and/or extending query builder.
Definition: Clause.php:14
__construct($joined_table, $joined_alias=null, $condition=null, $join_type= 'inner')
Constructor.
Definition: JoinClause.php:41
Extends QueryBuilder with JOIN clauses.
Definition: JoinClause.php:11
Database abstraction query builder.
getNextJoinAlias()
Get an index of the next available join alias.
isCallable($callback)
Check if a clause expression is callable.
Definition: Clause.php:35
callJoin($callback, QueryBuilder $qb, $joined_alias, $table_alias=null)
Call the expression for a join clause.
Definition: Clause.php:72
rightJoin(string $fromAlias, string $join, string $alias,?string $condition=null)
{}
join(string $fromAlias, string $join, string $alias,?string $condition=null)
{}
leftJoin(string $fromAlias, string $join, string $alias,?string $condition=null)
{}
$qb
Definition: queue.php:12
prepare(QueryBuilder $qb, $table_alias=null)
{}
Definition: JoinClause.php:51