-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathAbstractGridView.class.php
More file actions
968 lines (833 loc) · 25.3 KB
/
AbstractGridView.class.php
File metadata and controls
968 lines (833 loc) · 25.3 KB
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
<?php
namespace wcf\system\gridView;
use wcf\action\GridViewFilterAction;
use wcf\data\DatabaseObject;
use wcf\data\DatabaseObjectList;
use wcf\event\IPsr14Event;
use wcf\system\event\EventHandler;
use wcf\system\view\filter\exception\InvalidFilterValue;
use wcf\system\interaction\bulk\IBulkInteractionProvider;
use wcf\system\interaction\IInteraction;
use wcf\system\interaction\IInteractionProvider;
use wcf\system\interaction\InteractionContextMenuComponent;
use wcf\system\request\LinkHandler;
use wcf\system\view\filter\IViewFilter;
use wcf\system\WCF;
use wcf\util\StringUtil;
/**
* Abstract implementation of a grid view.
*
* @author Marcel Werk
* @copyright 2001-2024 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 6.2
*
* @template TDatabaseObject of DatabaseObject
* @template TDatabaseObjectList of DatabaseObjectList
*/
abstract class AbstractGridView
{
/**
* @var GridViewColumn[]
*/
private array $columns = [];
/**
* @var IInteraction[]
*/
private array $quickInteractions = [];
/**
* @var TDatabaseObject[]
*/
protected array $objects;
protected int $objectCount;
/**
* @var TDatabaseObjectList
*/
protected DatabaseObjectList $objectList;
private IGridViewRowLink $rowLink;
private int $rowsPerPage = 20;
private string $baseUrl = '';
private string $defaultSortField = '';
private string $defaultSortOrder = 'ASC';
private string $sortField = '';
private string $sortOrder = 'ASC';
private int $pageNo = 1;
private string|int|null $objectIDFilter = null;
private ?IInteractionProvider $interactionProvider = null;
private ?IBulkInteractionProvider $bulkInteractionProvider = null;
private InteractionContextMenuComponent $interactionContextMenuComponent;
/**
* @var array<string, string|int>
*/
private array $activeFilters = [];
/**
* @var array<string, IViewFilter>
*/
private array $availableFilters = [];
/**
* @var array<string, array{
* filter: IViewFilter,
* target: ?string,
* insertBefore: bool,
* }>
*/
private array $extraFilters = [];
/**
* Adds a new column to the grid view.
*/
public function addColumn(GridViewColumn $column): void
{
$this->columns[] = $column;
}
/**
* Adds a new column to the grid view at the position before the specific id.
*/
public function addColumnBefore(GridViewColumn $column, string $beforeID): void
{
$position = -1;
foreach ($this->getColumns() as $key => $existingColumn) {
if ($existingColumn->getID() === $beforeID) {
$position = $key;
break;
}
}
if ($position === -1) {
throw new \InvalidArgumentException("Invalid column id '{$beforeID}' given.");
}
array_splice($this->columns, $position, 0, [
$column,
]);
}
/**
* Adds a new column to the grid view at the position after the specific id.
*/
public function addColumnAfter(GridViewColumn $column, string $afterID): void
{
$position = -1;
foreach ($this->getColumns() as $key => $existingColumn) {
if ($existingColumn->getID() === $afterID) {
$position = $key;
break;
}
}
if ($position === -1) {
throw new \InvalidArgumentException("Invalid column id '{$afterID}' given.");
}
array_splice($this->columns, $position + 1, 0, [
$column,
]);
}
/**
* Adds multiple new columns to the grid view.
*
* @param GridViewColumn[] $columns
*/
public function addColumns(array $columns): void
{
foreach ($columns as $column) {
$this->addColumn($column);
}
}
/**
* Returns all columns of the grid view.
*
* @return GridViewColumn[]
*/
public function getColumns(): array
{
return $this->columns;
}
/**
* Returns all visible (non-hidden) columns of the grid view.
*
* @return GridViewColumn[]
*/
public function getVisibleColumns(): array
{
return \array_filter($this->getColumns(), fn($column) => !$column->isHidden());
}
/**
* Returns the column with the given id or null if no such column exists.
*/
public function getColumn(string $id): ?GridViewColumn
{
foreach ($this->getColumns() as $column) {
if ($column->getID() === $id) {
return $column;
}
}
return null;
}
/**
* Returns all columns that are sortable.
*
* @return GridViewColumn[]
*/
public function getSortableColumns(): array
{
return \array_filter($this->getColumns(), fn($column) => $column->isSortable());
}
/**
* Sets the interaction provider that is used to render the interaction context menu.
*/
public function setInteractionProvider(IInteractionProvider $provider): void
{
$this->interactionProvider = $provider;
}
/**
* Returns the interaction provider of the grid view.
*/
public function getInteractionProvider(): ?IInteractionProvider
{
return $this->interactionProvider;
}
/**
* Sets the bulk interaction provider for this grid view.
*/
public function setBulkInteractionProvider(IBulkInteractionProvider $provider): void
{
$this->bulkInteractionProvider = $provider;
}
/**
* Returns the bulk interaction provider of the grid view.
*/
public function getBulkInteractionProvider(): ?IBulkInteractionProvider
{
return $this->bulkInteractionProvider;
}
public function getBulkInteractionProviderClassName(): string
{
if (!$this->hasBulkInteractions()) {
return '';
}
return \get_class($this->getBulkInteractionProvider());
}
/**
* Returns true, if this grid view has interactions.
*/
public function hasInteractions(): bool
{
return $this->interactionProvider !== null || $this->quickInteractions !== [];
}
/**
* Adds a quick interaction.
*/
public function addQuickInteraction(IInteraction $interaction): void
{
$this->quickInteractions[] = $interaction;
}
/**
* Returns true if this grid view has bulk interactions.
*/
public function hasBulkInteractions(): bool
{
return $this->getBulkInteractionProvider() !== null
&& $this->getBulkInteractionProvider()->getInteractions() !== [];
}
/**
* Returns the quick interactions.
*
* @return IInteraction[]
*/
public function getQuickInteractions(): array
{
return $this->quickInteractions;
}
/**
* Renders the grid view and returns the HTML code.
*/
public function render(): string
{
$this->init();
return WCF::getTPL()->render('wcf', 'shared_gridView', ['view' => $this]);
}
/**
* Renders the rows and returns the HTML code.
*/
public function renderRows(): string
{
$this->init();
$this->prepareRenderers();
return WCF::getTPL()->render('wcf', 'shared_gridViewRows', ['view' => $this]);
}
/**
* Renders the given grid view column.
*
* @param TDatabaseObject $row
*/
public function renderColumn(GridViewColumn $column, DatabaseObject $row): string
{
$value = $this->getData($row, $column->getID());
if ($value !== null && $column->encodeValue()) {
$value = StringUtil::encodeHTML($value);
}
$value = $column->render($value, $row);
if (
isset($this->rowLink)
&& $column->applyRowLink()
&& $this->rowLink->isAvailable($row)
) {
$value = $this->rowLink->render($value, $row, $column->isTitleColumn());
}
return $value;
}
/**
* Returns the view of the interaction context menu.
*/
public function getInteractionContextMenuComponent(): InteractionContextMenuComponent
{
if ($this->interactionProvider === null) {
throw new \BadMethodCallException("Missing interaction provider.");
}
if (!isset($this->interactionContextMenuComponent)) {
$this->interactionContextMenuComponent = new InteractionContextMenuComponent($this->interactionProvider);
}
return $this->interactionContextMenuComponent;
}
/**
* Renders the initialization code for the interactions of the grid view.
*/
public function renderInteractionInitialization(): string
{
$code = '';
if ($this->interactionProvider !== null) {
$code = $this->getInteractionContextMenuComponent()->renderInitialization($this->getID() . '_table');
}
if ($this->quickInteractions !== []) {
$code .= "\n";
$code .= \implode("\n", \array_map(
fn($interaction) => $interaction->renderInitialization($this->getID() . '_table'),
$this->getQuickInteractions()
));
}
if (isset($this->rowLink)) {
$code .= "\n";
$code .= $this->rowLink->renderInitialization($this->getID() . '_table');
}
return $code;
}
/**
* Renders the initialization code for the bulk interactions of the grid view.
*/
public function renderBulkInteractionInitialization(): string
{
if (!$this->hasBulkInteractions()) {
return '';
}
return \implode("\n", \array_map(
fn($interaction) => $interaction->renderInitialization($this->getID() . '_table'),
$this->getBulkInteractionProvider()->getInteractions()
));
}
/**
* Renders the interactions for the given row.
*
* @param TDatabaseObject $row
*/
public function renderInteractionContextMenuButton(DatabaseObject $row): string
{
if ($this->interactionProvider === null) {
return '';
}
return $this->getInteractionContextMenuComponent()->renderButton($row);
}
/**
* Renders the interactions for the given row.
*
* @param TDatabaseObject $row
*/
public function renderQuickInteractions(DatabaseObject $row): string
{
$availableInteractions = \array_filter(
$this->getQuickInteractions(),
static fn($interaction) => $interaction->isAvailable($row)
);
return \implode("\n", \array_map(
static fn($interaction) => $interaction->render($row),
$availableInteractions
));
}
/**
* Returns the row data for the given identifier.
*
* @param TDatabaseObject $row
*/
protected function getData(DatabaseObject $row, string $identifier): mixed
{
return $row->__get($identifier);
}
/**
* Counts the pages of the grid view.
*/
public function countPages(): int
{
return (int)\ceil($this->countRows() / $this->getRowsPerPage());
}
/**
* Returns the class name of this grid view.
*/
public function getClassName(): string
{
return \get_class($this);
}
/**
* Returns true, if this grid view is accessible for the active user.
*/
public function isAccessible(): bool
{
return true;
}
/**
* Returns the id of this grid view.
*/
public function getID(): string
{
$id = \str_replace('\\', '_', static::class);
if ($this->getParameters() !== []) {
$parameters = $this->getParameters();
\array_multisort($parameters);
$id .= '_' . \sha1(\serialize($parameters));
}
return $id;
}
/**
* Sets the base url of the grid view.
*/
public function setBaseUrl(string $url): void
{
$this->baseUrl = $url;
}
/**
* Returns the base url of the grid view.
*/
public function getBaseUrl(): string
{
return $this->baseUrl;
}
/**
* Sets the default sort field of the grid view.
*/
public function setDefaultSortField(string $sortField): void
{
$this->defaultSortField = $sortField;
$this->setSortField($sortField);
}
/**
* Sets the default sort order of the grid view.
*/
public function setDefaultSortOrder(string $sortOrder): void
{
if ($sortOrder !== 'ASC' && $sortOrder !== 'DESC') {
throw new \InvalidArgumentException("Invalid value '{$sortOrder}' as default sort order given.");
}
$this->defaultSortOrder = $sortOrder;
$this->setSortOrder($sortOrder);
}
/**
* Returns the default sort field of the grid view.
*/
public function getDefaultSortField(): string
{
return $this->defaultSortField;
}
/**
* Returns the sort order of the grid view.
*/
public function getDefaultSortOrder(): string
{
return $this->defaultSortOrder;
}
/**
* Sets the sort field of the grid view.
*/
public function setSortField(string $sortField): void
{
$this->sortField = $sortField;
}
/**
* Sets the sort order of the grid view.
*/
public function setSortOrder(string $sortOrder): void
{
if ($sortOrder !== 'ASC' && $sortOrder !== 'DESC') {
throw new \InvalidArgumentException("Invalid value '{$sortOrder}' as sort order given.");
}
$this->sortOrder = $sortOrder;
}
/**
* Returns the sort field of the grid view.
*/
public function getSortField(): string
{
return $this->sortField;
}
/**
* Returns the sort order of the grid view.
*/
public function getSortOrder(): string
{
return $this->sortOrder;
}
/**
* Returns the page number.
*/
public function getPageNo(): int
{
return $this->pageNo;
}
/**
* Sets the page number.
*/
public function setPageNo(int $pageNo): void
{
$this->pageNo = $pageNo;
}
/**
* Returns the number of rows per page.
*/
public function getRowsPerPage(): int
{
return $this->rowsPerPage;
}
/**
* Sets the number of rows per page.
*/
public function setRowsPerPage(int $rowsPerPage): void
{
$this->rowsPerPage = $rowsPerPage;
}
/**
* Returns true, if the grid view is filterable.
*/
public function isFilterable(): bool
{
return $this->getAvailableFilters() !== [];
}
/**
* Returns the endpoint for the filter action.
*/
public function getFilterActionEndpoint(): string
{
return LinkHandler::getInstance()->getControllerLink(
GridViewFilterAction::class,
['gridView' => \get_class($this), 'gridViewParameters' => $this->getParameters()]
);
}
/**
* Sets the active filter values.
*
* @param array<string, string|int> $filters
*/
public function setActiveFilters(array $filters): void
{
$this->activeFilters = $filters;
}
/**
* Returns the active filter values.
*
* @return array<string, string|int>
*/
public function getActiveFilters(): array
{
return $this->activeFilters;
}
/**
* Returns the label for the given filter.
*/
public function getFilterLabel(string $id): string
{
if (!isset($this->availableFilters[$id])) {
throw new \LogicException("Unknown filter '" . $id . "'.");
}
if (!isset($this->activeFilters[$id])) {
throw new \LogicException("No value for filter '" . $id . "' found.");
}
$value = $this->availableFilters[$id]->renderValue($this->activeFilters[$id]);
return $this->availableFilters[$id]->getLabel() . ($value !== '' ? ': ' . $value : '');
}
/**
* Gets the additional parameters of the grid view.
*
* @return mixed[]
*/
public function getParameters(): array
{
return [];
}
/**
* Adds the given row link to the grid view.
*/
public function addRowLink(IGridViewRowLink $rowLink): void
{
$this->rowLink = $rowLink;
}
/**
* Returns the id for the given row.
*
* @param TDatabaseObject $row
*/
public function getObjectID(DatabaseObject $row): string|int
{
return $row->getObjectID();
}
/**
* Filters the grid view by the given object id.
*/
public function setObjectIDFilter(string|int|null $objectID): void
{
$this->objectIDFilter = $objectID;
}
/**
* Returns the object id by which the grid view is filtered.
*/
public function getObjectIDFilter(): string|int|null
{
return $this->objectIDFilter;
}
/**
* Fires the initialized event.
*/
protected function fireInitializedEvent(): void
{
$event = $this->getInitializedEvent();
if ($event === null) {
return;
}
EventHandler::getInstance()->fire($event);
}
private function buildAvailableFilters(): void
{
$filters = [];
foreach ($this->getColumns() as $column) {
if ($column->getFilter() !== null) {
$filters[] = $column->getFilter();
}
}
foreach ($this->extraFilters as $filterData) {
$filter = $filterData['filter'];
if ($filterData['target'] === null) {
if ($filterData['insertBefore']) {
\array_unshift($filters, $filter);
} else {
$filters[] = $filter;
}
} else {
$index = \array_find_key(
$filters,
static fn($filterObj) => $filterObj->getId() === $filterData['target']
);
if ($index === null) {
throw new \RuntimeException("Cannot find the target '{$filterData['target']}' for filter '{$filter->getId()}'.");
}
if (!$filterData['insertBefore']) {
$index++;
}
\array_splice($filters, $index, 0, [$filter]);
}
}
foreach ($filters as $filter) {
$this->availableFilters[$filter->getId()] = $filter;
}
}
/**
* Validates the configuration of this grid view.
*/
protected function validate(): void
{
$this->buildAvailableFilters();
if ($this->getDefaultSortField() === '') {
throw new \InvalidArgumentException("Undefined default sort field.");
}
if ($this->getSortField()) {
if (!\in_array($this->getSortField(), \array_map(fn($column) => $column->getID(), $this->getSortableColumns()))) {
if (\ENABLE_DEBUG_MODE) {
throw new \InvalidArgumentException("Invalid value '{$this->getSortField()}' as sort field given.");
} {
$this->setSortField('');
}
}
}
$titleColumn = null;
foreach ($this->getColumns() as $column) {
if ($column->isTitleColumn()) {
if ($titleColumn !== null) {
throw new \InvalidArgumentException("More than one title column defined in grid view with id '{$this->getID()}'.");
}
$titleColumn = $column;
}
}
if ($titleColumn === null) {
throw new \InvalidArgumentException("Missing title column in grid view with id '{$this->getID()}'.");
}
}
/**
* Returns the initialized event or null if there is no such event for this grid view.
*/
protected function getInitializedEvent(): ?IPsr14Event
{
return null;
}
/**
* Prepares the column renderers.
*/
protected function prepareRenderers(): void
{
foreach ($this->getVisibleColumns() as $column) {
foreach ($column->getRenderers() as $renderer) {
foreach ($this->getRows() as $row) {
$renderer->prepare($this->getData($row, $column->getID()), $row);
}
}
}
}
/**
* Returns the rows for the active page.
*
* @return TDatabaseObject[]
*/
public function getRows(): array
{
if (!isset($this->objects)) {
$this->getObjectList()->readObjects();
$this->objects = $this->getObjectList()->getObjects();
}
return $this->objects;
}
/**
* Returns the total number of rows.
*/
public function countRows(): int
{
if (!isset($this->objectCount)) {
$this->objectCount = $this->getObjectList()->countObjects();
}
return $this->objectCount;
}
/**
* Returns the database object list.
*
* @return TDatabaseObjectList
*/
public function getObjectList(): DatabaseObjectList
{
$this->init();
return $this->objectList;
}
/**
* Returns true if the rows are currently sorted by the provided column.
*/
public function isSortedBy(GridViewColumn $column): bool
{
return $this->getSortField() === $column->getID();
}
/**
* Initializes the database object list.
*/
protected function initObjectList(): void
{
$this->objectList = $this->createObjectList();
$this->fireInitializedEvent();
$this->validate();
if ($this->getObjectIDFilter() !== null) {
$this->objectList->getConditionBuilder()->add(
$this->objectList->getDatabaseTableAlias() . '.' . $this->objectList->getDatabaseTableIndexName() . ' = ?',
[$this->getObjectIDFilter()]
);
}
$this->applyFilters();
if ($this->getPageNo() > 1 && $this->getPageNo() > $this->countPages()) {
$this->setPageNo($this->countPages() ?: 1);
}
$this->objectList->sqlLimit = $this->getRowsPerPage();
$this->objectList->sqlOffset = ($this->getPageNo() - 1) * $this->getRowsPerPage();
if ($this->getSortField()) {
$column = $this->getColumn($this->getSortField());
if ($column && $column->getSortByDatabaseColumn()) {
$this->objectList->sqlOrderBy = $column->getSortByDatabaseColumn() . ' ' . $this->getSortOrder();
} else {
$this->objectList->sqlOrderBy = $this->objectList->getDatabaseTableAlias() .
'.' . $this->getSortField() . ' ' . $this->getSortOrder();
}
$this->objectList->sqlOrderBy .= ',' . $this->objectList->getDatabaseTableAlias() .
'.' . $this->objectList->getDatabaseTableIndexName() . ' ' . $this->getSortOrder();
}
}
/**
* Applies the active filters.
*/
protected function applyFilters(): void
{
$this->activeFilters = \array_filter($this->activeFilters, function ($value, $key) {
if (!isset($this->availableFilters[$key])) {
if (\ENABLE_DEBUG_MODE) {
throw new \LogicException("Filter applied for unknown column '{$key}'.");
} else {
return false;
}
}
try {
$this->availableFilters[$key]->applyFilter($this->getObjectList(), $value);
} catch (InvalidFilterValue $e) {
if (\ENABLE_DEBUG_MODE) {
throw $e;
} else {
return false;
}
}
return true;
}, \ARRAY_FILTER_USE_BOTH);
}
public function addAvailableFilter(IViewFilter $filter): void
{
$this->extraFilters[$filter->getId()] = [
'filter' => $filter,
'target' => null,
'insertBefore' => false,
];
}
public function addAvailableFilterBefore(IViewFilter $filter, ?string $targetFilterID = null): void
{
$this->extraFilters[$filter->getId()] = [
'filter' => $filter,
'target' => $targetFilterID,
'insertBefore' => true,
];
}
public function addAvailableFilterAfter(IViewFilter $filter, ?string $targetFilterID = null): void
{
$this->extraFilters[$filter->getId()] = [
'filter' => $filter,
'target' => $targetFilterID,
'insertBefore' => false,
];
}
/**
* @param IViewFilter[] $filters
*/
public function addAvailableFilters(array $filters): void
{
foreach ($filters as $filter) {
$this->addAvailableFilter($filter);
}
}
/**
* @return array<string, IViewFilter>
*/
public function getAvailableFilters(): array
{
$this->init();
return $this->availableFilters;
}
private function init(): void
{
if (!isset($this->objectList)) {
$this->initObjectList();
}
}
/**
* Creates the database object list of this grid view.
*
* @return TDatabaseObjectList
*/
protected abstract function createObjectList(): DatabaseObjectList;
}