ILIAS  release_8 Revision v8.24
class.ilPDSelectedItemsBlockGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27
33{
34 protected bool $new_rendering = true;
39 public static string $block_type = 'pditems';
42 protected bool $manage = false;
43 protected string $content = '';
44 protected ilLanguage $lng;
45 protected ilCtrl $ctrl;
46 protected ilObjUser $user;
47 protected Services $http;
48 protected Factory $refinery;
51 protected ilTree $tree;
53 protected ilLogger $logging;
54
55 public function __construct()
56 {
58 global $DIC;
59
60 $this->rbacsystem = $DIC->rbac()->system();
61 $this->settings = $DIC->settings();
62 $this->obj_definition = $DIC["objDefinition"];
63 $this->access = $DIC->access();
64 $this->ui = $DIC->ui();
65 $this->http = $DIC->http();
66 $this->refinery = $DIC->refinery();
67 $this->objectService = $DIC->object();
68 $this->favourites = new ilFavouritesManager();
69 $this->tree = $DIC->repositoryTree();
70 $this->logging = $DIC->logger()->root();
71
73
74 $this->lng = $DIC->language();
75 $this->ctrl = $DIC->ctrl();
76 $this->user = $DIC->user();
77
78 $this->lng->loadLanguageModule('pd');
79 $this->lng->loadLanguageModule('cntr');
80 $this->lng->loadLanguageModule('rep');
81
82 $this->setEnableNumInfo(false);
83 $this->setLimit(99999);
84 $this->allow_moving = false;
85
86 $this->initViewSettings();
87 $this->list_factory = new ilPDSelectedItemsBlockListGUIFactory($this, $this->blockView);
88
89 if ($this->viewSettings->isTilePresentation()) {
90 $this->setPresentation(self::PRES_MAIN_LEG);
91 } else {
92 $this->setPresentation(self::PRES_MAIN_LIST);
93 }
94
95 $params = $DIC->http()->request()->getQueryParams();
96 $this->requested_item_ref_id = (int) ($params["item_ref_id"] ?? 0);
97 }
98
99 protected function initViewSettings(): void
100 {
101 $this->viewSettings = new ilPDSelectedItemsBlockViewSettings(
102 $this->user,
104 );
105
106 $this->viewSettings->parse();
107
108 $this->blockView = ilPDSelectedItemsBlockViewGUI::bySettings($this->viewSettings);
109
110 $this->ctrl->setParameter($this, 'view', $this->viewSettings->getCurrentView());
111 }
112
114 {
115 return $this->viewSettings;
116 }
117
118 public function addToDeskObject(): void
119 {
120 $this->favourites->add($this->user->getId(), $this->requested_item_ref_id);
121 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt("rep_added_to_favourites"), true);
122 $this->returnToContext();
123 }
124
125 protected function returnToContext(): void
126 {
127 $this->ctrl->setParameterByClass('ildashboardgui', 'view', $this->viewSettings->getCurrentView());
128 $this->ctrl->redirectByClass('ildashboardgui', 'show');
129 }
130
131 public function removeFromDeskObject(): void
132 {
133 $this->lng->loadLanguageModule("rep");
134 $this->favourites->remove($this->user->getId(), $this->requested_item_ref_id);
135 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt("rep_removed_from_favourites"), true);
136 $this->returnToContext();
137 }
138
139 public function getBlockType(): string
140 {
141 return static::$block_type;
142 }
143
144 protected function isRepositoryObject(): bool
145 {
146 return false;
147 }
148
149 protected function getViewTitle(): string
150 {
151 return $this->blockView->getTitle();
152 }
153
154 public function getHTML(): string
155 {
156 global $DIC;
157
158 $this->setTitle($this->getViewTitle());
159
160 $DIC->database()->useSlave(true);
161
162 $this->setData([['dummy']]);
163
164 $DIC['ilHelp']->setDefaultScreenId(ilHelpGUI::ID_PART_SCREEN, $this->blockView->getScreenId());
165
166 $this->ctrl->clearParameters($this);
167
168 $DIC->database()->useSlave(false);
169
170 return parent::getHTML();
171 }
172
173 public function executeCommand(): string
174 {
175 $next_class = $this->ctrl->getNextClass();
176 $cmd = $this->ctrl->getCmd('getHTML');
177
178 switch ($next_class) {
179 case 'ilcommonactiondispatchergui':
181 $this->ctrl->forwardCommand($gui);
182 break;
183
184 default:
185 if (method_exists($this, $cmd)) {
186 return $this->$cmd();
187 }
188 return $this->{$cmd . 'Object'}();
189 }
190 return "";
191 }
192
193 protected function getContent(): string
194 {
195 return $this->content;
196 }
197
198 protected function setContent(string $a_content): void
199 {
200 $this->content = $a_content;
201 }
202
203 public function fillDataSection(): void
204 {
205 if ($this->getContent() === '') {
206 $this->setDataSection($this->blockView->getIntroductionHtml());
207 } else {
208 $this->tpl->setVariable('BLOCK_ROW', $this->getContent());
209 }
210 }
211
212 protected function getGroupedCommandsForView(
213 bool $manage = false
214 ): array {
215 $commandGroups = [];
216
217 $sortingCommands = [];
218 $sortings = $this->viewSettings->getSelectableSortingModes();
219 $effectiveSorting = $this->viewSettings->getEffectiveSortingMode();
220 foreach ($sortings as $sorting) {
221 $this->ctrl->setParameter($this, 'sorting', $sorting);
222 $sortingCommands[] = [
223 'txt' => $this->lng->txt('dash_sort_by_' . $sorting),
224 'url' => $this->ctrl->getLinkTarget($this, 'changePDItemSorting'),
225 'xxxasyncUrl' => $this->ctrl->getLinkTarget($this, 'changePDItemSorting', '', true),
226 'active' => $sorting === $effectiveSorting,
227 ];
228 $this->ctrl->setParameter($this, 'sorting', null);
229 }
230
231 if (count($sortingCommands) > 1) {
232 $commandGroups[] = $sortingCommands;
233 }
234
235 if ($manage) {
236 return $commandGroups;
237 }
238
239 $presentationCommands = [];
240 $presentations = $this->viewSettings->getSelectablePresentationModes();
241 $effectivePresentation = $this->viewSettings->getEffectivePresentationMode();
242 foreach ($presentations as $presentation) {
243 $this->ctrl->setParameter($this, 'presentation', $presentation);
244 $presentationCommands[] = [
245 'txt' => $this->lng->txt('pd_presentation_mode_' . $presentation),
246 'url' => $this->ctrl->getLinkTarget($this, 'changePDItemPresentation'),
247 'xxxasyncUrl' => $this->ctrl->getLinkTarget($this, 'changePDItemPresentation', '', true),
248 'active' => $presentation === $effectivePresentation,
249 ];
250 $this->ctrl->setParameter($this, 'presentation', null);
251 }
252
253 if (count($presentationCommands) > 1) {
254 $commandGroups[] = $presentationCommands;
255 }
256
257 $commandGroups[] = [
258 [
259 'txt' => $this->viewSettings->isSelectedItemsViewActive() ?
260 $this->lng->txt('pd_remove_multiple') :
261 $this->lng->txt('pd_unsubscribe_multiple_memberships'),
262 'url' => $this->ctrl->getLinkTarget($this, 'manage'),
263 'asyncUrl' => null,
264 'active' => false,
265 ]
266 ];
267
268 return $commandGroups;
269 }
270
271 public function changePDItemPresentation(): void
272 {
273 $this->viewSettings->storeActorPresentationMode(
274 ilUtil::stripSlashes((string) ($this->http->request()->getQueryParams()['presentation'] ?? ''))
275 );
276 $this->initAndShow();
277 }
278
279 public function changePDItemSorting(): void
280 {
281 $this->viewSettings->storeActorSortingMode(
282 ilUtil::stripSlashes((string) ($this->http->request()->getQueryParams()['sorting'] ?? ''))
283 );
284
285 $this->initAndShow();
286 }
287
288 protected function initAndShow(): void
289 {
290 $this->initViewSettings();
291
292 if ($this->ctrl->isAsynch()) {
293 echo $this->getHTML();
294 exit;
295 }
296
297 $this->returnToContext();
298 }
299
300 public function manageObject(): string
301 {
302 $this->blockView->setIsInManageMode(true);
303
304 $top_tb = new ilToolbarGUI();
305 $top_tb->setFormAction($this->ctrl->getFormAction($this));
306 $top_tb->setLeadingImage(ilUtil::getImagePath('arrow_upright.svg'), $this->lng->txt('actions'));
307
308 $button = ilSubmitButton::getInstance();
309 $grouped_items = $this->blockView->getItemGroups();
310 if ($this->viewSettings->isSelectedItemsViewActive()) {
311 $button->setCaption('remove');
312 } else {
313 $button->setCaption('pd_unsubscribe_memberships');
314 foreach ($grouped_items as $group) {
315 $items = $group->getItems();
316 $group->setItems([]);
317 foreach ($items as $item) {
318 if ($this->rbacsystem->checkAccess('leave', $item['ref_id'])) {
319 if (
320 $item['type'] !== 'crs' ||
321 ilParticipants::getInstance($item['ref_id'])->checkLastAdmin([$this->user->getId()])
322 ) {
323 $group->pushItem($item);
324 }
325 }
326 }
327 }
328 }
329 $button->setCommand('confirmRemove');
330 $top_tb->addStickyItem($button);
331
332 $top_tb->setCloseFormTag(false);
333
334 $bot_tb = new ilToolbarGUI();
335 $bot_tb->setLeadingImage(ilUtil::getImagePath('arrow_downright.svg'), $this->lng->txt('actions'));
336 $bot_tb->addStickyItem($button);
337 $bot_tb->setOpenFormTag(false);
338
339 return $top_tb->getHTML() . $this->renderManageList($grouped_items) . $bot_tb->getHTML();
340 }
341
342 protected function cancel(): void
343 {
344 $this->ctrl->returnToParent($this);
345 }
346
347 public function confirmRemoveObject(): string
348 {
349 $this->ctrl->setParameter($this, 'view', $this->viewSettings->getCurrentView());
350
351 $refIds = (array) ($this->http->request()->getParsedBody()['id'] ?? []);
352 if (0 === count($refIds)) {
353 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('select_one'), true);
354 $this->ctrl->redirect($this, 'manage');
355 }
356
357 if ($this->viewSettings->isSelectedItemsViewActive()) {
358 $question = $this->lng->txt('dash_info_sure_remove_from_favs');
359 $cmd = 'confirmedRemove';
360 } else {
361 $question = $this->lng->txt('mmbr_info_delete_sure_unsubscribe');
362 $cmd = 'confirmedUnsubscribe';
363 }
364
365 $cgui = new ilConfirmationGUI();
366 $cgui->setHeaderText($question);
367
368 $cgui->setFormAction($this->ctrl->getFormAction($this));
369 $cgui->setCancel($this->lng->txt('cancel'), 'manage');
370 $cgui->setConfirm($this->lng->txt('confirm'), $cmd);
371
372 foreach ($refIds as $ref_id) {
373 $obj_id = ilObject::_lookupObjectId((int) $ref_id);
374 $title = ilObject::_lookupTitle($obj_id);
375 $type = ilObject::_lookupType($obj_id);
376
377 $cgui->addItem(
378 'ref_id[]',
379 $ref_id,
380 $title,
381 ilObject::_getIcon($obj_id, 'small', $type),
382 $this->lng->txt('icon') . ' ' . $this->lng->txt('obj_' . $type)
383 );
384 }
385
386 return $cgui->getHTML();
387 }
388
389 public function confirmedRemove(): void
390 {
391 $refIds = (array) ($this->http->request()->getParsedBody()['ref_id'] ?? []);
392 if (0 === count($refIds)) {
393 $this->ctrl->redirect($this, 'manage');
394 }
395
396 foreach ($refIds as $ref_id) {
397 $this->favourites->remove($this->user->getId(), (int) $ref_id);
398 }
399
400 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('pd_remove_multi_confirm'), true);
401 $this->ctrl->redirect($this, 'manage');
402 }
403
404 public function confirmedUnsubscribe(): void
405 {
406 $refIds = $this->http->wrapper()->post()->retrieve(
407 'ref_id',
408 $this->refinery->to()->listOf($this->refinery->kindlyTo()->int())
409 );
410 if (0 === count($refIds)) {
411 $this->ctrl->redirect($this, 'manage');
412 }
413
414 foreach ($refIds as $ref_id) {
415 if ($this->access->checkAccess('leave', '', (int) $ref_id)) {
416 switch (ilObject::_lookupType($ref_id, true)) {
417 case 'crs':
419 $members->delete($this->user->getId());
420
421 $members->sendUnsubscribeNotificationToAdmins($this->user->getId());
422 $members->sendNotification(
424 $this->user->getId()
425 );
426 break;
427
428 case 'grp':
430 $members->delete($this->user->getId());
431
432 $members->sendNotification(
434 $this->user->getId()
435 );
436 $members->sendNotification(
438 $this->user->getId()
439 );
440 break;
441
442 default:
443 continue 2;
444 }
445
446 ilForumNotification::checkForumsExistsDelete($ref_id, $this->user->getId());
447 }
448 }
449
450 $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('mmbr_unsubscribed_from_objs'), true);
451 $this->ctrl->returnToParent($this);
452 }
453
457 protected function getListItemGroups(): array
458 {
459 $groupedItems = $this->blockView->getItemGroups();
460 $groupedCommands = $this->getGroupedCommandsForView();
461 foreach ($groupedCommands as $group) {
462 foreach ($group as $command) {
463 $asynch_url = $command['asyncUrl'] ?? "";
464 $this->addBlockCommand(
465 (string) $command['url'],
466 (string) $command['txt'],
467 (string) $asynch_url
468 );
469 }
470 }
471
472 $item_groups = [];
473 $list_items = [];
474
475 foreach ($groupedItems as $group) {
476 $list_items = [];
477
478 foreach ($group->getItems() as $item) {
479 try {
480 $itemListGUI = $this->list_factory->byType($item['type']);
482
483 $list_items[] = $this->getListItemForData($item);
484 } catch (ilException $e) {
485 $this->logging->warning('Listing failed for item with ID ' . $item['obj_id'] . ': ' . $e->getMessage());
486 continue;
487 }
488 }
489 if (count($list_items) > 0) {
490 $item_groups[] = $this->ui->factory()->item()->group($group->getLabel(), $list_items);
491 }
492 }
493
494 return $item_groups;
495 }
496
497 protected function getListItemForData(array $data): ?Item
498 {
499 $itemListGui = $this->list_factory->byType($data['type']);
501
502 $list_item = $itemListGui->getAsListItem(
503 (int) $data['ref_id'],
504 (int) $data['obj_id'],
505 (string) $data['type'],
506 (string) $data['title'],
507 (string) $data['description']
508 );
509
510 return $list_item;
511 }
512
513 protected function getCardForData(array $item): RepositoryObject
514 {
515 $itemListGui = $this->list_factory->byType($item['type']);
517
518 $card = $itemListGui->getAsCard(
519 (int) $item['ref_id'],
520 (int) $item['obj_id'],
521 (string) $item['type'],
522 (string) $item['title'],
523 (string) $item['description']
524 );
525
526 return $card;
527 }
528
529 protected function getLegacyContent(): string
530 {
531 $groupedCommands = $this->getGroupedCommandsForView();
532 foreach ($groupedCommands as $group) {
533 foreach ($group as $command) {
534 $asynch_url = $command['asyncUrl'] ?? "";
535 $this->addBlockCommand(
536 (string) $command['url'],
537 (string) $command['txt'],
538 (string) $asynch_url
539 );
540 }
541 }
542
543 $groupedItems = $this->blockView->getItemGroups();
544
545 $subs = [];
546 foreach ($groupedItems as $group) {
547 $cards = [];
548
549 foreach ($group->getItems() as $item) {
550 try {
551 $cards[] = $this->getCardForData($item);
552 } catch (ilException $e) {
553 $this->logging->warning('Listing failed for item with ID ' . $item['obj_id'] . ': ' . $e->getMessage());
554 continue;
555 }
556 }
557 if (count($cards) > 0) {
558 $subs[] = $this->ui->factory()->panel()->sub(
559 $group->getLabel(),
560 $this->ui->factory()->deck($cards)->withNormalCardsSize()
561 );
562 }
563 }
564
565 if (count($subs) > 0) {
566 return $this->ui->renderer()->render($subs);
567 }
568
569 return $this->getNoItemFoundContent();
570 }
571
572 protected function renderManageList(array $grouped_items): string
573 {
574 $ui = $this->ui;
575
576 $this->ctrl->setParameter($this, "manage", "1");
577 $groupedCommands = $this->getGroupedCommandsForView(true);
578 foreach ($groupedCommands as $group) {
579 foreach ($group as $command) {
580 $this->addBlockCommand(
581 (string) $command['url'],
582 (string) $command['txt'],
583 (string) ($command['asyncUrl'] ?? "")
584 );
585 }
586 }
587
588 if (is_array($groupedCommands[0])) {
589 $actions = array_map(static function ($item) use ($ui) {
590 return $ui->factory()->link()->standard($item["txt"], $item["url"]);
591 }, $groupedCommands[0]);
592 if (count($actions) > 0) {
593 $dd = $this->ui->factory()->dropdown()->standard($actions);
594 $this->main_tpl->setHeaderActionMenu($ui->renderer()->render($dd));
595 }
596 }
597
598 return (new ilDashObjectsTableRenderer($this))->render($grouped_items);
599 }
600
601 public function getNoItemFoundContent(): string
602 {
603 $txt = $this->lng->txt("rep_fav_intro1") . "<br>";
604 $txt .= sprintf(
605 $this->lng->txt('rep_fav_intro2'),
606 $this->getRepositoryTitle()
607 ) . "<br>";
608 $txt .= $this->lng->txt("rep_fav_intro3");
609 $mbox = $this->ui->factory()->messageBox()->info($txt);
610 $mbox = $mbox->withLinks([$this->ui->factory()->link()->standard($this->getRepositoryTitle(), ilLink::_getStaticLink(1, 'root', true))]);
611 return $this->ui->renderer()->render($mbox);
612 }
613
614 protected function getRepositoryTitle(): string
615 {
616 $nd = $this->tree->getNodeData($this->tree->getRootId());
617 $title = $nd['title'];
618
619 if ($title === 'ILIAS') {
620 $title = $this->lng->txt('repository');
621 }
622
623 return $title;
624 }
625}
Customizing of pimple-DIC for ILIAS.
Definition: Container.php:32
Builds data types.
Definition: Factory.php:21
Class Services.
Definition: Services.php:38
This class represents a block method of a block.
setData(array $a_data)
setDataSection(string $a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
setTitle(string $a_title)
setPresentation(int $type)
setLimit(int $a_limit)
setEnableNumInfo(bool $a_enablenuminfo)
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilCtrl provides processing control methods.
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...
static checkForumsExistsDelete(int $ref_id, int $user_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const ID_PART_SCREEN
language handling
Component logger with individual log levels by component id.
User class.
static addListGUIActivationProperty(ilObjectListGUI $list_gui, array &$item)
Get timing details for list gui.
parses the objects.xml it handles the xml-description of all ilias objects
static _lookupObjectId(int $ref_id)
static _lookupType(int $id, bool $reference=false)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
@ilCtrl_IsCalledBy ilPDSelectedItemsBlockGUI: ilColumnGUI @ilCtrl_Calls ilPDSelectedItemsBlockGUI: il...
removeFromDeskObject()
Remove from desktop @access public.
ilPDSelectedItemsBlockViewGUI $blockView
getListItemForData(array $data)
Get list item for data array.
fillDataSection()
Standard implementation for row based data.
ilPDSelectedItemsBlockViewSettings $viewSettings
isRepositoryObject()
Returns whether block has a corresponding repository object.
ilPDSelectedItemsBlockListGUIFactory $list_factory
addToDeskObject()
Add desktop item @access public.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static bySettings(ilPDSelectedItemsBlockViewSettings $viewSettings)
static getInstance(int $a_ref_id)
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
$nd
Definition: error.php:12
$txt
Definition: error.php:13
global $DIC
Definition: feed.php:28
Common interface to all items.
Definition: Item.php:32
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
exit
Definition: login.php:28
$ref_id
Definition: ltiauth.php:67
if(! $DIC->user() ->getId()||!ilLTIConsumerAccess::hasCustomProviderCreationAccess()) $params
Definition: ltiregstart.php:33
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
standard()
This is an example, of how the Notification Slate is generated by assigning Notification Items to it.
Definition: standard.php:16
$type