ILIAS  trunk Revision v12.0_alpha-377-g3641b37b9db
ILIAS\User\Profile\DataQuery Class Reference
+ Collaboration diagram for ILIAS\User\Profile\DataQuery:

Public Member Functions

 __construct (private readonly \ilDBInterface $db, private readonly string $user_base_table_name, private readonly string $user_values_table_name, array $select_fields)
 
 withAdditionalAdditionalTableSelectField (string $field_name)
 
 withAdditionalDefaultTableSelectField (string $field_name)
 
 withAdditionalUdfField (Field $field)
 
 withAdditionalMultiField (string $field_name)
 
 withAdditionalJoin (string $join)
 
 withAdditionalWhere (string $where)
 
 withAdditionalMultiDataWhere (string $identifier, string|array $value)
 
 withAdditionalTableOrder (string $order)
 
 withMultiDataTableOrder (string $order_field, string $direction)
 
 withDefaultTableOrderFields (array $order_fields, string $direction)
 
 withLimitedUsers (array $users)
 
 withJoinedMultiDataTable ()
 
 buildRecordsQueryString ()
 
 buildCntQueryString ()
 
 withAdditionalSelectAndJoinForUdfAndMultiValueFields ()
 
 explodeArrayValues (array $row)
 

Private Member Functions

 buildWhere ()
 
 buildJoinForMultiDataTable ()
 

Private Attributes

const string ARRAY_SEPARATOR = '##!:!##'
 
const string RECORDS_QUERY_INIT = 'SELECT '
 
string $cnt_query_init
 
array $multi_fields = []
 
array $select_fields
 
array $udf_fields = []
 
array $join = []
 
array $where = []
 
string $order = ''
 
bool $multi_data_table_joined = false
 
bool $additional_fields_processed = false
 

Detailed Description

Definition at line 25 of file DataQuery.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\User\Profile\DataQuery::__construct ( private readonly \ilDBInterface  $db,
private readonly string  $user_base_table_name,
private readonly string  $user_values_table_name,
array  $select_fields 
)

Definition at line 41 of file DataQuery.php.

46 {
47 $this->cnt_query_init = 'SELECT COUNT(DISTINCT ' . $this->user_base_table_name
48 . '.usr_id) cnt FROM ' . $this->user_base_table_name;
49 $this->select_fields = array_map(
50 fn(string $v): string => $this->user_base_table_name . '.' . $v,
52 );
53 }

References ILIAS\User\Profile\DataQuery\$select_fields.

Member Function Documentation

◆ buildCntQueryString()

ILIAS\User\Profile\DataQuery::buildCntQueryString ( )

Definition at line 166 of file DataQuery.php.

166 : string
167 {
168 return $this->cnt_query_init . PHP_EOL
169 . implode(PHP_EOL, $this->join) . PHP_EOL
170 . 'WHERE usr_data.usr_id <> ' . $this->db->quote(ANONYMOUS_USER_ID, \ilDBConstants::T_INTEGER) . PHP_EOL
171 . $this->buildWhere();
172 }
const ANONYMOUS_USER_ID
Definition: constants.php:27

References ANONYMOUS_USER_ID, ILIAS\User\Profile\DataQuery\buildWhere(), and ilDBConstants\T_INTEGER.

+ Here is the call graph for this function:

◆ buildJoinForMultiDataTable()

ILIAS\User\Profile\DataQuery::buildJoinForMultiDataTable ( )
private

Definition at line 227 of file DataQuery.php.

227 : string
228 {
229 return 'LEFT JOIN ' . $this->user_values_table_name . ' ON '
230 . $this->user_values_table_name . '.usr_id = ' . $this->user_base_table_name . '.usr_id';
231 }

Referenced by ILIAS\User\Profile\DataQuery\withAdditionalSelectAndJoinForUdfAndMultiValueFields(), and ILIAS\User\Profile\DataQuery\withJoinedMultiDataTable().

+ Here is the caller graph for this function:

◆ buildRecordsQueryString()

ILIAS\User\Profile\DataQuery::buildRecordsQueryString ( )

Definition at line 155 of file DataQuery.php.

155 : string
156 {
157 return self::RECORDS_QUERY_INIT . implode(', ', $this->select_fields) . PHP_EOL
158 . 'FROM usr_data' . PHP_EOL
159 . implode(PHP_EOL, $this->join) . PHP_EOL
160 . 'WHERE usr_data.usr_id <> ' . $this->db->quote(ANONYMOUS_USER_ID, \ilDBConstants::T_INTEGER) . PHP_EOL
161 . $this->buildWhere()
162 . 'GROUP BY ' . $this->user_base_table_name . '.usr_id' . PHP_EOL
163 . $this->order;
164 }

References ILIAS\User\Profile\DataQuery\$order, ANONYMOUS_USER_ID, ILIAS\User\Profile\DataQuery\buildWhere(), and ilDBConstants\T_INTEGER.

Referenced by ILIAS\User\Profile\DatabaseDataRepository\retrieveRecordsFromQuery().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildWhere()

ILIAS\User\Profile\DataQuery::buildWhere ( )
private

