ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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;
40
41 public function __construct(protected ResourceBuilder $resource_builder, protected CollectionBuilder $collection_builder, protected ResourceCollection $collection)
42 {
43 }
44
45 public function andSave(): self
46 {
47 $this->sort_and_save = true;
48 return $this;
49 }
50
51 public function asc(): self
52 {
53 $this->sort_direction = self::SORT_ASC;
54 return $this;
55 }
56
57 public function desc(): self
58 {
59 $this->sort_direction = self::SORT_DESC;
60 return $this;
61 }
62
63
64 public function byTitle(): ResourceCollection
65 {
66 return $this->custom(new ByTitle($this->resource_builder, $this->sort_direction));
67 }
68
69 public function bySize(): ResourceCollection
70 {
71 return $this->custom(new BySize($this->resource_builder, $this->sort_direction));
72 }
73
74
76 {
77 return $this->custom(new ByCreationDate($this->resource_builder, $this->sort_direction));
78 }
79
80 public function custom(CollectionSorter $sorter): ResourceCollection
81 {
82 $collection = $sorter->sort($this->collection);
83 if ($this->sort_and_save) {
84 $this->collection_builder->store($collection);
85 }
86 return $collection;
87 }
88}
custom(CollectionSorter $sorter)
Definition: Sorter.php:80
__construct(protected ResourceBuilder $resource_builder, protected CollectionBuilder $collection_builder, protected ResourceCollection $collection)
Definition: Sorter.php:41