ILIAS  release_7 Revision v7.30-3-g800a261c036
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
8{
12 protected $viewSettings;
13
17 protected $provider;
18
22 protected $lng;
23
27 protected $tree;
28
32 protected $object_cache;
33
37 protected $accessHandler;
38
40 protected $isInManageMode = false;
41
48 {
49 global $DIC;
50
51 $this->lng = $DIC->language();
52 $this->tree = $DIC->repositoryTree();
53 $this->object_cache = $DIC['ilObjDataCache'];
54 $this->accessHandler = $DIC->rbac()->system();
55
56 $this->viewSettings = $viewSettings;
57 $this->provider = $provider;
58 }
59
63 abstract public function getScreenId();
64
68 abstract public function getTitle();
69
74 {
75 if ($this->viewSettings->isSortedByLocation()) {
76 return 1;
77 }
78
79 return 3;
80 }
81
85 abstract public function supportsSelectAll();
86
90 abstract public function getIntroductionHtml();
91
95 abstract public function getGroups();
96
101 public function mayRemoveItem($refId)
102 {
103 return true;
104 }
105
109 public function setIsInManageMode(bool $isInManageMode)
110 {
112 }
113
117 public function isInManageMode() : bool
118 {
120 }
121
125 public function getItemGroups()
126 {
127 $items_groups = $this->getGroups();
128 $this->preloadItemGroups($items_groups);
129
130 return $items_groups;
131 }
132
138 {
139 if ($viewSettings->isMembershipsViewActive()) {
143 );
144 }
145
149 );
150 }
151
156 protected function isRootNode($refId)
157 {
158 return $this->tree->getRootId() == $refId;
159 }
160
164 protected function getRepositoryTitle()
165 {
166 $nd = $this->tree->getNodeData($this->tree->getRootId());
167 $title = $nd['title'];
168
169 if ($title == 'ILIAS') {
170 $title = $this->lng->txt('repository');
171 }
172
173 return $title;
174 }
175
179 protected function preloadItemGroups(array $item_groups)
180 {
181 require_once 'Services/Object/classes/class.ilObjectListGUIPreloader.php';
183
184 $obj_ids = [];
185 foreach ($item_groups as $item_group) {
186 foreach ($item_group->getItems() as $item) {
187 $obj_ids[] = $item['obj_id'];
188 $listPreloader->addItem($item['obj_id'], $item['type'], $item['ref_id']);
189 }
190 }
191
192 $listPreloader->preload();
194 }
195
199 protected function groupItemsByType()
200 {
201 global $DIC;
202
203 $objDefinition = $DIC["objDefinition"];
204
205 $object_types_by_container = $DIC['objDefinition']->getGroupedRepositoryObjectTypes(array('cat', 'crs', 'grp', 'fold'));
206
207 $grouped_items = array();
208
209 foreach ($object_types_by_container as $container_object_type => $container_data) {
210 $group = new ilPDSelectedItemsBlockGroup();
211 // Icons are currently not determined for section header objects
212 if (!$objDefinition->isPlugin($container_object_type)) {
213 $title = $this->lng->txt('objs_' . $container_object_type);
214 } else {
215 include_once("./Services/Component/classes/class.ilPlugin.php");
216 $pl = ilObjectPlugin::getPluginObjectByType($container_object_type);
217 $title = $pl->txt("objs_" . $container_object_type);
218 }
219
220 $group->setLabel($title);
221 $group->setItems($this->provider->getItems($container_data['objs']));
222
223 $grouped_items[] = $group;
224 }
225
226 return $grouped_items;
227 }
228
232 protected function groupItemsByStartDate()
233 {
234 $items = $this->provider->getItems();
235
236 if (0 == count($items)) {
237 return array();
238 }
239
240 $groups = array(
241 'upcoming' => array(),
242 'ongoing' => array(),
243 'ended' => array(),
244 'not_dated' => array()
245 );
246 foreach ($items as $key => $item) {
247 if ($item['start'] && $item['start']->get(IL_CAL_UNIX) > 0 && $item['start'] instanceof ilDateTime) {
248 if ($item['start']->get(IL_CAL_UNIX) > time()) {
249 $groups['upcoming'][] = $item;
250 } elseif ($item['end']->get(IL_CAL_UNIX) > time()) {
251 $groups['ongoing'][] = $item;
252 } else {
253 $groups['ended'][] = $item;
254 }
255 } else {
256 $groups['not_dated'][] = $item;
257 }
258 }
259
260 uasort($groups['upcoming'], function ($left, $right) {
261 if ($left['start']->get(IL_CAL_UNIX) < $right['start']->get(IL_CAL_UNIX)) {
262 return -1;
263 } elseif ($left['start']->get(IL_CAL_UNIX) > $right['start']->get(IL_CAL_UNIX)) {
264 return 1;
265 }
266
267 return strcmp($left['title'], $right['title']);
268 });
269
270 uasort($groups['ongoing'], function ($left, $right) {
271 if ($left['start']->get(IL_CAL_UNIX) < $right['start']->get(IL_CAL_UNIX)) {
272 return 1;
273 } elseif ($left['start']->get(IL_CAL_UNIX) > $right['start']->get(IL_CAL_UNIX)) {
274 return -1;
275 }
276
277 return strcmp($left['title'], $right['title']);
278 });
279
280 uasort($groups['ended'], function ($left, $right) {
281 if ($left['start']->get(IL_CAL_UNIX) < $right['start']->get(IL_CAL_UNIX)) {
282 return 1;
283 } elseif ($left['start']->get(IL_CAL_UNIX) > $right['start']->get(IL_CAL_UNIX)) {
284 return -1;
285 }
286
287 return strcmp($left['title'], $right['title']);
288 });
289
290 uasort($groups['not_dated'], function ($left, $right) {
291 return strcmp($left['title'], $right['title']);
292 });
293
294 $upcoming = new ilPDSelectedItemsBlockGroup();
295 $upcoming->setLabel($this->lng->txt('pd_upcoming'));
296 $upcoming->setItems($groups['upcoming']);
297
298 $ongoing = new ilPDSelectedItemsBlockGroup();
299 $ongoing->setLabel($this->lng->txt('pd_ongoing'));
300 $ongoing->setItems($groups['ongoing']);
301
302 $ended = new ilPDSelectedItemsBlockGroup();
303 $ended->setLabel($this->lng->txt('pd_ended'));
304 $ended->setItems($groups['ended']);
305
306 $not_dated = new ilPDSelectedItemsBlockGroup();
307 $not_dated->setLabel($this->lng->txt('pd_not_date'));
308 $not_dated->setItems($groups['not_dated']);
309
310 return array_filter([
311 $upcoming,
312 $ongoing,
313 $ended,
314 $not_dated
315 ], function (ilPDSelectedItemsBlockGroup $group) {
316 return count($group->getItems()) > 0;
317 });
318 }
319
323 protected function groupItemsByLocation()
324 {
325 $grouped_items = array();
326
327 $items = $this->provider->getItems();
328
329 $parent_ref_ids = array_values(array_unique(array_map(function ($item) {
330 return $item['parent_ref'];
331 }, $items)));
332 $this->object_cache->preloadReferenceCache($parent_ref_ids);
333
334 foreach ($items as $key => $item) {
335 if (!array_key_exists('grp_' . $item['parent_ref'], $grouped_items)) {
336 $group = new ilPDSelectedItemsBlockGroup();
337 /* The parent objects of items grouped by location do not need an image (per current concept), so
338 we do not determine images to reduced the runtime/memory */
339 if ($this->isRootNode($item['parent_ref'])) {
340 $group->setLabel($this->getRepositoryTitle());
341 } else {
342 $group->setLabel($this->object_cache->lookupTitle($this->object_cache->lookupObjId($item['parent_ref'])));
343 }
344 $grouped_items['grp_' . $item['parent_ref']] = $group;
345 }
346
347 $grouped_items['grp_' . $item['parent_ref']]->pushItem($item);
348 }
349
350 return $grouped_items;
351 }
352}
An exception for terminatinating execution or to throw for unit testing.
const IL_CAL_UNIX
static preloadByObjIds(array $a_obj_ids)
Preload list gui data.
@classDescription Date and time handling
Preloader for object list GUIs.
static getPluginObjectByType($type)
Return either a repoObject plugin or a orgunit extension plugin or null if the type is not a plugin.
Class ilPDSelectedItemsBlockGroup.
Class ilPDSelectedItemsBlockViewGUI.
__construct(ilPDSelectedItemsBlockViewSettings $viewSettings, ilPDSelectedItemsBlockProvider $provider)
ilPDSelectedItemsBlockViewGUI constructor.
static bySettings(ilPDSelectedItemsBlockViewSettings $viewSettings)
$nd
Definition: error.php:12
global $DIC
Definition: goto.php:24
Interface ilPDSelectedItemsBlockProvider.
$refId
Definition: xapitoken.php:40