Elgg  Version 6.3
MetadataWhereClause.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Elgg\Database\Clauses;
4 
6 
11 
15  public $ids;
16 
20  public $entity_guids;
21 
25  public $names;
26 
30  public $values;
31 
36 
41 
42  public string $value_type = ELGG_VALUE_STRING;
43 
44  public bool $case_sensitive = true;
45 
46  public string $comparison = '=';
47 
51  public function prepare(QueryBuilder $qb, $table_alias = null) {
52  $alias = function ($column) use ($table_alias) {
53  return $table_alias ? "{$table_alias}.{$column}" : $column;
54  };
55 
56  $wheres = [];
57  $wheres[] = parent::prepare($qb, $table_alias);
58 
59  $wheres[] = $qb->compare($alias('id'), '=', $this->ids, ELGG_VALUE_ID);
60  $wheres[] = $qb->compare($alias('name'), '=', $this->names, ELGG_VALUE_STRING);
61  $wheres[] = $qb->compare($alias('value'), $this->comparison, $this->values, $this->value_type, $this->case_sensitive);
62  $wheres[] = $qb->compare($alias('entity_guid'), '=', $this->entity_guids, ELGG_VALUE_GUID);
63  $wheres[] = $qb->between($alias('time_created'), $this->created_after, $this->created_before, ELGG_VALUE_TIMESTAMP);
64 
65  return $qb->merge($wheres);
66  }
67 
77  public static function factory(array $attributes): static {
78  $result = new static();
79 
80  $array_attributes = [
81  'ids',
82  'entity_guids',
83  'names',
84  'values',
85  ];
86  foreach ($array_attributes as $array_key) {
87  if (isset($attributes[$array_key])) {
88  $result->{$array_key} = (array) $attributes[$array_key];
89  }
90  }
91 
92  $singular_attributes = [
93  'comparison',
94  'value_type',
95  'case_sensitive',
96  'created_after',
97  'created_before',
98  ];
99  foreach ($singular_attributes as $array_key) {
100  if (isset($attributes[$array_key])) {
101  $result->{$array_key} = $attributes[$array_key];
102  }
103  }
104 
105  return $result;
106  }
107 }
$column
Definition: add.php:10
$attributes
Elgg AJAX loader.
Definition: ajax_loader.php:10
Builds clauses for filtering entities by properties in metadata table.
prepare(QueryBuilder $qb, $table_alias=null)
{{Build an expression and/or apply it to an instance of query builder.Query builder Table aliasCompos...
static factory(array $attributes)
Build a new MetadataWhereClause.
Builds a clause from closure or composite expression.
Definition: WhereClause.php:11
Database abstraction query builder.
const ELGG_VALUE_STRING
Definition: constants.php:112
const ELGG_VALUE_ID
Definition: constants.php:114
const ELGG_VALUE_GUID
Definition: constants.php:113
const ELGG_VALUE_TIMESTAMP
Definition: constants.php:115
$qb
Definition: queue.php:14