ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 include_once("./Services/Dashboard/Access/class.DashboardAccess.php");
105 $this->access = new \ILIAS\Dashboard\Access\DashboardAccess();
106 }
107
111 public function getMembershipsView() : int
112 {
114 }
115
119 public function getSelectedItemsView() : int
120 {
122 }
123
127 public function getStudyProgrammeView() : int
128 {
130 }
131
135 public function getListPresentationMode() : string
136 {
138 }
139
143 public function getTilePresentationMode() : string
144 {
146 }
147
151 public function isMembershipsViewActive() : bool
152 {
153 return $this->currentView === $this->getMembershipsView();
154 }
155
159 public function isSelectedItemsViewActive() : bool
160 {
161 return $this->currentView === $this->getSelectedItemsView();
162 }
163
167 public function isStudyProgrammeViewActive() : bool
168 {
169 return $this->currentView === $this->getStudyProgrammeView();
170 }
171
175 public function getSortByStartDateMode() : string
176 {
178 }
179
183 public function getSortByLocationMode() : string
184 {
186 }
187
191 public function getSortByTypeMode() : string
192 {
193 return self::SORT_BY_TYPE;
194 }
195
202 public function getAvailableSortOptionsByView(int $view) : array
203 {
204 return self::$availableSortOptionsByView[$view];
205 }
206
213 public function getAvailablePresentationsByView(int $view) : array
214 {
215 return self::$availablePresentationsByView[$view];
216 }
217
222 public function getDefaultSortingByView(int $view) : string
223 {
224 switch ($view) {
225 case $this->getSelectedItemsView():
226 return $this->settings->get('selected_items_def_sort', $this->getSortByLocationMode());
227
228 default:
229 return $this->settings->get('my_memberships_def_sort', $this->getSortByLocationMode());
230 }
231 }
232
233
237 public function isSortedByType() : bool
238 {
239 return $this->currentSortOption === $this->getSortByTypeMode();
240 }
241
245 public function isSortedByLocation() : bool
246 {
247 return $this->currentSortOption === $this->getSortByLocationMode();
248 }
249
253 public function isSortedByStartDate() : bool
254 {
255 return $this->currentSortOption === $this->getSortByStartDateMode();
256 }
257
261 public function isTilePresentation() : bool
262 {
263 return $this->currentPresentationOption === $this->getTilePresentationMode();
264 }
265
269 public function isListPresentation() : bool
270 {
271 return $this->currentPresentationOption === $this->getListPresentationMode();
272 }
273
279 public function storeViewSorting(int $view, string $type, array $active)
280 {
281 if (!in_array($type, $active)) {
282 $active[] = $type;
283 }
284
285 assert(in_array($type, $this->getAvailableSortOptionsByView($view)));
286
287 switch ($view) {
288 case $this->getSelectedItemsView():
289 $this->settings->set('selected_items_def_sort', $type);
290 break;
291
292 default:
293 $this->settings->set('my_memberships_def_sort', $type);
294 break;
295 }
296
297 $this->settings->set('pd_active_sort_view_' . $view, serialize($active));
298 }
299
306 public function getActiveSortingsByView(int $view)
307 {
308 $val = $this->settings->get('pd_active_sort_view_' . $view);
309 return ($val == "")
310 ? []
311 : unserialize($val);
312 }
313
321 public function storeViewPresentation(int $view, string $default, array $active)
322 {
323 if (!in_array($default, $active)) {
324 $active[] = $default;
325 }
326 $this->settings->set('pd_def_pres_view_' . $view, $default);
327 $this->settings->set('pd_active_pres_view_' . $view, serialize($active));
328 }
329
336 public function getDefaultPresentationByView(int $view) : string
337 {
338 return $this->settings->get('pd_def_pres_view_' . $view, "list");
339 }
340
347 public function getActivePresentationsByView(int $view) : array
348 {
349 $val = $this->settings->get('pd_active_pres_view_' . $view, '');
350
351 return ('' === $val)
352 ? []
353 : unserialize($val);
354 }
355
359 public function enabledMemberships() : bool
360 {
361 return $this->settings->get('disable_my_memberships', 0) == 0;
362 }
363
367 public function enabledSelectedItems() : bool
368 {
369 return $this->settings->get('disable_my_offers', 0) == 0;
370 }
371
375 public function enableMemberships(bool $status)
376 {
377 $this->settings->set('disable_my_memberships', (int) !$status);
378 }
379
383 public function enableSelectedItems(bool $status)
384 {
385 $this->settings->set('disable_my_offers', (int) !$status);
386 }
387
391 public function allViewsEnabled() : bool
392 {
393 return $this->enabledMemberships() && $this->enabledSelectedItems();
394 }
395
399 protected function allViewsDisabled() : bool
400 {
401 return !$this->enabledMemberships() && !$this->enabledSelectedItems();
402 }
403
407 public function getDefaultView() : int
408 {
409 return (int) $this->settings->get('personal_items_default_view', $this->getSelectedItemsView());
410 }
411
415 public function storeDefaultView(int $view)
416 {
417 $this->settings->set('personal_items_default_view', $view);
418 }
419
423 public function parse()
424 {
425 $this->validViews = self::$availableViews;
426
427 /*
428 foreach (array_filter([
429 $this->getMembershipsView() => !$this->enabledMemberships(),
430 $this->getSelectedItemsView() => !$this->enabledSelectedItems()
431 ]) as $viewId => $status) {
432 $key = array_search($viewId, $this->validViews);
433 if ($key !== false) {
434 unset($this->validViews[$key]);
435 }
436 }
437
438
439 if (1 === count($this->validViews)) {
440 $this->storeDefaultView($this->getSelectedItemsView());
441 $this->validViews[] = $this->getSelectedItemsView();
442 }
443
444 if (!$this->isValidView($this->getCurrentView())) {
445 $this->currentView = $this->getDefaultView();
446 }*/
447
448 $this->currentSortOption = $this->getEffectiveSortingMode();
449 $this->currentPresentationOption = $this->getEffectivePresentationMode();
450 }
451
455 public function getEffectivePresentationMode() : string
456 {
457 $mode = $this->actor->getPref('pd_view_pres_' . $this->currentView);
458
459 if (!in_array($mode, $this->getSelectablePresentationModes())) {
460 $mode = $this->getDefaultPresentationByView($this->currentView);
461 }
462
463 return $mode;
464 }
465
466
470 public function getEffectiveSortingMode() : string
471 {
472 $mode = $this->actor->getPref('pd_order_items_' . $this->currentView);
473
474 if (!in_array($mode, $this->getSelectableSortingModes())) {
475 $mode = $this->getDefaultSortingByView($this->currentView);
476 }
477
478 return $mode;
479 }
480
484 public function getSelectableSortingModes() : array
485 {
486 return array_intersect(
487 $this->getActiveSortingsByView($this->currentView),
488 $this->getAvailableSortOptionsByView($this->currentView)
489 );
490 }
491
495 public function getSelectablePresentationModes() : array
496 {
497 if (!$this->access->canChangePresentation($this->actor->getId())) {
498 return [$this->getDefaultSortingByView($this->currentView)];
499 }
500 return array_intersect(
501 $this->getActivePresentationsByView($this->currentView),
502 $this->getAvailablePresentationsByView($this->currentView)
503 );
504 }
505
509 public function storeActorPresentationMode(string $presentationMode)
510 {
511 if (in_array($presentationMode, $this->getSelectablePresentationModes())) {
512 $this->actor->writePref(
513 'pd_view_pres_' . $this->currentView,
514 $presentationMode
515 );
516 }
517 }
518
522 public function storeActorSortingMode(string $sortingMode)
523 {
524 if (in_array($sortingMode, $this->getSelectableSortingModes())) {
525 $this->actor->writePref(
526 'pd_order_items_' . $this->currentView,
527 $sortingMode
528 );
529 }
530 }
531
535 public function getActor() : ilObjUser
536 {
537 return $this->actor;
538 }
539
543 public function getCurrentView() : int
544 {
545 return $this->currentView;
546 }
547
551 public function getCurrentSortOption() : int
552 {
554 }
555
560 public function isValidView(int $view) : bool
561 {
562 return in_array($view, $this->validViews);
563 }
564}
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 $ilSetting
Definition: privfeed.php:17
$type
settings()
Definition: settings.php:2
$DIC
Definition: xapitoken.php:46