Elgg  Version master
TypeSubtypeWhereClause.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Database\Clauses;
4 
6 
11 
15  public $type_column = 'type';
16 
20  public $subtype_column = 'subtype';
21 
25  public $type_subtype_pairs = [];
26 
30  public function prepare(QueryBuilder $qb, $table_alias = null) {
31 
32  $alias = function ($column) use ($table_alias) {
33  return $table_alias ? "{$table_alias}.{$column}" : $column;
34  };
35 
36  $types_where = [];
37 
38  if (!empty($this->type_subtype_pairs)) {
39  foreach ($this->type_subtype_pairs as $type => $subtypes) {
40  if (is_array($subtypes) && !empty($subtypes)) {
41  $types_where[] = $qb->merge([
42  $qb->compare($alias($this->type_column), '=', $type, ELGG_VALUE_STRING),
43  $qb->compare($alias($this->subtype_column), '=', $subtypes, ELGG_VALUE_STRING),
44  ]);
45  } else {
46  $types_where[] = $qb->compare($alias($this->type_column), '=', $type, ELGG_VALUE_STRING);
47  }
48  }
49  }
50 
51  $wheres = [];
52  if (!empty($types_where)) {
53  $wheres[] = $qb->merge($types_where, 'OR');
54  }
55 
56  $wheres[] = parent::prepare($qb, $table_alias);
57 
58  return $qb->merge($wheres);
59  }
60 }
prepare(QueryBuilder $qb, $table_alias=null)
{}
$column
Definition: add.php:10
Database abstraction query builder.
$type
Definition: delete.php:21
compare(string $x, string $comparison, $y=null, string $type=null, bool $case_sensitive=null)
Build value comparison clause.
Builds clauses for filtering entities by their type and subtype.
Builds a clause from closure or composite expression.
Definition: WhereClause.php:11
merge($parts=null, $boolean= 'AND')
Merges multiple composite expressions with a boolean.
const ELGG_VALUE_STRING
Definition: constants.php:112
$subtypes
$qb
Definition: queue.php:12