PluginProbe
VikBooking Hotel Booking Engine & PMS / trunk
VikBooking Hotel Booking Engine & PMS vtrunk
1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 All 36 releases
vikbooking / admin / helpers / src / chat / search.php

search.php in VikBooking Hotel Booking Engine & PMS trunk, at admin/helpers/src/chat/search.php

494 lines 9.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2026 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 /**
15 * Encpsulates the supported search techniques.
16 *
17 * @since 1.8
18 */
19 class VBOChatSearch
20 {
21 /**
22 * The pagination offset.
23 *
24 * @var int|null
25 */
26 protected $start = null;
27
28 /**
29 * The pagination limit.
30 *
31 * @var int|null
32 */
33 protected $limit = null;
34
35 /**
36 * Searches the messages by context.
37 *
38 * @var VBOChatContext|null
39 */
40 protected $context = null;
41
42 /**
43 * Searches the messages under the specified context aliases.
44 *
45 * @var string[]
46 * @since 1.8.8
47 */
48 protected $categories = [];
49
50 /**
51 * Searches the messages by ID.
52 * The object contains the "id" and "operator" properties.
53 *
54 * @var object|null
55 */
56 protected $message = null;
57
58 /**
59 * Searches the messages by sender ID.
60 * The object contains the "id" and "operator" properties.
61 *
62 * @var object|null
63 */
64 protected $sender = null;
65
66 /**
67 * Searches the messages by date.
68 * The object contains the "utc" and "operator" properties.
69 *
70 * @var object|null
71 */
72 protected $date = null;
73
74 /**
75 * The ID of the user that is requesting the search.
76 *
77 * @var int|null
78 */
79 protected $readerId = null;
80
81 /**
82 * Whether the system should return only the unread messages.
83 *
84 * @var bool
85 */
86 protected $unread = false;
87
88 /**
89 * Whether the results should be aggregated per message.
90 *
91 * @var bool
92 */
93 protected $aggregate = false;
94
95 /**
96 * The ID of the external resource the message is linked to.
97 *
98 * @var string|null
99 * @since 1.8.8
100 */
101 protected $refId = null;
102
103 /**
104 * Sets the specified pagination offset.
105 *
106 * @param int $start
107 *
108 * @return self
109 */
110 public function start(?int $start)
111 {
112 $this->start = is_null($start) ? null : abs($start);
113
114 return $this;
115 }
116
117 /**
118 * Checks whether a custom start position has been specified.
119 *
120 * @return bool
121 */
122 public function hasStart()
123 {
124 return $this->start !== null;
125 }
126
127 /**
128 * Returns the specified pagination offset (0 if not provided).
129 *
130 * @return int
131 */
132 public function getStart()
133 {
134 return $this->start ?: 0;
135 }
136
137 /**
138 * Sets the specified pagination limit.
139 *
140 * @param int|null $limit
141 *
142 * @return self
143 */
144 public function limit(?int $limit)
145 {
146 $this->limit = is_null($limit) ? null : abs($limit);
147
148 return $this;
149 }
150
151 /**
152 * Checks whether a custom limit has been specified.
153 *
154 * @return bool
155 */
156 public function hasLimit()
157 {
158 return $this->limit !== null;
159 }
160
161 /**
162 * Returns the specified pagination limit (0 if not provided).
163 *
164 * @return int|null
165 */
166 public function getLimit()
167 {
168 return $this->limit;
169 }
170
171 /**
172 * Sets the specified context parent.
173 *
174 * @param VBOChatContext $context
175 *
176 * @return self
177 */
178 public function withContext(?VBOChatContext $context)
179 {
180 $this->context = $context;
181
182 return $this;
183 }
184
185 /**
186 * Checks whether a custom context has been specified.
187 *
188 * @return bool
189 */
190 public function hasContext()
191 {
192 return $this->context !== null;
193 }
194
195 /**
196 * Returns the specified context parent, if any.
197 *
198 * @return VBOChatContext|null
199 */
200 public function getContext()
201 {
202 return $this->context;
203 }
204
205 /**
206 * Sets the supported categories.
207 *
208 * @param string[] $categories
209 *
210 * @return self
211 *
212 * @since 1.8.8
213 */
214 public function forCategories(array $categories)
215 {
216 $this->categories = $categories;
217
218 return $this;
219 }
220
221 /**
222 * Checks whether custom categories have been specified.
223 *
224 * @return bool
225 *
226 * @since 1.8.8
227 */
228 public function hasCategories()
229 {
230 return (bool) $this->categories;
231 }
232
233 /**
234 * Returns the specified categories, if any.
235 *
236 * @return string[]
237 *
238 * @since 1.8.8
239 */
240 public function getCategories()
241 {
242 return $this->categories;
243 }
244
245 /**
246 * Sets the specified message ID.
247 *
248 * @param int $messageId The ID of the message.
249 * @param string $operator Used to set the comparison operator.
250 *
251 * @return self
252 */
253 public function message(?int $messageId, string $operator = '=')
254 {
255 if ($messageId !== null) {
256 $this->message = new stdClass;
257 $this->message->id = $messageId;
258 $this->message->operator = $operator;
259 } else {
260 $this->message = null;
261 }
262
263 return $this;
264 }
265
266 /**
267 * Checks whether a custom message has been specified.
268 *
269 * @return bool
270 */
271 public function hasMessage()
272 {
273 return $this->message !== null;
274 }
275
276 /**
277 * Returns the specified message, if any.
278 *
279 * @return object|null
280 */
281 public function getMessage()
282 {
283 return $this->message;
284 }
285
286 /**
287 * Sets the specified sender ID.
288 *
289 * @param int $senderId The ID of the sender.
290 * @param bool $equals Whether the search should match the ID.
291 *
292 * @return self
293 */
294 public function sender(?int $senderId, bool $equals = true)
295 {
296 if ($senderId !== null) {
297 $this->sender = new stdClass;
298 $this->sender->id = $senderId;
299 $this->sender->operator = $equals ? '=' : '<>';
300 } else {
301 $this->sender = null;
302 }
303
304 return $this;
305 }
306
307 /**
308 * Checks whether a custom sender has been specified.
309 *
310 * @return bool
311 */
312 public function hasSender()
313 {
314 return $this->sender !== null;
315 }
316
317 /**
318 * Returns the specified sender, if any.
319 *
320 * @return object|null
321 */
322 public function getSender()
323 {
324 return $this->sender;
325 }
326
327 /**
328 * Sets the specified date.
329 *
330 * @param mixed $date The search date.
331 * @param string $operator Used to set the comparison operator.
332 *
333 * @return self
334 */
335 public function date($date, string $operator = '=')
336 {
337 if ($date !== null) {
338 if (is_scalar($date)) {
339 $date = JFactory::getDate($date)->toSql();
340 }
341
342 $this->date = new stdClass;
343 $this->date->utc = $date;
344 $this->date->operator = $operator;
345 } else {
346 $this->date = null;
347 }
348
349 return $this;
350 }
351
352 /**
353 * Checks whether a custom date has been specified.
354 *
355 * @return bool
356 */
357 public function hasDate()
358 {
359 return $this->date !== null;
360 }
361
362 /**
363 * Returns the specified date, if any.
364 *
365 * @return object|null
366 */
367 public function getDate()
368 {
369 return $this->date;
370 }
371
372 /**
373 * Sets the specified reader ID.
374 *
375 * @param int|null $readerId
376 *
377 * @return self
378 */
379 public function reader(?int $readerId)
380 {
381 $this->readerId = $readerId;
382
383 return $this;
384 }
385
386 /**
387 * Checks whether a custom reader has been specified.
388 *
389 * @return bool
390 */
391 public function hasReader()
392 {
393 return $this->readerId !== null;
394 }
395
396 /**
397 * Returns the specified reader.
398 *
399 * @return int|null
400 */
401 public function getReader()
402 {
403 return $this->readerId;
404 }
405
406 /**
407 * Sets whether only unread messages should be returned.
408 *
409 * @param bool $unread
410 *
411 * @return self
412 */
413 public function unread(bool $unread = true)
414 {
415 $this->unread = $unread;
416
417 return $this;
418 }
419
420 /**
421 * Checks whether only unread messages should be returned.
422 *
423 * @return bool
424 */
425 public function hasUnread()
426 {
427 return $this->unread;
428 }
429
430 /**
431 * Sets whether the messages should be aggregated.
432 *
433 * @param bool $aggregate
434 *
435 * @return self
436 */
437 public function aggregate(bool $aggregate = true)
438 {
439 $this->aggregate = $aggregate;
440
441 return $this;
442 }
443
444 /**
445 * Checks whether the messages should be aggregated.
446 *
447 * @return bool
448 */
449 public function hasAggregate()
450 {
451 return $this->aggregate;
452 }
453
454 /**
455 * Sets the specified message reference ID.
456 *
457 * @param string|null $refId
458 *
459 * @return self
460 *
461 * @since 1.8.8
462 */
463 public function refId(?string $refId)
464 {
465 $this->refId = $refId;
466
467 return $this;
468 }
469
470 /**
471 * Checks whether a custom reference ID has been specified.
472 *
473 * @return bool
474 *
475 * @since 1.8.8
476 */
477 public function hasRefId()
478 {
479 return $this->refId !== null;
480 }
481
482 /**
483 * Returns the specified reference ID.
484 *
485 * @return string|null
486 *
487 * @since 1.8.8
488 */
489 public function getRefId()
490 {
491 return $this->refId;
492 }
493 }
494