ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPDSelectedItemsBlockViewGUI.php
Go to the documentation of this file.
1 <?php
2 
20 {
23  protected ilLanguage $lng;
24  protected ilTree $tree;
27  protected bool $isInManageMode = false;
28 
30  {
31  global $DIC;
32 
33  $this->lng = $DIC->language();
34  $this->tree = $DIC->repositoryTree();
35  $this->object_cache = $DIC['ilObjDataCache'];
36  $this->accessHandler = $DIC->rbac()->system();
37 
38  $this->viewSettings = $viewSettings;
39  $this->provider = $provider;
40  }
41 
42  abstract public function getScreenId(): string;
43 
44  abstract public function getTitle(): string;
45 
46  abstract public function supportsSelectAll(): bool;
47 
48  abstract public function getIntroductionHtml(): string;
49 
53  abstract public function getGroups(): array;
54 
55  public function mayRemoveItem(int $refId): bool
56  {
57  return true;
58  }
59 
60  public function setIsInManageMode(bool $isInManageMode): void
61  {
63  }
64 
65  public function isInManageMode(): bool
66  {
67  return $this->isInManageMode;
68  }
69 
73  public function getItemGroups(): array
74  {
75  $items_groups = $this->getGroups();
76  $this->preloadItemGroups($items_groups);
77 
78  return $items_groups;
79  }
80 
82  {
83  if ($viewSettings->isMembershipsViewActive()) {
85  $viewSettings,
87  );
88  }
89 
91  $viewSettings,
93  );
94  }
95 
96  protected function isRootNode(int $refId): bool
97  {
98  return $this->tree->getRootId() == $refId;
99  }
100 
101  protected function getRepositoryTitle(): string
102  {
103  $nd = $this->tree->getNodeData($this->tree->getRootId());
104  $title = $nd['title'];
105 
106  if ($title == 'ILIAS') {
107  $title = $this->lng->txt('repository');
108  }
109 
110  return $title;
111  }
112 
116  protected function preloadItemGroups(array $item_groups)
117  {
119 
120  $obj_ids = [];
121  foreach ($item_groups as $item_group) {
122  foreach ($item_group->getItems() as $item) {
123  $obj_ids[] = (int) $item['obj_id'];
124  $listPreloader->addItem($item['obj_id'], $item['type'], $item['ref_id']);
125  }
126  }
127 
128  $listPreloader->preload();
130  }
131 
135  protected function groupItemsByType(): array
136  {
137  global $DIC;
138 
139  $objDefinition = $DIC["objDefinition"];
140 
141  $object_types_by_container = $DIC['objDefinition']->getGroupedRepositoryObjectTypes(array('cat', 'crs', 'grp', 'fold'));
142 
143  $grouped_items = array();
144 
145  foreach ($object_types_by_container as $container_object_type => $container_data) {
146  $group = new ilPDSelectedItemsBlockGroup();
147  // Icons are currently not determined for section header objects
148  if (!$objDefinition->isPlugin($container_object_type)) {
149  $title = $this->lng->txt('objs_' . $container_object_type);
150  } else {
151  $pl = ilObjectPlugin::getPluginObjectByType($container_object_type);
152  $title = $pl->txt("objs_" . $container_object_type);
153  }
154 
155  $group->setLabel($title);
156  $group->setItems($this->provider->getItems($container_data['objs']));
157 
158  $grouped_items[] = $group;
159  }
160 
161  return $grouped_items;
162  }
163 
167  protected function groupItemsByStartDate(): array
168  {
169  $items = $this->provider->getItems();
170 
171  if (0 == count($items)) {
172  return array();
173  }
174 
175  $groups = array(
176  'upcoming' => array(),
177  'ongoing' => array(),
178  'ended' => array(),
179  'not_dated' => array()
180  );
181  foreach ($items as $key => $item) {
182  if ($item['start'] && $item['start']->get(IL_CAL_UNIX) > 0 && $item['start'] instanceof ilDateTime) {
183  if ($item['start']->get(IL_CAL_UNIX) > time()) {
184  $groups['upcoming'][] = $item;
185  } elseif ($item['end']->get(IL_CAL_UNIX) > time()) {
186  $groups['ongoing'][] = $item;
187  } else {
188  $groups['ended'][] = $item;
189  }
190  } else {
191  $groups['not_dated'][] = $item;
192  }
193  }
194 
195  uasort($groups['upcoming'], function ($left, $right) {
196  if ($left['start']->get(IL_CAL_UNIX) < $right['start']->get(IL_CAL_UNIX)) {
197  return -1;
198  } elseif ($left['start']->get(IL_CAL_UNIX) > $right['start']->get(IL_CAL_UNIX)) {
199  return 1;
200  }
201 
202  return strcmp($left['title'], $right['title']);
203  });
204 
205  uasort($groups['ongoing'], function ($left, $right) {
206  if ($left['start']->get(IL_CAL_UNIX) < $right['start']->get(IL_CAL_UNIX)) {
207  return 1;
208  } elseif ($left['start']->get(IL_CAL_UNIX) > $right['start']->get(IL_CAL_UNIX)) {
209  return -1;
210  }
211 
212  return strcmp($left['title'], $right['title']);
213  });
214 
215  uasort($groups['ended'], function ($left, $right) {
216  if ($left['start']->get(IL_CAL_UNIX) < $right['start']->get(IL_CAL_UNIX)) {
217  return 1;
218  } elseif ($left['start']->get(IL_CAL_UNIX) > $right['start']->get(IL_CAL_UNIX)) {
219  return -1;
220  }
221 
222  return strcmp($left['title'], $right['title']);
223  });
224 
225  uasort($groups['not_dated'], function ($left, $right) {
226  return strcmp($left['title'], $right['title']);
227  });
228 
229  $upcoming = new ilPDSelectedItemsBlockGroup();
230  $upcoming->setLabel($this->lng->txt('pd_upcoming'));
231  $upcoming->setItems($groups['upcoming']);
232 
233  $ongoing = new ilPDSelectedItemsBlockGroup();
234  $ongoing->setLabel($this->lng->txt('pd_ongoing'));
235  $ongoing->setItems($groups['ongoing']);
236 
237  $ended = new ilPDSelectedItemsBlockGroup();
238  $ended->setLabel($this->lng->txt('pd_ended'));
239  $ended->setItems($groups['ended']);
240 
241  $not_dated = new ilPDSelectedItemsBlockGroup();
242  $not_dated->setLabel($this->lng->txt('pd_not_date'));
243  $not_dated->setItems($groups['not_dated']);
244 
245  return array_filter([
246  $upcoming,
247  $ongoing,
248  $ended,
249  $not_dated
250  ], function (ilPDSelectedItemsBlockGroup $group) {
251  return count($group->getItems()) > 0;
252  });
253  }
254 
258  protected function groupItemsByLocation(): array
259  {
260  $grouped_items = array();
261 
262  $items = $this->provider->getItems();
263 
264  $parent_ref_ids = array_values(array_unique(array_map(function ($item) {
265  return $item['parent_ref'];
266  }, $items)));
267  $this->object_cache->preloadReferenceCache($parent_ref_ids);
268 
269  foreach ($items as $key => $item) {
270  if (!array_key_exists('grp_' . $item['parent_ref'], $grouped_items)) {
271  $group = new ilPDSelectedItemsBlockGroup();
272  /* The parent objects of items grouped by location do not need an image (per current concept), so
273  we do not determine images to reduced the runtime/memory */
274  if ($this->isRootNode($item['parent_ref'])) {
275  $group->setLabel($this->getRepositoryTitle());
276  } else {
277  $group->setLabel($this->object_cache->lookupTitle($this->object_cache->lookupObjId((int) $item['parent_ref'])));
278  }
279  $grouped_items['grp_' . $item['parent_ref']] = $group;
280  }
281 
282  $grouped_items['grp_' . $item['parent_ref']]->pushItem($item);
283  }
284 
285  return $grouped_items;
286  }
287 
291  protected function sortItemsByAlphabetInOneGroup(): array
292  {
293  $items = array_values($this->provider->getItems());
294 
295  usort($items, static function (array $first, array $second): int {
296  return strnatcmp(strtolower($first['title']), strtolower($second['title']));
297  });
298 
299  $group = new ilPDSelectedItemsBlockGroup();
300  array_map([$group, 'pushItem'], $items);
301 
302  return [$group];
303  }
304 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilPDSelectedItemsBlockViewSettings $viewSettings, ilPDSelectedItemsBlockProvider $provider)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static preloadByObjIds(array $a_obj_ids)
Preload list gui data.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilPDSelectedItemsBlockViewSettings $viewSettings
$refId
Definition: xapitoken.php:58
const IL_CAL_UNIX
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$nd
Definition: error.php:12
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static bySettings(ilPDSelectedItemsBlockViewSettings $viewSettings)
string $key
Consumer key/client ID value.
Definition: System.php:193
static getPluginObjectByType(string $type)
Return either a repoObject plugin or a orgunit extension plugin or null if the type is not a plugin...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...