Elgg  Version 6.3
AttributeWhereClause.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Database\Clauses;
4 
6 
11 
15  public $names;
16 
20  public $values;
21 
22  public string $comparison = '=';
23 
24  public string $value_type = ELGG_VALUE_STRING;
25 
29  public function prepare(QueryBuilder $qb, $table_alias = null) {
30  $alias = function ($column) use ($table_alias) {
31  return $table_alias ? "{$table_alias}.{$column}" : $column;
32  };
33 
34  $wheres = [];
35  $wheres[] = parent::prepare($qb, $table_alias);
36 
37  foreach ((array) $this->names as $name) {
38  $wheres[] = $qb->compare($alias($name), $this->comparison, $this->values, $this->value_type);
39  }
40 
41  return $qb->merge($wheres);
42  }
43 
53  public static function factory(array $attributes): static {
54  $result = new static();
55 
56  $array_attributes = [
57  'names',
58  'values',
59  ];
60  foreach ($array_attributes as $array_key) {
61  if (isset($attributes[$array_key])) {
62  $result->{$array_key} = (array) $attributes[$array_key];
63  }
64  }
65 
66  $singular_attributes = [
67  'comparison',
68  'value_type',
69  ];
70  foreach ($singular_attributes as $array_key) {
71  if (isset($attributes[$array_key])) {
72  $result->{$array_key} = $attributes[$array_key];
73  }
74  }
75 
76  return $result;
77  }
78 }
if(! $user||! $user->canDelete()) $name
Definition: delete.php:22
$column
Definition: add.php:10
$attributes
Elgg AJAX loader.
Definition: ajax_loader.php:10
Builds queries for matching entities by their attributes.
static factory(array $attributes)
Build a new AttributeWhereClause.
prepare(QueryBuilder $qb, $table_alias=null)
{{Build an expression and/or apply it to an instance of query builder.Query builder Table aliasCompos...
Builds a clause from closure or composite expression.
Definition: WhereClause.php:11
Database abstraction query builder.
const ELGG_VALUE_STRING
Definition: constants.php:112
$qb
Definition: queue.php:14