ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilPDSelectedItemsBlockGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
27 
33 {
35  protected $new_rendering = true;
36 
38  protected $rbacsystem;
39 
41  protected $settings;
42 
44  protected $obj_definition;
45 
47  public static $block_type = 'pditems';
48 
50  protected $viewSettings;
51 
53  protected $blockView;
54 
56  protected $manage = false;
57 
59  protected $content = '';
60 
62  protected $lng;
63 
65  protected $ctrl;
66 
68  protected $user;
69 
71  protected $ui;
72 
74  protected $http;
75 
77  protected $objectService;
78 
80  protected $favourites;
81 
83  protected $tree;
84 
86  protected $list_factory;
87 
89  protected $logging;
90 
91  public function __construct()
92  {
93  global $DIC;
94 
95  $this->rbacsystem = $DIC->rbac()->system();
96  $this->settings = $DIC->settings();
97  $this->obj_definition = $DIC["objDefinition"];
98  $this->access = $DIC->access();
99  $this->ui = $DIC->ui();
100  $this->http = $DIC->http();
101  $this->objectService = $DIC->object();
102  $this->favourites = new ilFavouritesManager();
103  $this->tree = $DIC->repositoryTree();
104  $this->logging = $DIC->logger()->root();
105 
107 
108  $this->lng = $DIC->language();
109  $this->ctrl = $DIC->ctrl();
110  $this->user = $DIC->user();
111 
112  $this->lng->loadLanguageModule('pd');
113  $this->lng->loadLanguageModule('cntr'); // #14158
114  $this->lng->loadLanguageModule('rep'); // #14158
115 
116  $this->setEnableNumInfo(false);
117  $this->setLimit(99999);
118  $this->allow_moving = false;
119 
120  $this->initViewSettings();
121  $this->list_factory = new ilPDSelectedItemsBlockListGUIFactory($this, $this->blockView);
122 
123  if ($this->viewSettings->isTilePresentation()) {
124  $this->setPresentation(self::PRES_MAIN_LEG);
125  } else {
126  $this->setPresentation(self::PRES_MAIN_LIST);
127  }
128  }
129 
130  protected function initViewSettings()
131  {
132  $this->viewSettings = new ilPDSelectedItemsBlockViewSettings(
133  $this->user,
135  );
136 
137  $this->viewSettings->parse();
138 
139  $this->blockView = ilPDSelectedItemsBlockViewGUI::bySettings($this->viewSettings);
140 
141  $this->ctrl->setParameter($this, 'view', $this->viewSettings->getCurrentView());
142  }
143 
145  {
146  return $this->viewSettings;
147  }
148 
152  public function addToDeskObject()
153  {
154  $this->favourites->add($this->user->getId(), (int) $_GET["item_ref_id"]);
155  ilUtil::sendSuccess($this->lng->txt("rep_added_to_favourites"), true);
156  $this->returnToContext();
157  }
158 
162  protected function returnToContext()
163  {
164  $this->ctrl->setParameterByClass('ildashboardgui', 'view', $this->viewSettings->getCurrentView());
165  $this->ctrl->redirectByClass('ildashboardgui', 'show');
166  }
167 
171  public function removeFromDeskObject()
172  {
173  $this->lng->loadLanguageModule("rep");
174  $this->favourites->remove($this->user->getId(), (int) $_GET["item_ref_id"]);
175  ilUtil::sendSuccess($this->lng->txt("rep_removed_from_favourites"), true);
176  $this->returnToContext();
177  }
178 
182  public function getBlockType(): string
183  {
184  return static::$block_type;
185  }
186 
190  public static function getScreenMode()
191  {
192  $cmd = $_GET['cmd'];
193  if ($cmd === 'post') {
194  global $DIC;
195  $cmd = key($DIC->http()->request()->getParsedBody()['cmd']);
196  }
197 
198  switch ($cmd) {
199  case 'confirmRemove':
200  case 'manage':
201  return IL_SCREEN_FULL;
202 
203  default:
204  return IL_SCREEN_SIDE;
205  }
206  }
207 
211  protected function isRepositoryObject(): bool
212  {
213  return false;
214  }
215 
219  protected function getViewTitle()
220  {
221  return $this->blockView->getTitle();
222  }
223 
227  public function getHTML()
228  {
229  global $DIC;
230 
231  $this->setTitle($this->getViewTitle());
232  $DIC->database()->useSlave(true);
233  $this->setData([['dummy']]);
234  $DIC['ilHelp']->setDefaultScreenId(ilHelpGUI::ID_PART_SCREEN, $this->blockView->getScreenId());
235  $this->ctrl->clearParameters($this);
236  $DIC->database()->useSlave(false);
237 
238  return parent::getHTML();
239  }
240 
241  public function executeCommand()
242  {
243  $next_class = $this->ctrl->getNextClass();
244  $cmd = $this->ctrl->getCmd('getHTML');
245 
246  switch ($next_class) {
247  case 'ilcommonactiondispatchergui':
248  include_once('Services/Object/classes/class.ilCommonActionDispatcherGUI.php');
250  $this->ctrl->forwardCommand($gui);
251  break;
252 
253  default:
254  if (method_exists($this, $cmd)) {
255  return $this->$cmd();
256  } else {
257  return $this->{$cmd . 'Object'}();
258  }
259  }
260  }
261 
262  protected function getContent(): string
263  {
264  return $this->content;
265  }
266 
267  protected function setContent(string $a_content)
268  {
269  $this->content = $a_content;
270  }
271 
275  public function fillDataSection()
276  {
277  if ($this->getContent() === '') {
278  $this->setDataSection($this->blockView->getIntroductionHtml());
279  } else {
280  $this->tpl->setVariable('BLOCK_ROW', $this->getContent());
281  }
282  }
283 
284 
288  public function fillFooter(): void
289  {
290  }
291 
292  protected function getGroupedCommandsForView($manage = false): array
293  {
294  $commandGroups = [];
295 
296  $sortingCommands = [];
297  $sortings = $this->viewSettings->getSelectableSortingModes();
298  $effectiveSorting = $this->viewSettings->getEffectiveSortingMode();
299  foreach ($sortings as $sorting) {
300  $this->ctrl->setParameter($this, 'sorting', $sorting);
301  $sortingCommands[] = [
302  'txt' => $this->lng->txt('dash_sort_by_' . $sorting),
303  'url' => $this->ctrl->getLinkTarget($this, 'changePDItemSorting'),
304  'xxxasyncUrl' => $this->ctrl->getLinkTarget($this, 'changePDItemSorting', '', true),
305  'active' => $sorting === $effectiveSorting,
306  ];
307  $this->ctrl->setParameter($this, 'sorting', null);
308  }
309 
310  if (count($sortingCommands) > 1) {
311  $commandGroups[] = $sortingCommands;
312  }
313 
314  if ($manage) {
315  return $commandGroups;
316  }
317 
318  $presentationCommands = [];
319  $presentations = $this->viewSettings->getSelectablePresentationModes();
320  $effectivePresentation = $this->viewSettings->getEffectivePresentationMode();
321  foreach ($presentations as $presentation) {
322  $this->ctrl->setParameter($this, 'presentation', $presentation);
323  $presentationCommands[] = [
324  'txt' => $this->lng->txt('pd_presentation_mode_' . $presentation),
325  'url' => $this->ctrl->getLinkTarget($this, 'changePDItemPresentation'),
326  'xxxasyncUrl' => $this->ctrl->getLinkTarget($this, 'changePDItemPresentation', '', true),
327  'active' => $presentation === $effectivePresentation,
328  ];
329  $this->ctrl->setParameter($this, 'presentation', null);
330  }
331 
332  if (count($presentationCommands) > 1) {
333  $commandGroups[] = $presentationCommands;
334  }
335 
336  $commandGroups[] = [
337  [
338  'txt' => $this->viewSettings->isSelectedItemsViewActive() ?
339  $this->lng->txt('pd_remove_multiple') :
340  $this->lng->txt('pd_unsubscribe_multiple_memberships'),
341  'url' => $this->ctrl->getLinkTarget($this, 'manage'),
342  'asyncUrl' => null,
343  'active' => false,
344  ]
345  ];
346 
347  return $commandGroups;
348  }
349 
350  protected function setFooterLinks()
351  {
352  if ('' === $this->getContent()) {
353  $this->setEnableNumInfo(false);
354  return;
355  }
356 
357  if ($this->blockView->isInManageMode()) {
358  return;
359  }
360 
361  // @todo: handle $command['active']
362  $groupedCommands = $this->getGroupedCommandsForView();
363  foreach ($groupedCommands as $group) {
364  foreach ($group as $command) {
365  $this->addBlockCommand(
366  $command['url'],
367  $command['txt'],
368  $command['asyncUrl']
369  );
370  }
371  }
372  }
373 
377  protected function renderGroupedItems(array $grouped_items, bool $showHeader = true): string
378  {
379  if (0 === count($grouped_items)) {
380  return '';
381  }
382 
383  if ($this->viewSettings->isTilePresentation()) {
384  $renderer = new ilPDObjectsTileRenderer(
385  $this->blockView,
386  $this->ui->factory(),
387  $this->ui->renderer(),
389  $this->user,
390  $this->lng,
393  );
394 
395  return $renderer->render($grouped_items, $showHeader);
396  }
397 
398  $renderer = new ilPDObjectsListRenderer(
399  $this->blockView,
400  $this->ui->factory(),
401  $this->ui->renderer(),
403  $this->user,
404  $this->lng,
407  );
408 
409  return $renderer->render($grouped_items, $showHeader);
410  }
411 
412  protected function getViewBlockHtml(): string
413  {
414  return $this->renderGroupedItems(
415  $this->blockView->getItemGroups()
416  );
417  }
418 
419  public function changePDItemPresentation()
420  {
421  $this->viewSettings->storeActorPresentationMode(
422  ilUtil::stripSlashes((string) ($this->http->request()->getQueryParams()['presentation'] ?? ''))
423  );
424  $this->initAndShow();
425  }
426 
427  public function changePDItemSorting()
428  {
429  $this->viewSettings->storeActorSortingMode(
430  ilUtil::stripSlashes((string) ($this->http->request()->getQueryParams()['sorting'] ?? ''))
431  );
432 
433  $this->initAndShow();
434  }
435 
436  protected function initAndShow()
437  {
438  $this->initViewSettings();
439 
440  if ($this->ctrl->isAsynch()) {
441  echo $this->getHTML();
442  exit;
443  }
444 
445  if ($_GET["manage"]) {
446  $this->ctrl->redirect($this, 'manage');
447  }
448 
449  $this->returnToContext();
450  }
451 
452  public function manageObject()
453  {
454  $this->blockView->setIsInManageMode(true);
455 
456  $top_tb = new ilToolbarGUI();
457  $top_tb->setFormAction($this->ctrl->getFormAction($this));
458  $top_tb->setLeadingImage(ilUtil::getImagePath('arrow_upright.svg'), $this->lng->txt('actions'));
459 
460  $button = ilSubmitButton::getInstance();
461  $grouped_items = $this->blockView->getItemGroups();
462  if ($this->viewSettings->isSelectedItemsViewActive()) {
463  $button->setCaption('remove');
464  } else {
465  $button->setCaption('pd_unsubscribe_memberships');
466  foreach ($grouped_items as $group) {
467  $items = $group->getItems();
468  $group->setItems([]);
469  foreach ($items as $item) {
470  if ($this->rbacsystem->checkAccess('leave', $item['ref_id'])) {
471  if (
472  $item['type'] !== 'crs' ||
473  ilParticipants::getInstance($item['ref_id'])->checkLastAdmin([$this->user->getId()])
474  ) {
475  $group->pushItem($item);
476  }
477  }
478  }
479  }
480  }
481  $button->setCommand('confirmRemove');
482  $top_tb->addStickyItem($button);
483 
484  $top_tb->setCloseFormTag(false);
485 
486  $bot_tb = new ilToolbarGUI();
487  $bot_tb->setLeadingImage(ilUtil::getImagePath('arrow_downright.svg'), $this->lng->txt('actions'));
488  $bot_tb->addStickyItem($button);
489  $bot_tb->setOpenFormTag(false);
490 
491  return $top_tb->getHTML() . $this->renderManageList($grouped_items) . $bot_tb->getHTML();
492  }
493 
494  protected function cancel()
495  {
496  $this->ctrl->returnToParent($this);
497  }
498 
499  public function confirmRemoveObject()
500  {
501  $this->ctrl->setParameter($this, 'view', $this->viewSettings->getCurrentView());
502 
503  $refIds = (array) ($this->http->request()->getParsedBody()['id'] ?? []);
504  if (0 === count($refIds)) {
505  ilUtil::sendFailure($this->lng->txt('select_one'), true);
506  $this->ctrl->redirect($this, 'manage');
507  }
508 
509  if ($this->viewSettings->isSelectedItemsViewActive()) {
510  $question = $this->lng->txt('dash_info_sure_remove_from_favs');
511  $cmd = 'confirmedRemove';
512  } else {
513  $question = $this->lng->txt('mmbr_info_delete_sure_unsubscribe');
514  $cmd = 'confirmedUnsubscribe';
515  }
516 
517  include_once('./Services/Utilities/classes/class.ilConfirmationGUI.php');
518  $cgui = new ilConfirmationGUI();
519  $cgui->setHeaderText($question);
520 
521  $cgui->setFormAction($this->ctrl->getFormAction($this));
522  $cgui->setCancel($this->lng->txt('cancel'), 'manage');
523  $cgui->setConfirm($this->lng->txt('confirm'), $cmd);
524 
525  foreach ($refIds as $ref_id) {
526  $obj_id = ilObject::_lookupObjectId((int) $ref_id);
527  $title = ilObject::_lookupTitle($obj_id);
528  $type = ilObject::_lookupType($obj_id);
529 
530  $cgui->addItem(
531  'ref_id[]',
532  $ref_id,
533  $title,
534  ilObject::_getIcon($obj_id, 'small', $type),
535  $this->lng->txt('icon') . ' ' . $this->lng->txt('obj_' . $type)
536  );
537  }
538 
539  return $cgui->getHTML();
540  }
541 
542  public function confirmedRemove()
543  {
544  $refIds = (array) ($this->http->request()->getParsedBody()['ref_id'] ?? []);
545  if (0 === count($refIds)) {
546  $this->ctrl->redirect($this, 'manage');
547  }
548 
549  foreach ($refIds as $ref_id) {
550  $this->favourites->remove($this->user->getId(), (int) $ref_id);
551  }
552 
553  // #12909
554  ilUtil::sendSuccess($this->lng->txt('pd_remove_multi_confirm'), true);
555  $this->ctrl->redirect($this, 'manage');
556  }
557 
558  public function confirmedUnsubscribe()
559  {
560  $refIds = (array) ($this->http->request()->getParsedBody()['ref_id'] ?? []);
561  if (0 === count($refIds)) {
562  $this->ctrl->redirect($this, 'manage');
563  }
564 
565  foreach ($refIds as $ref_id) {
566  if ($this->access->checkAccess('leave', '', (int) $ref_id)) {
567  switch (ilObject::_lookupType($ref_id, true)) {
568  case 'crs':
569  $members = new ilCourseParticipants(ilObject::_lookupObjId((int) $ref_id));
570  $members->delete($this->user->getId());
571 
572  $members->sendUnsubscribeNotificationToAdmins($this->user->getId());
573  $members->sendNotification(
574  $members->NOTIFY_UNSUBSCRIBE,
575  $this->user->getId()
576  );
577  break;
578 
579  case 'grp':
580  $members = new ilGroupParticipants(ilObject::_lookupObjId((int) $ref_id));
581  $members->delete($this->user->getId());
582 
583  $members->sendNotification(
585  $this->user->getId()
586  );
587  $members->sendNotification(
589  $this->user->getId()
590  );
591  break;
592 
593  default:
594  continue 2;
595  }
596 
597  include_once './Modules/Forum/classes/class.ilForumNotification.php';
598  ilForumNotification::checkForumsExistsDelete($ref_id, $this->user->getId());
599  }
600  }
601 
602  ilUtil::sendSuccess($this->lng->txt('mmbr_unsubscribed_from_objs'), true);
603  $this->ctrl->returnToParent($this);
604  }
605 
609  protected function getListItemGroups(): array
610  {
611  $groupedItems = $this->blockView->getItemGroups();
612  $groupedCommands = $this->getGroupedCommandsForView();
613  foreach ($groupedCommands as $group) {
614  foreach ($group as $command) {
615  $this->addBlockCommand(
616  (string) $command['url'],
617  (string) $command['txt'],
618  (string) $command['asyncUrl']
619  );
620  }
621  }
622 
623  $item_groups = [];
624  $list_items = [];
625 
626  foreach ($groupedItems as $group) {
627  $list_items = [];
628 
629  foreach ($group->getItems() as $item) {
630  try {
631  $list_items[] = $this->getListItemForData($item);
632  } catch (ilException $e) {
633  $this->logging->warning('Listing failed for item with ID ' . $item['obj_id'] . ': ' . $e->getMessage());
634  continue;
635  }
636  }
637  if (count($list_items) > 0) {
638  $item_groups[] = $this->ui->factory()->item()->group((string) $group->getLabel(), $list_items);
639  }
640  }
641 
642  return $item_groups;
643  }
644 
648  protected function getListItemForData(array $data): Item
649  {
650  $itemListGui = $this->list_factory->byType($data['type']);
652 
653  $list_item = $itemListGui->getAsListItem(
654  (int) $data['ref_id'],
655  (int) $data['obj_id'],
656  (string) $data['type'],
657  (string) $data['title'],
658  (string) $data['description']
659  );
660 
661  return $list_item;
662  }
663 
664  protected function getCardForData(array $item): Card
665  {
666  $itemListGui = $this->list_factory->byType($item['type']);
668 
669  $card = $itemListGui->getAsCard(
670  (int) $item['ref_id'],
671  (int) $item['obj_id'],
672  (string) $item['type'],
673  (string) $item['title'],
674  (string) $item['description']
675  );
676 
677  return $card;
678  }
679 
683  protected function getLegacyContent(): string
684  {
685  $groupedCommands = $this->getGroupedCommandsForView();
686  foreach ($groupedCommands as $group) {
687  foreach ($group as $command) {
688  $this->addBlockCommand(
689  (string) $command['url'],
690  (string) $command['txt'],
691  (string) $command['asyncUrl']
692  );
693  }
694  }
695 
696  $groupedItems = $this->blockView->getItemGroups();
697 
698  $subs = [];
699  foreach ($groupedItems as $group) {
700  $cards = [];
701 
702  foreach ($group->getItems() as $item) {
703  try {
704  $cards[] = $this->getCardForData($item);
705  } catch (ilException $e) {
706  $this->logging->warning('Listing failed for item with ID ' . $item['obj_id'] . ': ' . $e->getMessage());
707  continue;
708  }
709  }
710  if (count($cards) > 0) {
711  $subs[] = $this->ui->factory()->panel()->sub(
712  $group->getLabel(),
713  $this->ui->factory()->deck($cards)->withNormalCardsSize()
714  );
715  }
716  }
717 
718  if (count($subs) > 0) {
719  return $this->ui->renderer()->render($subs);
720  }
721 
722  return $this->getNoItemFoundContent();
723  }
724 
725  protected function renderManageList(array $grouped_items): string
726  {
727  $ui = $this->ui;
728 
729  $this->ctrl->setParameter($this, "manage", "1");
730  $groupedCommands = $this->getGroupedCommandsForView(true);
731  foreach ($groupedCommands as $group) {
732  foreach ($group as $command) {
733  $this->addBlockCommand(
734  (string) $command['url'],
735  (string) $command['txt'],
736  (string) $command['asyncUrl']
737  );
738  }
739  }
740 
741  if (is_array($groupedCommands[0])) {
742  $actions = array_map(static function ($item) use ($ui) {
743  return $ui->factory()->link()->standard($item["txt"], $item["url"]);
744  }, $groupedCommands[0]);
745  if (count($actions) > 0) {
746  $dd = $this->ui->factory()->dropdown()->standard($actions);
747  $this->main_tpl->setHeaderActionMenu($ui->renderer()->render($dd));
748  }
749  }
750 
751  return (new ilDashObjectsTableRenderer($this))->render($grouped_items);
752  }
753 
757  public function getNoItemFoundContent(): string
758  {
759  $txt = $this->lng->txt("rep_fav_intro1") . "<br>";
760  $txt .= sprintf(
761  $this->lng->txt('rep_fav_intro2'),
762  $this->getRepositoryTitle()
763  ) . "<br>";
764  $txt .= $this->lng->txt("rep_fav_intro3");
765  $mbox = $this->ui->factory()->messageBox()->info($txt);
766  $mbox = $mbox->withLinks([$this->ui->factory()->link()->standard($this->getRepositoryTitle(), ilLink::_getStaticLink(1, 'root', true))]);
767  return $this->ui->renderer()->render($mbox);
768  }
769 
770  protected function getRepositoryTitle()
771  {
772  $nd = $this->tree->getNodeData($this->tree->getRootId());
773  $title = $nd['title'];
774 
775  if ($title === 'ILIAS') {
776  $title = $this->lng->txt('repository');
777  }
778 
779  return $title;
780  }
781 }
renderGroupedItems(array $grouped_items, bool $showHeader=true)
static _getIcon( $a_obj_id="", $a_size="big", $a_type="", $a_offline=false)
Get icon for repository item.
Dashboard objects table renderer.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
exit
Definition: login.php:29
settings()
Definition: settings.php:2
Class ilPDSelectedItemsListRenderer.
$type
setDataSection($a_content)
Call this from overwritten fillDataSection(), if standard row based data is not used.
$_GET["client_id"]
static _lookupTitle($a_id)
lookup object title
setEnableNumInfo($a_enablenuminfo)
Set Enable Item Number Info.
Class ilPDSelectedItemsBlockListGUIFactory.
Manages favourites, currently the interface for other components, needs discussion.
user()
Definition: user.php:4
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupObjectId($a_ref_id)
lookup object id
static getInstance($a_ref_id)
Get instance by ref_id.
const IL_SCREEN_FULL
static http()
Fetches the global http state from ILIAS.
$nd
Definition: error.php:12
setTitle($a_title)
Set Title.
static bySettings(ilPDSelectedItemsBlockViewSettings $viewSettings)
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
setData($a_data)
Set Data.
static _lookupObjId($a_id)
Common interface to all items.
Definition: Item.php:10
global $DIC
Definition: goto.php:24
ui()
Definition: ui.php:5
Class ilPDObjectsTileRenderer.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
render(array $groupedItems, bool $showHeader)
$txt
Definition: error.php:13
static addListGUIActivationProperty(ilObjectListGUI $a_list_gui, array &$a_item)
Get timing details for list gui.
static _lookupType($a_id, $a_reference=false)
lookup object type
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static checkForumsExistsDelete($ref_id, $user_id=0)
render(array $groupedItems, bool $showHeader)
setLimit($a_limit)
Set Limit.
Interface for gui classes (e.g ilLuceneSearchGUI) that offer add/remove to/from desktop.
ilPDSelectedItemsBlockGUI: ilColumnGUI ilPDSelectedItemsBlockGUI: ilCommonActionDispatcherGUI ...
__construct(Container $dic, ilPlugin $plugin)
This class represents a block method of a block.
addBlockCommand(string $a_href, string $a_text, string $a_onclick="")
Add Block Command.
const IL_SCREEN_SIDE
const ID_PART_SCREEN
setPresentation(int $type)
Set presentation.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
Confirmation screen class.