ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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 {
35  public const MODE_AS_DATA_TABLE = 1;
39  public const MODE_AS_PRESENTATION_TABLE = 2;
43  public const MODE_AS_ITEMS = 3;
47  public const MODE_AS_DECK = 4;
51  public const P_PAGE = 'irss_page';
55  public const P_SORTATION = 'irss_sort';
59  public const BY_CREATION_DATE_DESC = 'by_creation_date_desc';
63  public const BY_CREATION_DATE_ASC = 'by_creation_date_asc';
67  public const BY_TITLE_DESC = 'by_title_desc';
71  public const BY_TITLE_ASC = 'by_title_asc';
75  public const BY_SIZE_DESC = 'by_size_desc';
79  public const BY_SIZE_ASC = 'by_size_asc';
83  public const P_MODE = 'irss_view_mode';
84  private Mode $mode;
85  private int $page;
86  private string $sortation;
88  private int $items_per_page = 20;
89 
90  public function __construct(
91  private \ilCtrlInterface $ctrl,
92  private ArrayBasedRequestWrapper $query,
93  private Configuration $view_configuration,
94  ) {
95  global $DIC;
96  $this->ctrl = $DIC->ctrl();
97  $this->refinery = $DIC->refinery();
98 
99  $this->mode = $this->determineMode();
100  $this->page = $this->determinePage();
101  $this->sortation = $this->determineSortation();
102  $this->items_per_page = $this->view_configuration->getItemsPerPage();
103  }
104 
105  public function init(
106  \ilResourceCollectionGUI $collection_gui
107  ): void {
108  $this->ctrl->saveParameter($collection_gui, self::P_SORTATION);
109  $this->ctrl->saveParameter($collection_gui, self::P_PAGE);
110  $this->ctrl->saveParameter($collection_gui, self::P_MODE);
111  $this->ctrl->saveParameter($collection_gui, 'tsort_f');
112  $this->ctrl->saveParameter($collection_gui, 'tsort_d');
113  }
114 
115  public function handleViewTitle(): bool
116  {
117  return false;
118  }
119 
120  private function determinePage(): int
121  {
122  return $this->query->has(self::P_PAGE)
123  ? $this->query->retrieve(self::P_PAGE, $this->refinery->kindlyTo()->int())
124  : 0;
125  }
126 
127  public function setPage(int $page): void
128  {
129  $this->page = $page;
130  }
131 
132  public function getItemsPerPage(): int
133  {
134  return $this->items_per_page;
135  }
136 
137  public function setItemsPerPage(int $items_per_page): void
138  {
139  $this->items_per_page = $items_per_page;
140  }
141 
142  public function getTitle(): ?string
143  {
144  return $this->view_configuration->getTitle();
145  }
146 
147  public function getDescription(): ?string
148  {
149  return $this->view_configuration->getDescription();
150  }
151 
152  private function determineSortation(): string
153  {
154  return $this->query->has(self::P_SORTATION)
155  ? $this->query->retrieve(self::P_SORTATION, $this->refinery->kindlyTo()->string())
156  : self::BY_TITLE_ASC;
157  }
158 
159  public function setSortation(string $sortation): void
160  {
161  $this->sortation = $sortation;
162  }
163 
165  {
166  return $this->view_configuration->getCollection();
167  }
168 
169  private function determineMode(): Mode
170  {
171  return $this->query->has(self::P_MODE)
172  ? Mode::from($this->query->retrieve(self::P_MODE, $this->refinery->kindlyTo()->int()))
173  : $this->view_configuration->getMode();
174  }
175 
176  public function getMode(): Mode
177  {
178  return $this->mode;
179  }
180 
181  public function getPage(): int
182  {
183  return $this->page;
184  }
185 
186  public function getSortation(): string
187  {
188  return $this->sortation;
189  }
190 
191  public function canUserUplaod(): bool
192  {
193  return $this->view_configuration->canUserUpload();
194  }
195 
196  public function canUserAdministrate(): bool
197  {
198  return $this->view_configuration->canUserAdministrate();
199  }
200 }
init(\ilResourceCollectionGUI $collection_gui)
Definition: Request.php:105
global $DIC
Definition: shib_login.php:26
__construct(private \ilCtrlInterface $ctrl, private ArrayBasedRequestWrapper $query, private Configuration $view_configuration,)
Definition: Request.php:90
sortation()
expected output: > ILIAS shows the rendered Component.
Definition: sortation.php:29