ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 require_once 'Services/PersonalDesktop/ItemsBlock/interfaces/interface.ilPDSelectedItemsBlockConstants.php';
5 
10 {
14  protected static $availableViews = array(
15  self::VIEW_SELECTED_ITEMS,
16  self::VIEW_MY_MEMBERSHIPS,
17  self::VIEW_MY_STUDYPROGRAMME
18  );
19 
23  protected static $availableSortOptions = array(
24  self::SORT_BY_LOCATION,
25  self::SORT_BY_TYPE,
26  self::SORT_BY_START_DATE
27  );
28 
32  protected static $availableSortOptionsByView = array(
33  self::VIEW_SELECTED_ITEMS => array(
34  self::SORT_BY_LOCATION,
35  self::SORT_BY_TYPE
36  ),
37  self::VIEW_MY_MEMBERSHIPS => array(
38  self::SORT_BY_LOCATION,
39  self::SORT_BY_TYPE,
40  self::SORT_BY_START_DATE
41  ),
42  self::VIEW_MY_STUDYPROGRAMME => array(
43  )
44  );
45 
49  protected $settings;
50 
54  protected $actor;
55 
59  protected $validViews = array();
60 
64  protected $currentView = self::VIEW_SELECTED_ITEMS;
65 
69  protected $currentSortOption = self::SORT_BY_LOCATION;
70 
76  public function __construct($actor, $view = self::VIEW_SELECTED_ITEMS)
77  {
78  global $DIC;
79 
80  $ilSetting = $DIC->settings();
81 
82  $this->settings = $ilSetting;
83 
84  $this->actor = $actor;
85  $this->currentView = $view;
86  }
87 
91  public function getMembershipsView()
92  {
93  return self::VIEW_MY_MEMBERSHIPS;
94  }
95 
99  public function getSelectedItemsView()
100  {
101  return self::VIEW_SELECTED_ITEMS;
102  }
103 
107  public function getStudyProgrammeView()
108  {
109  return self::VIEW_MY_STUDYPROGRAMME;
110  }
111 
115  public function isMembershipsViewActive()
116  {
117  return $this->currentView == $this->getMembershipsView();
118  }
119 
123  public function isSelectedItemsViewActive()
124  {
125  return $this->currentView == $this->getSelectedItemsView();
126  }
127 
131  public function isStudyProgrammeViewActive()
132  {
133  return $this->currentView == $this->getStudyProgrammeView();
134  }
135 
139  public function getSortByStartDateMode()
140  {
141  return self::SORT_BY_START_DATE;
142  }
143 
147  public function getSortByLocationMode()
148  {
149  return self::SORT_BY_LOCATION;
150  }
151 
155  public function getSortByTypeMode()
156  {
157  return self::SORT_BY_TYPE;
158  }
159 
163  public function getDefaultSortType()
164  {
165  return $this->settings->get('my_memberships_def_sort', $this->getSortByLocationMode());
166  }
167 
171  public function isSortedByType()
172  {
173  return $this->currentSortOption == $this->getSortByTypeMode();
174  }
175 
179  public function isSortedByLocation()
180  {
181  return $this->currentSortOption == $this->getSortByLocationMode();
182  }
183 
187  public function isSortedByStartDate()
188  {
189  return $this->currentSortOption == $this->getSortByStartDateMode();
190  }
191 
195  public function storeDefaultSortType($type)
196  {
197  assert(in_array($type, self::$availableSortOptions));
198  $this->settings->set('my_memberships_def_sort', $type);
199  }
200 
204  public function enabledMemberships()
205  {
206  return $this->settings->get('disable_my_memberships', 0) == 0;
207  }
208 
212  public function enabledSelectedItems()
213  {
214  return $this->settings->get('disable_my_offers', 0) == 0;
215  }
216 
220  public function enableMemberships($status)
221  {
222  $this->settings->set('disable_my_memberships', (int) !$status);
223  }
224 
228  public function enableSelectedItems($status)
229  {
230  $this->settings->set('disable_my_offers', (int) !$status);
231  }
232 
236  public function allViewsEnabled()
237  {
238  return $this->enabledMemberships() && $this->enabledSelectedItems();
239  }
240 
244  protected function allViewsDisabled()
245  {
246  return !$this->enabledMemberships() && !$this->enabledSelectedItems();
247  }
248 
252  public function getDefaultView()
253  {
254  return (int) $this->settings->get('personal_items_default_view', $this->getSelectedItemsView());
255  }
256 
260  public function storeDefaultView($view)
261  {
262  assert(in_array($view, self::$availableViews));
263  $this->settings->set('personal_items_default_view', $view);
264  }
265 
269  public function parse()
270  {
271  $this->validViews = self::$availableViews;
272 
273  foreach (array_filter([
274  $this->getMembershipsView() => !$this->enabledMemberships(),
275  $this->getSelectedItemsView() => !$this->enabledSelectedItems()
276  ]) as $viewId => $status) {
277  $key = array_search($viewId, $this->validViews);
278  if ($key !== false) {
279  unset($this->validViews[$key]);
280  }
281  }
282 
283  if (count($this->validViews) == 1) {
284  $this->storeDefaultView($this->getSelectedItemsView());
285  $this->validViews[] = $this->getSelectedItemsView();
286  }
287 
288  if (!$this->isValidView($this->getCurrentView())) {
289  $this->currentView = $this->getDefaultView();
290  }
291 
292  $this->currentSortOption = $this->actor->getPref('pd_order_items');
293  if (!in_array($this->currentSortOption, self::$availableSortOptionsByView[$this->currentView])) {
294  if ($this->isSelectedItemsViewActive()) {
295  $this->currentSortOption = self::SORT_BY_LOCATION;
296  } elseif ($this->isStudyProgrammeViewActive()) {
297  $this->currentSortOption = $this->getDefaultSortType();
298  }
299  }
300  }
301 
305  public function getActor()
306  {
307  return $this->actor;
308  }
309 
313  public function getCurrentView()
314  {
315  return $this->currentView;
316  }
317 
321  public function getCurrentSortOption()
322  {
324  }
325 
330  public function isValidView($view)
331  {
332  return in_array($view, $this->validViews);
333  }
334 }
settings()
Definition: settings.php:2
$type
global $DIC
Definition: saml.php:7
Class ilPDSelectedItemsBlockViewSettings.
global $ilSetting
Definition: privfeed.php:17
$key
Definition: croninfo.php:18
__construct($actor, $view=self::VIEW_SELECTED_ITEMS)
ilPDSelectedItemsBlockViewSettings constructor.