Elgg  Version 6.3
RelationshipWhereClause.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 $names;
21 
27  public $guid_one;
28 
34  public $guid_two;
35 
40 
45 
46  public bool $inverse = false;
47 
48  public string $join_on = 'guid';
49 
53  public function prepare(QueryBuilder $qb, $table_alias = null) {
54  $alias = function ($column) use ($table_alias) {
55  return $table_alias ? "{$table_alias}.{$column}" : $column;
56  };
57 
58  $wheres = [];
59 
60  $wheres[] = parent::prepare($qb, $table_alias);
61 
62  $wheres[] = $qb->compare($alias('id'), '=', $this->ids, ELGG_VALUE_ID);
63  $wheres[] = $qb->compare($alias('relationship'), '=', $this->names, ELGG_VALUE_STRING);
64  $wheres[] = $qb->compare($alias('guid_one'), '=', $this->guid_one, ELGG_VALUE_GUID);
65  $wheres[] = $qb->compare($alias('guid_two'), '=', $this->guid_two, ELGG_VALUE_GUID);
66  $wheres[] = $qb->between($alias('time_created'), $this->created_after, $this->created_before, ELGG_VALUE_TIMESTAMP);
67 
68  return $qb->merge($wheres);
69  }
70 
80  public static function factory(array $attributes): static {
81  $result = new static();
82 
83  $array_attributes = [
84  'ids',
85  'names',
86  'guid_one',
87  'guid_two',
88  ];
89  foreach ($array_attributes as $array_key) {
90  if (isset($attributes[$array_key])) {
91  $result->{$array_key} = (array) $attributes[$array_key];
92  }
93  }
94 
95  $singular_attributes = [
96  'join_on',
97  'inverse',
98  'created_after',
99  'created_before',
100  ];
101  foreach ($singular_attributes as $array_key) {
102  if (isset($attributes[$array_key])) {
103  $result->{$array_key} = $attributes[$array_key];
104  }
105  }
106 
107  return $result;
108  }
109 }
$column
Definition: add.php:10
$attributes
Elgg AJAX loader.
Definition: ajax_loader.php:10
Builds clauses for filtering entities by their properties in entity_relationships table.
static factory(array $attributes)
Build a new RelationshipWhereClause.
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
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