ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
Request.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
26 
30 final class Request
31 {
32  public const MODE_AS_DATA_TABLE = 1;
33  public const MODE_AS_PRESENTATION_TABLE = 2;
34  public const MODE_AS_ITEMS = 3;
35  public const MODE_AS_DECK = 4;
36  public const P_PAGE = 'irss_page';
37  public const P_SORTATION = 'irss_sort';
38  public const BY_CREATION_DATE_DESC = 'by_creation_date_desc';
39  public const BY_CREATION_DATE_ASC = 'by_creation_date_asc';
40  public const BY_TITLE_DESC = 'by_title_desc';
41  public const BY_TITLE_ASC = 'by_title_asc';
42  public const BY_SIZE_DESC = 'by_size_desc';
43  public const BY_SIZE_ASC = 'by_size_asc';
44  public const P_MODE = 'irss_view_mode';
45  private Mode $mode;
46  private int $page;
47  private string $sortation;
48  private Factory $refinery;
49  private int $items_per_page = 20;
50 
51  public function __construct(
52  private \ilCtrlInterface $ctrl,
53  private ArrayBasedRequestWrapper $query,
54  private Configuration $view_configuration,
55  ) {
56  global $DIC;
57  $this->ctrl = $DIC->ctrl();
58  $this->refinery = $DIC->refinery();
59 
60  $this->mode = $this->determineMode();
61  $this->page = $this->determinePage();
62  $this->sortation = $this->determineSortation();
63  $this->items_per_page = $this->view_configuration->getItemsPerPage();
64  }
65 
66  public function init(
67  \ilResourceCollectionGUI $collection_gui
68  ): void {
69  $this->ctrl->saveParameter($collection_gui, self::P_SORTATION);
70  $this->ctrl->saveParameter($collection_gui, self::P_PAGE);
71  $this->ctrl->saveParameter($collection_gui, self::P_MODE);
72  $this->ctrl->saveParameter($collection_gui, 'tsort_f');
73  $this->ctrl->saveParameter($collection_gui, 'tsort_d');
74  }
75 
76  public function handleViewTitle(): bool
77  {
78  return false;
79  }
80 
81  private function determinePage(): int
82  {
83  return $this->query->has(self::P_PAGE)
84  ? $this->query->retrieve(self::P_PAGE, $this->refinery->kindlyTo()->int())
85  : 0;
86  }
87 
88  public function setPage(int $page): void
89  {
90  $this->page = $page;
91  }
92 
93  public function getItemsPerPage(): int
94  {
95  return $this->items_per_page;
96  }
97 
98  public function setItemsPerPage(int $items_per_page): void
99  {
100  $this->items_per_page = $items_per_page;
101  }
102 
103  public function getTitle(): ?string
104  {
105  return $this->view_configuration->getTitle();
106  }
107 
108  public function getDescription(): ?string
109  {
110  return $this->view_configuration->getDescription();
111  }
112 
113  private function determineSortation(): string
114  {
115  return $this->query->has(self::P_SORTATION)
116  ? $this->query->retrieve(self::P_SORTATION, $this->refinery->kindlyTo()->string())
117  : self::BY_TITLE_ASC;
118  }
119 
120  public function setSortation(string $sortation): void
121  {
122  $this->sortation = $sortation;
123  }
124 
126  {
127  return $this->view_configuration->getCollection();
128  }
129 
130  private function determineMode(): Mode
131  {
132  return $this->query->has(self::P_MODE)
133  ? Mode::from($this->query->retrieve(self::P_MODE, $this->refinery->kindlyTo()->int()))
134  : $this->view_configuration->getMode();
135  }
136 
137  public function getMode(): Mode
138  {
139  return $this->mode;
140  }
141 
142  public function getPage(): int
143  {
144  return $this->page;
145  }
146 
147  public function getSortation(): string
148  {
149  return $this->sortation;
150  }
151 
152  public function canUserUplaod(): bool
153  {
154  return $this->view_configuration->canUserUpload();
155  }
156 
157  public function canUserAdministrate(): bool
158  {
159  return $this->view_configuration->canUserAdministrate();
160  }
161 }
init(\ilResourceCollectionGUI $collection_gui)
Definition: Request.php:66
global $DIC
Definition: shib_login.php:25
__construct(private \ilCtrlInterface $ctrl, private ArrayBasedRequestWrapper $query, private Configuration $view_configuration,)
Definition: Request.php:51
sortation()
expected output: > ILIAS shows the rendered Component.
Definition: sortation.php:13