ILIAS  release_8 Revision v8.24
class.ilPDSelectedItemsBlockViewSettings.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
25{
27 protected static array $availableViews = [
31 ];
33 protected static array $availableSortOptions = [
37 ];
39 protected static array $availablePresentations = [
42 ];
44 protected static array $availableSortOptionsByView = [
45 self::VIEW_SELECTED_ITEMS => [
49 ],
50 self::VIEW_MY_MEMBERSHIPS => [
55 ],
56 self::VIEW_MY_STUDYPROGRAMME => []
57 ];
59 protected static array $availablePresentationsByView = [
60 self::VIEW_SELECTED_ITEMS => [
63 ],
64 self::VIEW_MY_MEMBERSHIPS => [
67 ],
68 self::VIEW_MY_STUDYPROGRAMME => []
69 ];
70 protected Setting $settings;
71 protected ilObjUser $actor;
72 protected array $validViews = [];
77
78 public function __construct(
80 int $view = self::VIEW_SELECTED_ITEMS,
81 Setting $settings = null,
83 ) {
84 global $DIC;
85
86 $this->settings = $settings ?? $DIC->settings();
87
88 $this->actor = $actor;
89 $this->currentView = $view;
90 $this->access = $access ?? new DashboardAccess();
91 }
92
93 public function getMembershipsView(): int
94 {
96 }
97
98 public function getSelectedItemsView(): int
99 {
101 }
102
103 public function getStudyProgrammeView(): int
104 {
106 }
107
108 public function getListPresentationMode(): string
109 {
111 }
112
113 public function getTilePresentationMode(): string
114 {
116 }
117
118 public function isMembershipsViewActive(): bool
119 {
120 return $this->currentView === $this->getMembershipsView();
121 }
122
123 public function isSelectedItemsViewActive(): bool
124 {
125 return $this->currentView === $this->getSelectedItemsView();
126 }
127
128 public function isStudyProgrammeViewActive(): bool
129 {
130 return $this->currentView === $this->getStudyProgrammeView();
131 }
132
133 public function getSortByStartDateMode(): string
134 {
136 }
137
138 public function getSortByLocationMode(): string
139 {
141 }
142
143 public function getSortByTypeMode(): string
144 {
145 return self::SORT_BY_TYPE;
146 }
147
148 public function getSortByAlphabetMode(): string
149 {
151 }
152
153 public function getAvailableSortOptionsByView(int $view): array
154 {
155 return self::$availableSortOptionsByView[$view];
156 }
157
158 public function getAvailablePresentationsByView(int $view): array
159 {
160 return self::$availablePresentationsByView[$view];
161 }
162
163 public function getDefaultSortingByView(int $view): string
164 {
165 switch ($view) {
166 case $this->getSelectedItemsView():
167 return $this->settings->get('selected_items_def_sort', $this->getSortByLocationMode());
168
169 default:
170 return $this->settings->get('my_memberships_def_sort', $this->getSortByLocationMode());
171 }
172 }
173
174 public function isSortedByType(): bool
175 {
176 return $this->currentSortOption === $this->getSortByTypeMode();
177 }
178
179 public function isSortedByAlphabet(): bool
180 {
181 return $this->currentSortOption === $this->getSortByAlphabetMode();
182 }
183
184 public function isSortedByLocation(): bool
185 {
186 return $this->currentSortOption === $this->getSortByLocationMode();
187 }
188
189 public function isSortedByStartDate(): bool
190 {
191 return $this->currentSortOption === $this->getSortByStartDateMode();
192 }
193
194 public function isTilePresentation(): bool
195 {
196 return $this->currentPresentationOption === $this->getTilePresentationMode();
197 }
198
199 public function isListPresentation(): bool
200 {
201 return $this->currentPresentationOption === $this->getListPresentationMode();
202 }
203
204 public function storeViewSorting(int $view, string $type, array $active): void
205 {
206 if (!in_array($type, $active, true)) {
207 $active[] = $type;
208 }
209
210 assert(in_array($type, $this->getAvailableSortOptionsByView($view), true));
211
212 switch ($view) {
213 case $this->getSelectedItemsView():
214 $this->settings->set('selected_items_def_sort', $type);
215 break;
216
217 default:
218 $this->settings->set('my_memberships_def_sort', $type);
219 break;
220 }
221
222 $this->settings->set('pd_active_sort_view_' . $view, serialize($active));
223 }
224
225 public function getActiveSortingsByView(int $view): array
226 {
227 $val = $this->settings->get('pd_active_sort_view_' . $view, '');
228 return ($val === '') ? [] : unserialize($val);
229 }
230
231 public function storeViewPresentation(int $view, string $default, array $active): void
232 {
233 if (!in_array($default, $active, true)) {
234 $active[] = $default;
235 }
236 $this->settings->set('pd_def_pres_view_' . $view, $default);
237 $this->settings->set('pd_active_pres_view_' . $view, serialize($active));
238 }
239
240 public function getDefaultPresentationByView(int $view): string
241 {
242 return $this->settings->get('pd_def_pres_view_' . $view, 'list');
243 }
244
245 public function getActivePresentationsByView(int $view): array
246 {
247 $val = $this->settings->get('pd_active_pres_view_' . $view, '');
248 return ($val === '') ? [] : unserialize($val);
249 }
250
251 public function enabledMemberships(): bool
252 {
253 return $this->settings->get('disable_my_memberships', '0') === '0';
254 }
255
256 public function enabledSelectedItems(): bool
257 {
258 return $this->settings->get('disable_my_offers', '0') === '0';
259 }
260
261 public function enableMemberships(bool $status): void
262 {
263 $this->settings->set('disable_my_memberships', $status ? '0' : '1');
264 }
265
266 public function enableSelectedItems(bool $status): void
267 {
268 $this->settings->set('disable_my_offers', $status ? '0' : '1');
269 }
270
271 public function allViewsEnabled(): bool
272 {
273 return $this->enabledMemberships() && $this->enabledSelectedItems();
274 }
275
276 protected function allViewsDisabled(): bool
277 {
278 return !$this->enabledMemberships() && !$this->enabledSelectedItems();
279 }
280
281 public function getDefaultView(): int
282 {
283 return (int) ($this->settings->get('personal_items_default_view') ?? $this->getSelectedItemsView());
284 }
285
286 public function storeDefaultView(int $view): void
287 {
288 $this->settings->set('personal_items_default_view', (string) $view);
289 }
290
291 public function parse(): void
292 {
293 $this->validViews = self::$availableViews;
294
295 $this->currentSortOption = $this->getEffectiveSortingMode();
296 $this->currentPresentationOption = $this->getEffectivePresentationMode();
297 }
298
299 public function getEffectivePresentationMode(): string
300 {
301 $mode = $this->actor->getPref('pd_view_pres_' . $this->currentView);
302
303 if (!in_array($mode, $this->getSelectablePresentationModes(), true)) {
304 $mode = $this->getDefaultPresentationByView($this->currentView);
305 }
306
307 return $mode;
308 }
309
310 public function getEffectiveSortingMode(): string
311 {
312 $mode = $this->actor->getPref('pd_order_items_' . $this->currentView);
313
314 if (!in_array($mode, $this->getSelectableSortingModes(), true)) {
315 $mode = $this->getDefaultSortingByView($this->currentView);
316 }
317
318 return $mode;
319 }
320
324 public function getSelectableSortingModes(): array
325 {
326 return array_intersect(
327 $this->getActiveSortingsByView($this->currentView),
328 $this->getAvailableSortOptionsByView($this->currentView)
329 );
330 }
331
335 public function getSelectablePresentationModes(): array
336 {
337 if (!$this->access->canChangePresentation($this->actor->getId())) {
338 return [$this->getDefaultSortingByView($this->currentView)];
339 }
340 return array_intersect(
341 $this->getActivePresentationsByView($this->currentView),
342 $this->getAvailablePresentationsByView($this->currentView)
343 );
344 }
345
346 public function storeActorPresentationMode(string $presentationMode): void
347 {
348 if (in_array($presentationMode, $this->getSelectablePresentationModes())) {
349 $this->actor->writePref(
350 'pd_view_pres_' . $this->currentView,
351 $presentationMode
352 );
353 }
354 }
355
356 public function storeActorSortingMode(string $sortingMode): void
357 {
358 if (in_array($sortingMode, $this->getSelectableSortingModes())) {
359 $this->actor->writePref(
360 'pd_order_items_' . $this->currentView,
361 $sortingMode
362 );
363 }
364 }
365
366 public function getActor(): ilObjUser
367 {
368 return $this->actor;
369 }
370
371 public function getCurrentView(): int
372 {
373 return $this->currentView;
374 }
375
376 public function getCurrentSortOption(): string
377 {
379 }
380
381 public function isValidView(int $view): bool
382 {
383 return in_array($view, $this->validViews, true);
384 }
385}
User class.
storeViewSorting(int $view, string $type, array $active)
__construct(ilObjUser $actor, int $view=self::VIEW_SELECTED_ITEMS, Setting $settings=null, DashboardAccess $access=null)
storeViewPresentation(int $view, string $default, array $active)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$type