ILIAS  release_8 Revision v8.24
class.ilDashboardRecommendedContentGUI.php
Go to the documentation of this file.
1<?php
2
21
28{
29 protected ilObjUser $user;
32 protected array $recommendations;
33 public static array $list_by_type = [];
34 protected \ILIAS\DI\UIServices $ui;
35 protected ilLanguage $lng;
36 protected ilCtrl $ctrl;
42
43 public function __construct()
44 {
46 global $DIC;
47 $this->main_tpl = $DIC->ui()->mainTemplate();
48
49 $this->user = $DIC->user();
50 $this->rec_manager = new ilRecommendedContentManager();
51 $this->fav_manager = new ilFavouritesManager();
52 $this->objDefinition = $DIC["objDefinition"];
53 $this->ui = $DIC->ui();
54 $this->lng = $DIC->language();
55 $this->ctrl = $DIC->ctrl();
56 $this->settings = $DIC->settings();
57
58 $this->lng->loadLanguageModule("rep");
59
60 $request = $DIC->repository()->internal()->gui()->standardRequest();
61 $this->requested_item_ref_id = $request->getItemRefId();
62
63 $this->recommendations = $this->rec_manager->getOpenRecommendationsOfUser($this->user->getId());
64 }
65
66 public function executeCommand(): void
67 {
69
70 $next_class = $ctrl->getNextClass($this);
71 $cmd = $ctrl->getCmd();
72
73 switch ($next_class) {
74 default:
75 if (in_array($cmd, ["remove", "makeFavourite"])) {
76 $this->$cmd();
77 }
78 }
79 }
80
81 public function render(): string
82 {
83 if (count($this->recommendations) === 0) {
84 return "";
85 }
86 return $this->ui->renderer()->render(
87 $this->ui->factory()->panel()->listing()->standard(
88 $this->lng->txt("rep_recommended_content"),
89 $this->getListItemGroups()
90 )
91 );
92 }
93
97 protected function getListItemGroups(): array
98 {
99 global $DIC;
100 $factory = $DIC->ui()->factory();
101
102 $item_groups = [];
103 $list_items = [];
104
105 foreach ($this->recommendations as $ref_id) {
106 try {
107 if (!$DIC->access()->checkAccess('visible', '', $ref_id)) {
108 continue;
109 }
110 $list_items[] = $this->getListItemForData($ref_id);
111 } catch (ilException $e) {
112 continue;
113 }
114 }
115
116 $item_groups[] = $factory->item()->group("", $list_items);
117
118 return $item_groups;
119 }
120
121 protected function getListItemForData(int $ref_id): ?Item
122 {
123 $short_desc = $this->settings->get("rep_shorten_description");
124 $short_desc_max_length = (int) $this->settings->get("rep_shorten_description_length");
125 $ctrl = $this->ctrl;
126
128 $type = ilObject::_lookupType($obj_id);
129 $title = ilObject::_lookupTitle($obj_id);
130 $desc = ilObject::_lookupDescription($obj_id);
131 if ($short_desc && $short_desc_max_length !== 0) {
132 $desc = ilStr::shortenTextExtended($desc, $short_desc_max_length, true);
133 }
134 $item = [
135 "ref_id" => $ref_id,
136 "obj_id" => $obj_id,
137 "type" => $type,
138 "title" => $title,
139 "description" => $desc,
140 ];
141
143 $item_gui = $this->byType($type);
145
146 $ctrl->setParameter($this, "item_ref_id", $ref_id);
147
148 $item_gui->addCustomCommand(
149 $ctrl->getLinkTarget($this, "remove"),
150 "dash_remove_from_list"
151 );
152
153 $item_gui->addCustomCommand(
154 $ctrl->getLinkTarget($this, "makeFavourite"),
155 "dash_make_favourite"
156 );
157
158 $ctrl->clearParameterByClass(self::class, "item_ref_id");
159
160
161 $list_item = $item_gui->getAsListItem(
162 $ref_id,
163 $obj_id,
164 $type,
165 $title,
166 $desc
167 );
168
169 return $list_item;
170 }
171
175 public function byType(string $a_type): ilObjectListGUI
176 {
178 if (!array_key_exists($a_type, self::$list_by_type)) {
179 $class = $this->objDefinition->getClassName($a_type);
180 if (!$class) {
181 throw new ilException(sprintf("Could not find a class for object type: %s", $a_type));
182 }
183
184 $location = $this->objDefinition->getLocation($a_type);
185 if (!$location) {
186 throw new ilException(sprintf("Could not find a class location for object type: %s", $a_type));
187 }
188
189 $full_class = 'ilObj' . $class . 'ListGUI';
190 $item_list_gui = new $full_class();
191
192 $item_list_gui->setContainerObject($this);
193 $item_list_gui->enableNotes(false);
194 $item_list_gui->enableComments(false);
195 $item_list_gui->enableTags(false);
196
197 $item_list_gui->enableIcon(true);
198 $item_list_gui->enableDelete(false);
199 $item_list_gui->enableCut(false);
200 $item_list_gui->enableCopy(false);
201 $item_list_gui->enableLink(false);
202 $item_list_gui->enableInfoScreen(true);
203 //$item_list_gui->enableSubscribe($this->block->getViewSettings()->enabledSelectedItems());
204
205 $item_list_gui->enableCommands(true, true);
206
207 self::$list_by_type[$a_type] = $item_list_gui;
208 }
209
210 return (clone self::$list_by_type[$a_type]);
211 }
212
213 protected function remove(): void
214 {
217 $this->rec_manager->declineObjectRecommendation($this->user->getId(), $this->requested_item_ref_id);
218 $this->main_tpl->setOnScreenMessage('success', $lng->txt("dash_item_removed"), true);
219 $ctrl->returnToParent($this);
220 }
221
222 protected function makeFavourite(): void
223 {
226 $this->fav_manager->add($this->user->getId(), $this->requested_item_ref_id);
227 $this->main_tpl->setOnScreenMessage('success', $lng->txt("dash_added_to_favs"), true);
228 $ctrl->returnToParent($this);
229 }
230}
$location
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: buildRTE.php:22
Class ilCtrl provides processing control methods.
returnToParent(object $a_gui_obj, string $a_anchor=null)
@inheritDoc
getNextClass($a_gui_class=null)
@inheritDoc
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
clearParameterByClass(string $a_class, string $a_parameter)
@inheritDoc
getCmd(string $fallback_command=null)
@inheritDoc
getLinkTarget(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false, bool $has_xml_style=false)
@inheritDoc
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...
language handling
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
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 _lookupTitle(int $obj_id)
static _lookupDescription(int $obj_id)
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 shortenTextExtended(string $a_str, int $a_len, bool $a_dots=false, bool $a_next_blank=false, bool $a_keep_extension=false)
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...
$ref_id
Definition: ltiauth.php:67
$factory
Definition: metadata.php:75
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$type