ILIAS  release_8 Revision v8.24
Sorter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
26
33class Sorter
34{
35 protected const SORT_ASC = SORT_ASC;
36 protected const SORT_DESC = SORT_DESC;
37
39 private bool $sort_and_save = false;
43
44 public function __construct(
48 ) {
49 $this->resource_builder = $resource_builder;
50 $this->collection_builder = $collection_builder;
51 $this->collection = $collection;
52 }
53
54 public function andSave(): self
55 {
56 $this->sort_and_save = true;
57 return $this;
58 }
59
60 public function asc(): self
61 {
62 $this->sort_direction = self::SORT_ASC;
63 return $this;
64 }
65
66 public function desc(): self
67 {
68 $this->sort_direction = self::SORT_DESC;
69 return $this;
70 }
71
72
73 public function byTitle(): ResourceCollection
74 {
75 return $this->custom(new ByTitle($this->resource_builder, $this->sort_direction));
76 }
77
78 public function bySize(): ResourceCollection
79 {
80 return $this->custom(new BySize($this->resource_builder, $this->sort_direction));
81 }
82
83
85 {
86 return $this->custom(new ByCreationDate($this->resource_builder, $this->sort_direction));
87 }
88
89 public function custom(CollectionSorter $sorter): ResourceCollection
90 {
91 $collection = $sorter->sort($this->collection);
92 if ($this->sort_and_save) {
93 $this->collection_builder->store($collection);
94 }
95 return $collection;
96 }
97}
custom(CollectionSorter $sorter)
Definition: Sorter.php:89
__construct(ResourceBuilder $resource_builder, CollectionBuilder $collection_builder, ResourceCollection $collection)
Definition: Sorter.php:44