ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilPDSelectedItemsBlockViewSettings.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2017 ILIAS open source, Extended GPL, see docs/LICENSE */
3
8{
12 protected static $availableViews = [
16 ];
17
21 protected static $availableSortOptions = [
25 ];
26
30 protected static $availablePresentations = [
33 ];
34
38 protected static $availableSortOptionsByView = [
39 self::VIEW_SELECTED_ITEMS => [
42 ],
43 self::VIEW_MY_MEMBERSHIPS => [
47 ],
48 self::VIEW_MY_STUDYPROGRAMME => []
49 ];
50
54 protected static $availablePresentationsByView = [
55 self::VIEW_SELECTED_ITEMS => [
58 ],
59 self::VIEW_MY_MEMBERSHIPS => [
62 ],
63 self::VIEW_MY_STUDYPROGRAMME => []
64 ];
65
67 protected $settings;
68
70 protected $actor;
71
73 protected $validViews = [];
74
77
80
83
87 protected $access;
88
94 public function __construct(ilObjUser $actor, int $view = self::VIEW_SELECTED_ITEMS)
95 {
96 global $DIC;
97
98 $ilSetting = $DIC->settings();
99
100 $this->settings = $ilSetting;
101
102 $this->actor = $actor;
103 $this->currentView = $view;
104 $this->access = new \ILIAS\Dashboard\Access\DashboardAccess();
105 }
106
110 public function getMembershipsView() : int
111 {
113 }
114
118 public function getSelectedItemsView() : int
119 {
121 }
122
126 public function getStudyProgrammeView() : int
127 {
129 }
130
134 public function getListPresentationMode() : string
135 {
137 }
138
142 public function getTilePresentationMode() : string
143 {
145 }
146
150 public function isMembershipsViewActive() : bool
151 {
152 return $this->currentView === $this->getMembershipsView();
153 }
154
158 public function isSelectedItemsViewActive() : bool
159 {
160 return $this->currentView === $this->getSelectedItemsView();
161 }
162
166 public function isStudyProgrammeViewActive() : bool
167 {
168 return $this->currentView === $this->getStudyProgrammeView();
169 }
170
174 public function getSortByStartDateMode() : string
175 {
177 }
178
182 public function getSortByLocationMode() : string
183 {
185 }
186
190 public function getSortByTypeMode() : string
191 {
192 return self::SORT_BY_TYPE;
193 }
194
201 public function getAvailableSortOptionsByView(int $view) : array
202 {
203 return self::$availableSortOptionsByView[$view];
204 }
205
212 public function getAvailablePresentationsByView(int $view) : array
213 {
214 return self::$availablePresentationsByView[$view];
215 }
216
221 public function getDefaultSortingByView(int $view) : string
222 {
223 switch ($view) {
224 case $this->getSelectedItemsView():
225 return $this->settings->get('selected_items_def_sort', $this->getSortByLocationMode());
226
227 default:
228 return $this->settings->get('my_memberships_def_sort', $this->getSortByLocationMode());
229 }
230 }
231
232
236 public function isSortedByType() : bool
237 {
238 return $this->currentSortOption === $this->getSortByTypeMode();
239 }
240
244 public function isSortedByLocation() : bool
245 {
246 return $this->currentSortOption === $this->getSortByLocationMode();
247 }
248
252 public function isSortedByStartDate() : bool
253 {
254 return $this->currentSortOption === $this->getSortByStartDateMode();
255 }
256
260 public function isTilePresentation() : bool
261 {
262 return $this->currentPresentationOption === $this->getTilePresentationMode();
263 }
264
268 public function isListPresentation() : bool
269 {
270 return $this->currentPresentationOption === $this->getListPresentationMode();
271 }
272
278 public function storeViewSorting(int $view, string $type, array $active)
279 {
280 if (!in_array($type, $active)) {
281 $active[] = $type;
282 }
283
284 assert(in_array($type, $this->getAvailableSortOptionsByView($view)));
285
286 switch ($view) {
287 case $this->getSelectedItemsView():
288 $this->settings->set('selected_items_def_sort', $type);
289 break;
290
291 default:
292 $this->settings->set('my_memberships_def_sort', $type);
293 break;
294 }
295
296 $this->settings->set('pd_active_sort_view_' . $view, serialize($active));
297 }
298
305 public function getActiveSortingsByView(int $view)
306 {
307 $val = $this->settings->get('pd_active_sort_view_' . $view);
308 return ($val == "")
309 ? []
310 : unserialize($val);
311 }
312
320 public function storeViewPresentation(int $view, string $default, array $active)
321 {
322 if (!in_array($default, $active)) {
323 $active[] = $default;
324 }
325 $this->settings->set('pd_def_pres_view_' . $view, $default);
326 $this->settings->set('pd_active_pres_view_' . $view, serialize($active));
327 }
328
335 public function getDefaultPresentationByView(int $view) : string
336 {
337 return $this->settings->get('pd_def_pres_view_' . $view, "list");
338 }
339
346 public function getActivePresentationsByView(int $view) : array
347 {
348 $val = $this->settings->get('pd_active_pres_view_' . $view, '');
349
350 return ('' === $val)
351 ? []
352 : unserialize($val);
353 }
354
358 public function enabledMemberships() : bool
359 {
360 return $this->settings->get('disable_my_memberships', 0) == 0;
361 }
362
366 public function enabledSelectedItems() : bool
367 {
368 return $this->settings->get('disable_my_offers', 0) == 0;
369 }
370
374 public function enableMemberships(bool $status)
375 {
376 $this->settings->set('disable_my_memberships', (int) !$status);
377 }
378
382 public function enableSelectedItems(bool $status)
383 {
384 $this->settings->set('disable_my_offers', (int) !$status);
385 }
386
390 public function allViewsEnabled() : bool
391 {
392 return $this->enabledMemberships() && $this->enabledSelectedItems();
393 }
394
398 protected function allViewsDisabled() : bool
399 {
400 return !$this->enabledMemberships() && !$this->enabledSelectedItems();
401 }
402
406 public function getDefaultView() : int
407 {
408 return (int) $this->settings->get('personal_items_default_view', $this->getSelectedItemsView());
409 }
410
414 public function storeDefaultView(int $view)
415 {
416 $this->settings->set('personal_items_default_view', $view);
417 }
418
422 public function parse()
423 {
424 $this->validViews = self::$availableViews;
425
426 /*
427 foreach (array_filter([
428 $this->getMembershipsView() => !$this->enabledMemberships(),
429 $this->getSelectedItemsView() => !$this->enabledSelectedItems()
430 ]) as $viewId => $status) {
431 $key = array_search($viewId, $this->validViews);
432 if ($key !== false) {
433 unset($this->validViews[$key]);
434 }
435 }
436
437
438 if (1 === count($this->validViews)) {
439 $this->storeDefaultView($this->getSelectedItemsView());
440 $this->validViews[] = $this->getSelectedItemsView();
441 }
442
443 if (!$this->isValidView($this->getCurrentView())) {
444 $this->currentView = $this->getDefaultView();
445 }*/
446
447 $this->currentSortOption = $this->getEffectiveSortingMode();
448 $this->currentPresentationOption = $this->getEffectivePresentationMode();
449 }
450
454 public function getEffectivePresentationMode() : string
455 {
456 $mode = $this->actor->getPref('pd_view_pres_' . $this->currentView);
457
458 if (!in_array($mode, $this->getSelectablePresentationModes())) {
459 $mode = $this->getDefaultPresentationByView($this->currentView);
460 }
461
462 return $mode;
463 }
464
465
469 public function getEffectiveSortingMode() : string
470 {
471 $mode = $this->actor->getPref('pd_order_items_' . $this->currentView);
472
473 if (!in_array($mode, $this->getSelectableSortingModes())) {
474 $mode = $this->getDefaultSortingByView($this->currentView);
475 }
476
477 return $mode;
478 }
479
483 public function getSelectableSortingModes() : array
484 {
485 return array_intersect(
486 $this->getActiveSortingsByView($this->currentView),
487 $this->getAvailableSortOptionsByView($this->currentView)
488 );
489 }
490
494 public function getSelectablePresentationModes() : array
495 {
496 if (!$this->access->canChangePresentation($this->actor->getId())) {
497 return [$this->getDefaultSortingByView($this->currentView)];
498 }
499 return array_intersect(
500 $this->getActivePresentationsByView($this->currentView),
501 $this->getAvailablePresentationsByView($this->currentView)
502 );
503 }
504
508 public function storeActorPresentationMode(string $presentationMode)
509 {
510 if (in_array($presentationMode, $this->getSelectablePresentationModes())) {
511 $this->actor->writePref(
512 'pd_view_pres_' . $this->currentView,
513 $presentationMode
514 );
515 }
516 }
517
521 public function storeActorSortingMode(string $sortingMode)
522 {
523 if (in_array($sortingMode, $this->getSelectableSortingModes())) {
524 $this->actor->writePref(
525 'pd_order_items_' . $this->currentView,
526 $sortingMode
527 );
528 }
529 }
530
534 public function getActor() : ilObjUser
535 {
536 return $this->actor;
537 }
538
542 public function getCurrentView() : int
543 {
544 return $this->currentView;
545 }
546
550 public function getCurrentSortOption() : int
551 {
553 }
554
559 public function isValidView(int $view) : bool
560 {
561 return in_array($view, $this->validViews);
562 }
563}
An exception for terminatinating execution or to throw for unit testing.
storeViewSorting(int $view, string $type, array $active)
getActiveSortingsByView(int $view)
Get active sort options by view.
getDefaultPresentationByView(int $view)
Get default presentation.
getActivePresentationsByView(int $view)
Get active presentations by view.
storeViewPresentation(int $view, string $default, array $active)
Store default presentation.
__construct(ilObjUser $actor, int $view=self::VIEW_SELECTED_ITEMS)
ilPDSelectedItemsBlockViewSettings constructor.
getAvailableSortOptionsByView(int $view)
Get available sort options by view.
getAvailablePresentationsByView(int $view)
Get available presentations by view.
global $DIC
Definition: goto.php:24
global $ilSetting
Definition: privfeed.php:17
$type
settings()
Definition: settings.php:2