ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
AbstractBaseSorter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
25
32abstract class AbstractBaseSorter implements CollectionSorter
33{
34 public function __construct(protected ResourceBuilder $resource_builder, protected int $direction = SORT_ASC)
35 {
36 }
37
38 abstract protected function sortResourceIdentification(array $identifications): array;
39
40
41 public function sort(ResourceCollection $collection): ResourceCollection
42 {
43 $identifications = $collection->getResourceIdentifications();
44 $collection->clear();
45 $sorted = $this->sortResourceIdentification($identifications);
46 if ($this->direction == SORT_DESC) {
47 $sorted = array_reverse($sorted);
48 }
49 foreach ($sorted as $identification) {
50 $collection->add($identification);
51 }
52
53 return $collection;
54 }
55}
add(ResourceIdentification $identification)
__construct(protected ResourceBuilder $resource_builder, protected int $direction=SORT_ASC)