ILIAS  trunk Revision v11.0_alpha-1769-g99a433fe2dc
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilDashboardRecommendedContentGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
24 {
25  public function __construct()
26  {
27  global $DIC;
29  $request = $DIC->repository()->internal()->gui()->standardRequest();
30  }
31 
32  protected function removeRecommendationObject(): void
33  {
34  $rec_manager = new ilRecommendedContentManager();
35  $rec_manager->declineObjectRecommendation($this->user->getId(), $this->requested_item_ref_id);
36  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt("dash_item_removed"), true);
37  $this->ctrl->returnToParent($this);
38  }
39 
40  public function initViewSettings(): void
41  {
42  $this->viewSettings = new ilPDSelectedItemsBlockViewSettings(
43  $this->user,
45  );
46 
47  $this->ctrl->setParameter($this, 'view', $this->viewSettings->getCurrentView());
48  }
49 
50  public function emptyHandling(): string
51  {
52  return '';
53  }
54 
55  public function initData(): void
56  {
57  $rec_manager = new ilRecommendedContentManager();
58  $recommendations = $rec_manager->getOpenRecommendationsOfUser($this->user->getId());
59 
60  $short_desc = $this->settings->get("rep_shorten_description");
61  $short_desc_max_length = (int) $this->settings->get("rep_shorten_description_length");
63 
64  $recommendations = array_map(static function (int $ref_id) use ($short_desc, $short_desc_max_length): BlockDTO {
65  $obj_id = ilObject::_lookupObjectId($ref_id);
66  $desc = ilObject::_lookupDescription($obj_id);
67  if ($short_desc && $short_desc_max_length !== 0) {
68  $desc = ilStr::shortenTextExtended($desc, $short_desc_max_length, true);
69  }
71  $start = null;
72  $end = null;
73  if ($obj) {
74  switch (get_class($obj)) {
75  case ilObjGroup::class:
76  $start = new ilDateTime($obj->getStart());
77  $end = new ilDateTime($obj->getEnd());
78  break;
79  case ilObjCourse::class:
80  $start = new ilDateTime($obj->getActivationStart());
81  $end = new ilDateTime($obj->getActivationEnd());
82  break;
83  case ilObjTest::class:
84  $start = new ilDateTime($obj->getStartingTime());
85  $end = new ilDateTime($obj->getEndingTime());
86  break;
87  }
88  }
89  return new BlockDTO(
90  ilObject::_lookupType($obj_id),
91  $ref_id,
92  $obj_id,
93  ilObject::_lookupTitle($obj_id),
94  $desc,
95  $start,
96  $end,
97  );
98  }, $recommendations);
99 
100  $this->setData(['' => $recommendations]);
101  }
102 
103  public function getBlockType(): string
104  {
105  return 'pdrecc';
106  }
107 
108  public function addCustomCommandsToActionMenu(ilObjectListGUI $itemListGui, int $ref_id): void
109  {
110  $this->ctrl->setParameter($this, "item_ref_id", $ref_id);
111  $itemListGui->addCustomCommand(
112  $this->ctrl->getLinkTarget($this, "removeRecommendation"),
113  "dash_remove_from_list"
114  );
115  }
116 
117  public function confirmedRemove(array $ids): void
118  {
119  $rec_manager = new ilRecommendedContentManager();
120  foreach ($ids as $ref_id) {
121  $rec_manager->declineObjectRecommendation($this->user->getId(), $ref_id);
122  }
123  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt('pd_remove_multi_confirm'), true);
124  $this->ctrl->returnToParent($this);
125  }
126 
127  public function removeMultipleEnabled(): bool
128  {
129  return true;
130  }
131 
132  public function getRemoveMultipleActionText(): string
133  {
134  return $this->lng->txt('pd_remove_multiple');
135  }
136 }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
ILIAS Block StandardGUIRequest $request
$ref_id
Definition: ltiauth.php:65
static _lookupTitle(int $obj_id)
addCustomCommandsToActionMenu(ilObjectListGUI $itemListGui, int $ref_id)
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
global $DIC
Definition: shib_login.php:22
static _lookupObjectId(int $ref_id)
static _lookupDescription(int $obj_id)
addCustomCommand(string $link, string $lang_var, string $frame='', string $onclick='')
__construct(Container $dic, ilPlugin $plugin)
static shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...