Definition at line 219 of file DataQuery.php.

219 : string
220 {
221 if ($this->where === []) {
222 return '';
223 }
224 return 'AND ' . implode(PHP_EOL . 'AND ', $this->where) . PHP_EOL;
225 }

Referenced by ILIAS\User\Profile\DataQuery\buildCntQueryString(), and ILIAS\User\Profile\DataQuery\buildRecordsQueryString().

+ Here is the caller graph for this function:

◆ explodeArrayValues()

ILIAS\User\Profile\DataQuery::explodeArrayValues ( array  $row)

Definition at line 205 of file DataQuery.php.

205 : array
206 {
207 return array_map(
208 static function (mixed $v): mixed {
209 if (!is_string($v) || mb_stristr($v, self::ARRAY_SEPARATOR) === false) {
210 return $v;
211 }
212
213 return explode(self::ARRAY_SEPARATOR, $v);
214 },
215 $row
216 );
217 }

Referenced by ILIAS\User\Profile\DatabaseDataRepository\retrieveRecordsFromQuery().

+ Here is the caller graph for this function:

◆ withAdditionalAdditionalTableSelectField()

ILIAS\User\Profile\DataQuery::withAdditionalAdditionalTableSelectField ( string  $field_name)

Definition at line 55 of file DataQuery.php.

55 : self
56 {
57 $clone = clone $this;
58 $clone->select_fields[] = $field_name;
59 return $clone;
60 }

◆ withAdditionalDefaultTableSelectField()

ILIAS\User\Profile\DataQuery::withAdditionalDefaultTableSelectField ( string  $field_name)

Definition at line 62 of file DataQuery.php.

62 : self
63 {
64 $clone = clone $this;
65 $clone->select_fields[] = $this->user_base_table_name . '.' . $field_name;
66 return $clone;
67 }

◆ withAdditionalJoin()

ILIAS\User\Profile\DataQuery::withAdditionalJoin ( string  $join)

Definition at line 83 of file DataQuery.php.

83 : self
84 {
85 $clone = clone $this;
86 $clone->join[] = $join;
87 return $clone;
88 }

References ILIAS\User\Profile\DataQuery\$join.

◆ withAdditionalMultiDataWhere()

ILIAS\User\Profile\DataQuery::withAdditionalMultiDataWhere ( string  $identifier,
string|array  $value 
)

Definition at line 97 of file DataQuery.php.

97 : self
98 {
99 if (is_array($value)) {
100 $value_query = $this->db->in($this->user_values_table_name . '.value', $value, false, \ilDBConstants::T_TEXT);
101 } else {
102 $value_query = $this->db->like($this->user_values_table_name . '.value', \ilDBConstants::T_TEXT, "%{$value}%");
103 }
104 $clone = clone $this;
105 $clone->where[] = $this->user_values_table_name . ".field_id = '{$identifier}' AND {$value_query}";
106 return $clone;
107 }

References ilDBConstants\T_TEXT.

◆ withAdditionalMultiField()

ILIAS\User\Profile\DataQuery::withAdditionalMultiField ( string  $field_name)

Definition at line 76 of file DataQuery.php.

76 : self
77 {
78 $clone = clone $this;
79 $clone->multi_fields[] = $field_name;
80 return $clone;
81 }

◆ withAdditionalSelectAndJoinForUdfAndMultiValueFields()

ILIAS\User\Profile\DataQuery::withAdditionalSelectAndJoinForUdfAndMultiValueFields ( )

Definition at line 174 of file DataQuery.php.

174 : self
175 {
176 if ($this->additional_fields_processed
177 || $this->multi_fields === [] && $this->udf_fields === []) {
178 return $this;
179 }
180
181 $clone = clone $this;
182 if (!$this->multi_data_table_joined) {
183 $clone->join[] = $this->buildJoinForMultiDataTable();
184 $clone->multi_data_table_joined = true;
185 }
186
187 foreach ($this->multi_fields as $field) {
188 $clone->select_fields[] = 'GROUP_CONCAT(DISTINCT IF(' . $this->user_values_table_name
189 . ".field_id = {$this->db->quote($field, \ilDBConstants::T_TEXT)}, "
190 . $this->user_values_table_name . '.value, NULL) '
191 . "SEPARATOR '" . self::ARRAY_SEPARATOR . "') `{$field}`";
192 }
193
194 foreach ($this->udf_fields as $field) {
195 $clone->select_fields[] = 'GROUP_CONCAT(DISTINCT IF(' . $this->user_values_table_name
196 . ".field_id = {$this->db->quote($field->getIdentifier(), \ilDBConstants::T_TEXT)}, "
197 . $this->user_values_table_name . '.value, NULL) '
198 . "SEPARATOR '" . self::ARRAY_SEPARATOR . "') `udf_{$field->getIdentifier()}`";
199 }
200
201 $clone->additional_fields_processed = true;
202 return $clone;
203 }

References ILIAS\User\Profile\DataQuery\buildJoinForMultiDataTable().

+ Here is the call graph for this function:

◆ withAdditionalTableOrder()

ILIAS\User\Profile\DataQuery::withAdditionalTableOrder ( string  $order)

