ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilPDSelectedItemsBlockViewGUI.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/classes/class.ilPDSelectedItemsBlockGroup.php';
5 
10 {
14  protected $viewSettings;
15 
19  protected $provider;
20 
24  protected $lng;
25 
29  protected $tree;
30 
34  protected $object_cache;
35 
39  protected $accessHandler;
40 
47  {
48  global $DIC;
49 
50  $this->lng = $DIC->language();
51  $this->tree = $DIC->repositoryTree();
52  $this->object_cache = $DIC['ilObjDataCache'];
53  $this->accessHandler = $DIC->rbac()->system();
54 
55  $this->viewSettings = $viewSettings;
56  $this->provider = $provider;
57  }
58 
62  abstract public function getScreenId();
63 
67  abstract public function getTitle();
68 
73  {
74  if ($this->viewSettings->isSortedByLocation()) {
75  return 1;
76  }
77 
78  return 3;
79  }
80 
84  abstract public function supportsSelectAll();
85 
89  abstract public function getIntroductionHtml();
90 
94  abstract public function getGroups();
95 
100  public function mayRemoveItem($refId)
101  {
102  return true;
103  }
104 
108  public function getItemGroups()
109  {
110  $items_groups = $this->getGroups();
111 
112  $this->preloadItemGroups($items_groups);
113 
114  return $items_groups;
115  }
116 
122  {
123  if ($viewSettings->isMembershipsViewActive()) {
124  require_once 'Services/PersonalDesktop/ItemsBlock/classes/class.ilPDSelectedItemsBlockMembershipsViewGUI.php';
125  require_once 'Services/PersonalDesktop/ItemsBlock/classes/class.ilPDSelectedItemsBlockMembershipsProvider.php';
127  $viewSettings,
129  );
130  }
131 
132  require_once 'Services/PersonalDesktop/ItemsBlock/classes/class.ilPDSelectedItemsBlockSelectedItemsViewGUI.php';
133  require_once 'Services/PersonalDesktop/ItemsBlock/classes/class.ilPDSelectedItemsBlockSelectedItemsProvider.php';
135  $viewSettings,
137  );
138  }
139 
144  protected function isRootNode($refId)
145  {
146  return $this->tree->getRootId() == $refId;
147  }
148 
152  protected function getRepositoryTitle()
153  {
154  $nd = $this->tree->getNodeData($this->tree->getRootId());
155  $title = $nd['title'];
156 
157  if ($title == 'ILIAS') {
158  $title = $this->lng->txt('repository');
159  }
160 
161  return $title;
162  }
163 
167  protected function preloadItemGroups(array $item_groups)
168  {
169  require_once 'Services/Object/classes/class.ilObjectListGUIPreloader.php';
171 
172  $obj_ids = [];
173  foreach ($item_groups as $item_group) {
174  foreach ($item_group->getItems() as $item) {
175  $obj_ids[] = $item['obj_id'];
176  $listPreloader->addItem($item['obj_id'], $item['type'], $item['ref_id']);
177  }
178  }
179 
180  $listPreloader->preload();
182  }
183 
187  protected function groupItemsByType()
188  {
189  global $DIC;
190 
191  $objDefinition = $DIC["objDefinition"];
192 
193  $object_types_by_container = $DIC['objDefinition']->getGroupedRepositoryObjectTypes(array('cat', 'crs', 'grp', 'fold'));
194 
195  $grouped_items = array();
196 
197  foreach ($object_types_by_container as $container_object_type => $container_data) {
198  $group = new ilPDSelectedItemsBlockGroup();
199  // Icons are currently not determined for section header objects
200  if (!$objDefinition->isPlugin($container_object_type)) {
201  $title = $this->lng->txt('objs_' . $container_object_type);
202  } else {
203  include_once("./Services/Component/classes/class.ilPlugin.php");
204  $pl = ilObjectPlugin::getRepoPluginObjectByType($container_object_type);
205  $title= $pl->txt("objs_" . $container_object_type);
206  }
207 
208  $group->setLabel($title);
209  $group->setItems($this->provider->getItems($container_data['objs']));
210 
211  $grouped_items[] = $group;
212  }
213 
214  return $grouped_items;
215  }
216 
220  protected function groupItemsByStartDate()
221  {
222  $items = $this->provider->getItems();
223 
224  if (0 == count($items)) {
225  return array();
226  }
227 
228  $groups = array(
229  'upcoming' => array(),
230  'ongoing' => array(),
231  'ended' => array(),
232  'not_dated' => array()
233  );
234 
235  foreach ($items as $key => $item) {
236  if ($item['start'] && $item['start'] && $item['start'] instanceof ilDate) {
237  if ($item['start']->get(IL_CAL_UNIX) > time()) {
238  $groups['upcoming'][] = $item;
239  } elseif ($item['end']->get(IL_CAL_UNIX) > time()) {
240  $groups['ongoing'][] = $item;
241  } else {
242  $groups['ended'][] = $item;
243  }
244  } else {
245  $groups['not_dated'][] = $item;
246  }
247  }
248 
249  uasort($groups['upcoming'], function ($left, $right) {
250  if ($left['start']->get(IL_CAL_UNIX) < $right['start']->get(IL_CAL_UNIX)) {
251  return -1;
252  } elseif ($left['start']->get(IL_CAL_UNIX) > $right['start']->get(IL_CAL_UNIX)) {
253  return 1;
254  }
255 
256  return strcmp($left['title'], $right['title']);
257  });
258 
259  uasort($groups['ongoing'], function ($left, $right) {
260  if ($left['start']->get(IL_CAL_UNIX) < $right['start']->get(IL_CAL_UNIX)) {
261  return 1;
262  } elseif ($left['start']->get(IL_CAL_UNIX) > $right['start']->get(IL_CAL_UNIX)) {
263  return -1;
264  }
265 
266  return strcmp($left['title'], $right['title']);
267  });
268 
269  uasort($groups['ended'], function ($left, $right) {
270  if ($left['start']->get(IL_CAL_UNIX) < $right['start']->get(IL_CAL_UNIX)) {
271  return 1;
272  } elseif ($left['start']->get(IL_CAL_UNIX) > $right['start']->get(IL_CAL_UNIX)) {
273  return -1;
274  }
275 
276  return strcmp($left['title'], $right['title']);
277  });
278 
279  uasort($groups['not_dated'], function ($left, $right) {
280  return strcmp($left['title'], $right['title']);
281  });
282 
283  $upcoming = new ilPDSelectedItemsBlockGroup();
284  $upcoming->setLabel($this->lng->txt('pd_upcoming'));
285  $upcoming->setItems($groups['upcoming']);
286 
287  $ongoing = new ilPDSelectedItemsBlockGroup();
288  $ongoing->setLabel($this->lng->txt('pd_ongoing'));
289  $ongoing->setItems($groups['ongoing']);
290 
291  $ended = new ilPDSelectedItemsBlockGroup();
292  $ended->setLabel($this->lng->txt('pd_ended'));
293  $ended->setItems($groups['ended']);
294 
295  $not_dated = new ilPDSelectedItemsBlockGroup();
296  $not_dated->setLabel($this->lng->txt('pd_not_date'));
297  $not_dated->setItems($groups['not_dated']);
298 
299  return array_filter([
300  $upcoming,
301  $ongoing,
302  $ended,
303  $not_dated
304  ], function (ilPDSelectedItemsBlockGroup $group) {
305  return count($group->getItems()) > 0;
306  });
307  }
308 
312  protected function groupItemsByLocation()
313  {
314  $grouped_items = array();
315 
316  $items = $this->provider->getItems();
317 
318  $parent_ref_ids = array_values(array_unique(array_map(function ($item) {
319  return $item['parent_ref'];
320  }, $items)));
321  $this->object_cache->preloadReferenceCache($parent_ref_ids);
322 
323  foreach ($items as $key => $item) {
324  if (!array_key_exists('grp_' . $item['parent_ref'], $grouped_items)) {
325  $group = new ilPDSelectedItemsBlockGroup();
326  /* The parent objects of items grouped by location do not need an image (per current concept), so
327  we do not determine images to reduced the runtime/memory */
328  if ($this->isRootNode($item['parent_ref'])) {
329  $group->setLabel($this->getRepositoryTitle());
330  } else {
331  $group->setLabel($this->object_cache->lookupTitle($this->object_cache->lookupObjId($item['parent_ref'])));
332  }
333  $grouped_items['grp_' . $item['parent_ref']] = $group;
334  }
335 
336  $grouped_items['grp_' . $item['parent_ref']]->pushItem($item);
337  }
338 
339  return $grouped_items;
340  }
341 }
__construct(ilPDSelectedItemsBlockViewSettings $viewSettings, ilPDSelectedItemsBlockProvider $provider)
ilPDSelectedItemsBlockViewGUI constructor.
global $DIC
Definition: saml.php:7
Class ilPDSelectedItemsBlockViewGUI.
static preloadByObjIds(array $a_obj_ids)
Preload list gui data.
Class ilPDSelectedItemsBlockGroup.
const IL_CAL_UNIX
Preloader for object list GUIs.
$nd
Definition: error.php:10
Class for single dates.
static bySettings(ilPDSelectedItemsBlockViewSettings $viewSettings)
Class ilPDSelectedItemsBlockViewSettings.
static getRepoPluginObjectByType($type)
Return either a repoObject plugin or a orgunit extension plugin or null if the type is not a plugin...
Create styles array
The data for the language used.
Interface ilPDSelectedItemsBlockProvider.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
$key
Definition: croninfo.php:18