-
Notifications
You must be signed in to change notification settings - Fork 642
/
Copy pathElementQuery.php
3751 lines (3278 loc) · 116 KB
/
ElementQuery.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/**
* @link https://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license https://craftcms.github.io/license/
*/
namespace craft\elements\db;
use Craft;
use craft\base\Element;
use craft\base\ElementInterface;
use craft\base\ExpirableElementInterface;
use craft\base\FieldInterface;
use craft\behaviors\CustomFieldBehavior;
use craft\behaviors\DraftBehavior;
use craft\behaviors\RevisionBehavior;
use craft\cache\ElementQueryTagDependency;
use craft\db\CoalesceColumnsExpression;
use craft\db\Connection;
use craft\db\FixedOrderExpression;
use craft\db\Query;
use craft\db\QueryAbortedException;
use craft\db\Table;
use craft\elements\ElementCollection;
use craft\elements\User;
use craft\errors\SiteNotFoundException;
use craft\events\CancelableEvent;
use craft\events\DefineValueEvent;
use craft\events\PopulateElementEvent;
use craft\events\PopulateElementsEvent;
use craft\helpers\App;
use craft\helpers\ArrayHelper;
use craft\helpers\Db;
use craft\helpers\ElementHelper;
use craft\helpers\Json;
use craft\helpers\StringHelper;
use craft\models\FieldLayout;
use craft\models\Site;
use Illuminate\Support\Collection;
use ReflectionClass;
use ReflectionException;
use ReflectionProperty;
use Twig\Markup;
use yii\base\ArrayableTrait;
use yii\base\Exception;
use yii\base\InvalidArgumentException;
use yii\base\InvalidConfigException;
use yii\base\InvalidValueException;
use yii\base\NotSupportedException;
use yii\db\Connection as YiiConnection;
use yii\db\Expression;
use yii\db\ExpressionInterface;
use yii\db\QueryBuilder;
use yii\db\Schema;
/**
* ElementQuery represents a SELECT SQL statement for elements in a way that is independent of DBMS.
*
* @template TKey of array-key
* @template TElement of ElementInterface
* @extends Query<TKey,TElement>
*
* @property-write string|string[]|Site $site The site(s) that resulting elements must be returned in
* @mixin CustomFieldBehavior
* @author Pixel & Tonic, Inc. <[email protected]>
* @since 3.0.0
*/
class ElementQuery extends Query implements ElementQueryInterface
{
use ArrayableTrait;
/**
* @event CancelableEvent An event that is triggered at the beginning of preparing an element query for the query builder.
*/
public const EVENT_BEFORE_PREPARE = 'beforePrepare';
/**
* @event CancelableEvent An event that is triggered at the end of preparing an element query for the query builder.
*/
public const EVENT_AFTER_PREPARE = 'afterPrepare';
/**
* @event DefineValueEvent An event that is triggered when defining the cache tags that should be associated with the query.
* @see getCacheTags()
* @since 4.1.0
*/
public const EVENT_DEFINE_CACHE_TAGS = 'defineCacheTags';
/**
* @event PopulateElementEvent The event that is triggered before an element is populated.
*
* If [[PopulateElementEvent::$element]] is set by an event handler, the replacement will be returned by [[createElement()]] instead.
*
* @since 4.5.0
*/
public const EVENT_BEFORE_POPULATE_ELEMENT = 'beforePopulateElement';
/**
* @event PopulateElementEvent The event that is triggered after an element is populated.
*
* If [[PopulateElementEvent::$element]] is replaced by an event handler, the replacement will be returned by [[createElement()]] instead.
*/
public const EVENT_AFTER_POPULATE_ELEMENT = 'afterPopulateElement';
/**
* @event PopulateElementEvent The event that is triggered after an element is populated.
*
* If [[PopulateElementEvent::$element]] is replaced by an event handler, the replacement will be returned by [[createElement()]] instead.
*/
public const EVENT_AFTER_POPULATE_ELEMENTS = 'afterPopulateElements';
// Base config attributes
// -------------------------------------------------------------------------
/**
* @var class-string<TElement> The name of the [[ElementInterface]] class.
*/
public string $elementType;
/**
* @var Query|null The query object created by [[prepare()]]
* @see prepare()
*/
public ?Query $query = null;
/**
* @var Query|null The subselect’s query object created by [[prepare()]]
* @see prepare()
*/
public ?Query $subQuery = null;
/**
* @var FieldInterface[]|null The fields that may be involved in this query.
*/
public ?array $customFields = null;
// Result formatting attributes
// -------------------------------------------------------------------------
/**
* @var bool Whether the results should be queried in reverse.
* @used-by inReverse()
*/
public bool $inReverse = false;
/**
* @var bool Whether to return each element as an array. If false (default), an object
* of [[elementType]] will be created to represent each element.
* @used-by asArray()
*/
public bool $asArray = false;
/**
* @var bool Whether to replace canonical elements with provisional drafts,
* when they exist for the current user.
* @used-by withProvisionalDrafts()
* @since 5.6.0
*/
public bool $withProvisionalDrafts = false;
/**
* @var bool Whether to ignore placeholder elements when populating the results.
* @used-by ignorePlaceholders()
* @since 3.2.9
*/
public bool $ignorePlaceholders = false;
// Drafts and revisions
// -------------------------------------------------------------------------
/**
* @var bool|null Whether draft elements should be returned.
* @since 3.2.0
*/
public ?bool $drafts = false;
/**
* @var bool|null Whether provisional drafts should be returned.
* @since 3.7.0
*/
public ?bool $provisionalDrafts = false;
/**
* @var int|null The ID of the draft to return (from the `drafts` table)
* @since 3.2.0
*/
public ?int $draftId = null;
/**
* @var mixed The source element ID that drafts should be returned for.
*
* This can be set to one of the following:
*
* - A source element ID – matches drafts of that element
* - A source element
* - An array of source elements or element IDs
* - `'*'` – matches drafts of any source element
* - `false` – matches unpublished drafts that have no source element
*
* @since 3.2.0
*/
public mixed $draftOf = null;
/**
* @var int|null The drafts’ creator ID
* @since 3.2.0
*/
public ?int $draftCreator = null;
/**
* @var bool Whether only unpublished drafts which have been saved after initial creation should be included in the results.
* @since 3.6.6
*/
public bool $savedDraftsOnly = false;
/**
* @var bool|null Whether revision elements should be returned.
* @since 3.2.0
*/
public ?bool $revisions = false;
/**
* @var int|null The ID of the revision to return (from the `revisions` table)
* @since 3.2.0
*/
public ?int $revisionId = null;
/**
* @var int|null The source element ID that revisions should be returned for
* @since 3.2.0
*/
public ?int $revisionOf = null;
/**
* @var int|null The revisions’ creator ID
* @since 3.2.0
*/
public ?int $revisionCreator = null;
// General parameters
// -------------------------------------------------------------------------
/**
* @var mixed The element ID(s). Prefix IDs with `'not '` to exclude them.
* @used-by id()
*/
public mixed $id = null;
/**
* @var mixed The element UID(s). Prefix UIDs with `'not '` to exclude them.
* @used-by uid()
*/
public mixed $uid = null;
/**
* @var mixed The element ID(s) in the `elements_sites` table. Prefix IDs with `'not '` to exclude them.
* @used-by siteSettingsId()
* @since 3.7.0
*/
public mixed $siteSettingsId = null;
/**
* @var bool Whether results should be returned in the order specified by [[id]].
* @used-by fixedOrder()
*/
public bool $fixedOrder = false;
/**
* @var string|string[]|null The status(es) that the resulting elements must have.
* @used-by status()
*/
public array|string|null $status = [
Element::STATUS_ENABLED,
];
/**
* @var bool Whether to return only archived elements.
* @used-by archived()
*/
public bool $archived = false;
/**
* @var bool|null Whether to return trashed (soft-deleted) elements.
* If this is set to `null`, then both trashed and non-trashed elements will be returned.
* @used-by trashed()
* @since 3.1.0
*/
public ?bool $trashed = false;
/**
* @var mixed When the resulting elements must have been created.
* @used-by dateCreated()
*/
public mixed $dateCreated = null;
/**
* @var mixed When the resulting elements must have been last updated.
* @used-by dateUpdated()
*/
public mixed $dateUpdated = null;
/**
* @var mixed The site ID(s) that the elements should be returned in, or `'*'` if elements
* should be returned in all supported sites.
* @used-by site()
* @used-by siteId()
*/
public mixed $siteId = null;
/**
* @var bool Whether only elements with unique IDs should be returned by the query.
* @used-by unique()
* @since 3.2.0
*/
public bool $unique = false;
/**
* @var array|null Determines which site should be selected when querying multi-site elements.
* @used-by preferSites()
* @since 3.2.0
*/
public ?array $preferSites = null;
/**
* @var bool Whether the elements must be “leaves” in the structure.
* @used-by leaves()
*/
public bool $leaves = false;
/**
* @var mixed The element relation criteria.
*
* See [Relations](https://craftcms.com/docs/5.x/system/relations.html) for supported syntax options.
*
* @used-by relatedTo()
*/
public mixed $relatedTo = null;
/**
* @var mixed The element relation criteria.
*
* See [Relations](https://craftcms.com/docs/5.x/system/relations.html) for supported syntax options.
*
* @used-by notRelatedTo()
* @since 5.4.0
*/
public mixed $notRelatedTo = null;
/**
* @var mixed The title that resulting elements must have.
* @used-by title()
*/
public mixed $title = null;
/**
* @var mixed The slug that resulting elements must have.
* @used-by slug()
*/
public mixed $slug = null;
/**
* @var mixed The URI that the resulting element must have.
* @used-by uri()
*/
public mixed $uri = null;
/**
* @var mixed The search term to filter the resulting elements by.
*
* See [Searching](https://craftcms.com/docs/5.x/system/searching.html) for supported syntax options.
*
* @used-by ElementQuery::search()
*/
public mixed $search = null;
/**
* @var string|null The bulk element operation key that the resulting elements were involved in.
*
* @used-by ElementQuery::inBulkOp()
* @since 5.0.0
*/
public ?string $inBulkOp = null;
/**
* @var mixed The reference code(s) used to identify the element(s).
*
* This property is set when accessing elements via their reference tags, e.g. `{entry:section/slug}`.
*
* @used-by ElementQuery::ref()
*/
public mixed $ref = null;
// Eager-loading
// -------------------------------------------------------------------------
/**
* @var string|array|null The eager-loading declaration.
*
* See [Eager-Loading Elements](https://craftcms.com/docs/5.x/development/eager-loading.html) for supported syntax options.
*
* @used-by with()
* @used-by andWith()
*/
public array|string|null $with = null;
/**
* @var ElementInterface|null The source element that this query is fetching relations for.
* @since 5.0.0
*/
public ?ElementInterface $eagerLoadSourceElement = null;
/**
* @var string|null The handle that could be used to eager-load the query's target elmeents.
* @since 5.0.0
*/
public ?string $eagerLoadHandle = null;
/**
* @var string|null The eager-loading alias that should be used.
* @since 5.0.0
*/
public ?string $eagerLoadAlias = null;
/**
* @var bool Whether the query should be used to eager-load results for the [[$eagerSourceElement|source element]]
* and any other elements in its collection.
* @used-by eagerly()
* @since 5.0.0
*/
public bool $eagerly = false;
/**
* @var bool Whether custom fields should be factored into the query.
* @used-by withCustomFields()
* @since 5.2.0
*/
public bool $withCustomFields = true;
// Structure parameters
// -------------------------------------------------------------------------
/**
* @var bool|null Whether element structure data should automatically be left-joined into the query.
* @used-by withStructure()
*/
public ?bool $withStructure = null;
/**
* @var mixed The structure ID that should be used to join in the structureelements table.
* @used-by structureId()
*/
public mixed $structureId = null;
/**
* @var mixed The element’s level within the structure
* @used-by level()
*/
public mixed $level = null;
/**
* @var bool|null Whether the resulting elements must have descendants.
* @used-by hasDescendants()
* @since 3.0.4
*/
public ?bool $hasDescendants = null;
/**
* @var int|ElementInterface|null The element (or its ID) that results must be an ancestor of.
* @used-by ancestorOf()
*/
public ElementInterface|int|null $ancestorOf = null;
/**
* @var int|null The maximum number of levels that results may be separated from [[ancestorOf]].
* @used-by ancestorDist()
*/
public ?int $ancestorDist = null;
/**
* @var int|ElementInterface|null The element (or its ID) that results must be a descendant of.
* @used-by descendantOf()
*/
public ElementInterface|int|null $descendantOf = null;
/**
* @var int|null The maximum number of levels that results may be separated from [[descendantOf]].
* @used-by descendantDist()
*/
public ?int $descendantDist = null;
/**
* @var int|ElementInterface|null The element (or its ID) that the results must be a sibling of.
* @used-by siblingOf()
*/
public ElementInterface|int|null $siblingOf = null;
/**
* @var int|ElementInterface|null The element (or its ID) that the result must be the previous sibling of.
* @used-by prevSiblingOf()
*/
public ElementInterface|int|null $prevSiblingOf = null;
/**
* @var int|ElementInterface|null The element (or its ID) that the result must be the next sibling of.
* @used-by nextSiblingOf()
*/
public ElementInterface|int|null $nextSiblingOf = null;
/**
* @var int|ElementInterface|null The element (or its ID) that the results must be positioned before.
* @used-by positionedBefore()
*/
public ElementInterface|int|null $positionedBefore = null;
/**
* @var int|ElementInterface|null The element (or its ID) that the results must be positioned after.
* @used-by positionedAfter()
*/
public ElementInterface|int|null $positionedAfter = null;
/**
* @var array The default [[orderBy]] value to use if [[orderBy]] is empty but not null.
*/
protected array $defaultOrderBy = [
'elements.dateCreated' => SORT_DESC,
'elements.id' => SORT_DESC,
];
// For internal use
// -------------------------------------------------------------------------
/**
* @var mixed The placeholder condition for this query.
* @see _placeholderCondition()
*/
private mixed $_placeholderCondition = null;
/**
* @var mixed The [[siteId]] param used at the time the placeholder condition was generated.
* @see _placeholderCondition()
*/
private mixed $_placeholderSiteIds = null;
/**
* @var ElementInterface[]|null The cached element query result
* @see setCachedResult()
*/
private ?array $_result = null;
/**
* @var array|null The criteria params that were set when the cached element query result was set
* @see setCachedResult()
*/
private ?array $_resultCriteria = null;
/**
* @var array<string,int>|null
* @see _applySearchParam()
* @see _applyOrderByParams()
* @see populate()
*/
private ?array $_searchResults = null;
/**
* @var string[]|null
* @see getCacheTags()
*/
private array|null $_cacheTags = null;
/**
* @var array<string,string|string[]> Column alias => name mapping
* @see prepare()
* @see joinElementTable()
* @see _applyOrderByParams()
* @see _applySelectParam()
*/
private array $_columnMap = [];
/**
* @var bool Whether an element table has been joined for the query
* @see prepare()
* @see joinElementTable()
*/
private bool $_joinedElementTable = false;
/**
* @var array<string,string|string[]> Column alias => cast type
* @see prepare()
* @see _applyOrderByParams()
*/
private array $_columnsToCast = [];
/**
* Constructor
*
* @param class-string<TElement> $elementType The element type class associated with this query
* @param array $config Configurations to be applied to the newly created query object
*/
public function __construct(string $elementType, array $config = [])
{
$this->elementType = $elementType;
// Use ** as a placeholder for "all the default columns"
$config['select'] = $config['select'] ?? ['**' => '**'];
// Set a placeholder for the default `orderBy` param
if (!isset($this->orderBy)) {
$this->orderBy(new OrderByPlaceholderExpression());
}
parent::__construct($config);
}
/**
* @inheritdoc
*/
public function __set($name, $value)
{
switch ($name) {
case 'site':
$this->site($value);
break;
default:
parent::__set($name, $value);
}
}
/**
* @inheritdoc
*/
public function __toString()
{
return self::class;
}
/**
* @inheritdoc
*/
public function offsetExists(mixed $offset): bool
{
// Cached?
if (is_numeric($offset)) {
$cachedResult = $this->getCachedResult();
if ($cachedResult !== null) {
return $offset < count($cachedResult);
}
}
return parent::offsetExists($offset);
}
/**
* @inheritdoc
*/
public function behaviors(): array
{
$behaviors = parent::behaviors();
$behaviors['customFields'] = [
'class' => CustomFieldBehavior::class,
'hasMethods' => true,
];
return $behaviors;
}
// Element criteria parameter setters
// -------------------------------------------------------------------------
/**
* @inheritdoc
* @uses $inReverse
*/
public function inReverse(bool $value = true): static
{
$this->inReverse = $value;
return $this;
}
/**
* @inheritdoc
* @uses $asArray
*/
public function asArray(bool $value = true): static
{
$this->asArray = $value;
return $this;
}
/**
* @inheritdoc
* @uses $withProvisionalDrafts
*/
public function withProvisionalDrafts(bool $value = true): static
{
$this->withProvisionalDrafts = $value;
return $this;
}
/**
* @inheritdoc
* @uses $asArray
*/
public function ignorePlaceholders(bool $value = true): static
{
$this->ignorePlaceholders = $value;
return $this;
}
/**
* @inheritdoc
* @uses $drafts
*/
public function drafts(?bool $value = true): static
{
$this->drafts = $value;
return $this;
}
/**
* @inheritdoc
* @uses $draftId
* @uses $drafts
*/
public function draftId(?int $value = null): static
{
$this->draftId = $value;
if ($value !== null && $this->drafts === false) {
$this->drafts = true;
}
return $this;
}
/**
* @inheritdoc
* @uses $draftOf
* @uses $drafts
*/
public function draftOf($value): static
{
$valid = false;
if ($value instanceof ElementInterface) {
$this->draftOf = $value->getCanonicalId();
$valid = true;
} elseif (
is_numeric($value) ||
(is_array($value) && ArrayHelper::isNumeric($value)) ||
$value === '*' ||
$value === false ||
$value === null
) {
$this->draftOf = $value;
$valid = true;
} elseif (is_array($value) && !empty($value)) {
$c = Collection::make($value);
if ($c->every(fn($v) => $v instanceof ElementInterface || is_numeric($v))) {
$this->draftOf = $c->map(fn($v) => $v instanceof ElementInterface ? $v->id : $v)->all();
$valid = true;
}
}
if (!$valid) {
throw new InvalidArgumentException('Invalid draftOf value');
}
if ($value !== null && $this->drafts === false) {
$this->drafts = true;
}
return $this;
}
/**
* @inheritdoc
* @uses $draftCreator
* @uses $drafts
*/
public function draftCreator($value): static
{
if ($value instanceof User) {
$this->draftCreator = $value->id;
} elseif (is_numeric($value) || $value === null) {
$this->draftCreator = $value;
} else {
throw new InvalidArgumentException('Invalid draftCreator value');
}
if ($value !== null && $this->drafts === false) {
$this->drafts = true;
}
return $this;
}
/**
* @inheritdoc
* @uses $provisionalDrafts
* @uses $drafts
*/
public function provisionalDrafts(?bool $value = true): static
{
$this->provisionalDrafts = $value;
if ($value === true && $this->drafts === false) {
$this->drafts = true;
}
return $this;
}
/**
* @inheritdoc
* @uses $savedDraftsOnly
*/
public function savedDraftsOnly(bool $value = true): static
{
$this->savedDraftsOnly = $value;
return $this;
}
/**
* @inheritdoc
* @uses $revisions
*/
public function revisions(?bool $value = true): static
{
$this->revisions = $value;
return $this;
}
/**
* @inheritdoc
* @uses $revisionId
* @uses $revisions
*/
public function revisionId(?int $value = null): static
{
$this->revisionId = $value;
if ($value !== null && $this->revisions === false) {
$this->revisions = true;
}
return $this;
}
/**
* @inheritdoc
* @uses $revisionOf
* @uses $revisions
*/
public function revisionOf($value): static
{
if ($value instanceof ElementInterface) {
$this->revisionOf = $value->getCanonicalId();
} elseif (is_numeric($value) || $value === null) {
$this->revisionOf = $value;
} else {
throw new InvalidArgumentException('Invalid revisionOf value');
}
if ($value !== null && $this->revisions === false) {
$this->revisions = true;
}
return $this;
}
/**
* @inheritdoc
* @uses $revisionCreator
* @uses $revisions
*/
public function revisionCreator($value): static
{
if ($value instanceof User) {
$this->revisionCreator = $value->id;
} elseif (is_numeric($value) || $value === null) {
$this->revisionCreator = $value;
} else {
throw new InvalidArgumentException('Invalid revisionCreator value');
}
if ($value !== null && $this->revisions === false) {
$this->revisions = true;
}
return $this;
}
/**
* @inheritdoc
* @uses $id
*/
public function id($value): static
{
$this->id = $value;
return $this;
}
/**
* @inheritdoc
* @uses $uid
*/
public function uid($value): static
{
$this->uid = $value;
return $this;
}
/**
* @inheritdoc
* @uses $siteSettingsId
*/
public function siteSettingsId($value): static
{
$this->siteSettingsId = $value;
return $this;
}
/**
* @inheritdoc
* @uses $fixedOrder
*/
public function fixedOrder(bool $value = true): static
{
$this->fixedOrder = $value;
return $this;
}
/**
* @inheritdoc
* @uses $orderBy
*/
public function orderBy($columns): static
{
parent::orderBy($columns);
// If $columns normalizes to an empty array, just set it to null
if ($this->orderBy === []) {
$this->orderBy = null;
}
return $this;
}
/**
* @inheritdoc
* @uses $orderBy
*/
public function addOrderBy($columns): static
{
// If orderBy is an empty, non-null value (leaving it up to the element query class to decide),
// then treat this is an orderBy() call.
if (isset($this->orderBy) && empty($this->orderBy)) {
$this->orderBy = null;
}
parent::addOrderBy($columns);
// If $this->>orderBy is empty, just set it to null
if ($this->orderBy === []) {
$this->orderBy = null;
}
return $this;
}
/**
* @inheritdoc
* @uses $status
*/
public function status(array|string|null $value): static
{
$this->status = $value;
return $this;
}
/**
* @inheritdoc
* @uses $archived
*/
public function archived(bool $value = true): static
{
$this->archived = $value;
return $this;
}
/**
* @inheritdoc
* @uses $trashed
*/
public function trashed(?bool $value = true): static
{
$this->trashed = $value;
return $this;
}
/**
* @inheritdoc
* @uses $dateCreated
*/
public function dateCreated(mixed $value): static
{
$this->dateCreated = $value;
return $this;
}
/**
* @inheritdoc
* @uses $dateUpdated
*/
public function dateUpdated(mixed $value): static
{