Definition at line 109 of file DataQuery.php.

109 : self
110 {
111 $clone = clone $this;
112 $clone->order = $order;
113 return $clone;
114 }

References ILIAS\User\Profile\DataQuery\$order.

Referenced by ilUserQuery\addOrderToQuery().

+ Here is the caller graph for this function:

◆ withAdditionalUdfField()

ILIAS\User\Profile\DataQuery::withAdditionalUdfField ( Field  $field)

Definition at line 69 of file DataQuery.php.

69 : self
70 {
71 $clone = clone $this;
72 $clone->udf_fields[] = $field;
73 return $clone;
74 }

◆ withAdditionalWhere()

ILIAS\User\Profile\DataQuery::withAdditionalWhere ( string  $where)

Definition at line 90 of file DataQuery.php.

90 : self
91 {
92 $clone = clone $this;
93 $clone->where[] = $where;
94 return $clone;
95 }

References ILIAS\User\Profile\DataQuery\$where.

◆ withDefaultTableOrderFields()

ILIAS\User\Profile\DataQuery::withDefaultTableOrderFields ( array  $order_fields,
string  $direction 
)

Definition at line 123 of file DataQuery.php.

123 : self
124 {
125 $clone = clone $this;
126 $clone->order = 'ORDER BY ' . implode(', ', array_reduce(
127 $order_fields,
128 function (array $c, string $v) use ($direction): array {
129 $c[] = $this->user_base_table_name . ".`{$v}` {$direction}";
130 return $c;
131 },
132 []
133 ));
134 return $clone;
135 }
$c
Definition: deliver.php:25

References $c.

Referenced by ilUserQuery\addOrderToQuery().

+ Here is the caller graph for this function:

◆ withJoinedMultiDataTable()

ILIAS\User\Profile\DataQuery::withJoinedMultiDataTable ( )

Definition at line 147 of file DataQuery.php.

147 : self
148 {
149 $clone = clone $this;
150 $clone->join[] = $this->buildJoinForMultiDataTable();
151 $clone->multi_data_table_joined = true;
152 return $clone;
153 }

References ILIAS\User\Profile\DataQuery\buildJoinForMultiDataTable().

Referenced by ilUserQuery\addUdfFilterToQuery().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ withLimitedUsers()

ILIAS\User\Profile\DataQuery::withLimitedUsers ( array  $users)

Definition at line 137 of file DataQuery.php.

137 : self
138 {
139 if ($users === []) {
140 return $this;
141 }
142 $clone = clone $this;
143 $clone->where[] = $this->db->in('usr_data.usr_id', $users, false, \ilDBConstants::T_INTEGER);
144 return $clone;
145 }

References ilDBConstants\T_INTEGER.

◆ withMultiDataTableOrder()

ILIAS\User\Profile\DataQuery::withMultiDataTableOrder ( string  $order_field,
string  $direction 
)

Definition at line 116 of file DataQuery.php.

116 : self
117 {
118 $clone = clone $this;
119 $clone->order = "ORDER BY `{$order_field}` {$direction}";
120 return $clone;
121 }

Referenced by ilUserQuery\addOrderToQuery().

+ Here is the caller graph for this function:

Field Documentation

◆ $additional_fields_processed

bool ILIAS\User\Profile\DataQuery::$additional_fields_processed = false
private

Definition at line 39 of file DataQuery.php.

◆ $cnt_query_init

string ILIAS\User\Profile\DataQuery::$cnt_query_init
private

Definition at line 30 of file DataQuery.php.

◆ $join

array ILIAS\User\Profile\DataQuery::$join = []
private

Definition at line 35 of file DataQuery.php.

Referenced by ILIAS\User\Profile\DataQuery\withAdditionalJoin().

◆ $multi_data_table_joined

bool ILIAS\User\Profile\DataQuery::$multi_data_table_joined = false
private

Definition at line 38 of file DataQuery.php.

◆ $multi_fields

array ILIAS\User\Profile\DataQuery::$multi_fields = []
private

Definition at line 32 of file DataQuery.php.

◆ $order

string ILIAS\User\Profile\DataQuery::$order = ''
private

◆ $select_fields

array ILIAS\User\Profile\DataQuery::$select_fields
private

Definition at line 33 of file DataQuery.php.

Referenced by ILIAS\User\Profile\DataQuery\__construct().

◆ $udf_fields

array ILIAS\User\Profile\DataQuery::$udf_fields = []
private

Definition at line 34 of file DataQuery.php.

◆ $where

array ILIAS\User\Profile\DataQuery::$where = []
private

Definition at line 36 of file DataQuery.php.

Referenced by ILIAS\User\Profile\DataQuery\withAdditionalWhere().

◆ ARRAY_SEPARATOR

const string ILIAS\User\Profile\DataQuery::ARRAY_SEPARATOR = '##!:!##'
private

Definition at line 27 of file DataQuery.php.

◆ RECORDS_QUERY_INIT

const string ILIAS\User\Profile\DataQuery::RECORDS_QUERY_INIT = 'SELECT '
private

Definition at line 28 of file DataQuery.php.


The documentation for this class was generated from the following file: