ILIAS  trunk Revision v12.0_alpha-1338-g8f7e531aa3c
ObjectsContent.php
Go to the documentation of this file.
1<?php
2
20
21use ILIAS\UI\Factory as UIFactory;
22use ILIAS\UI\Renderer as UIRenderer;
23use ILIAS\UI\Component\Panel\Sub as SubPanel;
24use ilObjUser;
28use ilLanguage;
29use ilCtrl;
34use ilLink;
37
42{
43 protected ilObjUser $user;
47 protected ilLanguage $lng;
48 protected ilCtrl $ctrl;
49 protected UIFactory $ui_factory;
50 protected UIRenderer $ui_renderer;
53 protected array $item_list_guis;
54 protected bool $enable_desktop;
56
57 public function __construct(
58 ilContainerGUI $a_parent_obj,
59 ilContainerStartObjects $a_start_objects,
60 UIFactory $ui_factory,
61 UIRenderer $ui_renderer,
62 bool $a_enable_desktop = true
63 ) {
64 global $DIC;
65
66 $this->user = $DIC->user();
67 $this->obj_data_cache = $DIC["ilObjDataCache"];
68 $this->access = $DIC->access();
69 $this->obj_definition = $DIC["objDefinition"];
70 $this->ui_factory = $ui_factory;
71 $this->ui_renderer = $ui_renderer;
72 $lng = $DIC->language();
73 $ilCtrl = $DIC->ctrl();
74
75 $this->lng = $lng;
76 $this->lng->loadLanguageModule('rep');
77 $this->ctrl = $ilCtrl;
78
79 $this->parent_obj = $a_parent_obj;
80 $this->start_object = $a_start_objects;
81 $this->enable_desktop = $a_enable_desktop;
82
83 $this->fav_manager = new ilFavouritesManager();
84 }
85
86 protected function getData(): array
87 {
88 $ilUser = $this->user;
89 $ilObjDataCache = $this->obj_data_cache;
90 $ilAccess = $this->access;
91
92 $lm_continue = new ilCourseLMHistory($this->start_object->getRefId(), $ilUser->getId());
93 $continue_data = $lm_continue->getLMHistory();
94
95 $items = [];
96 $counter = 0;
97 foreach ($this->start_object->getStartObjects() as $start) {
98 $obj_id = $ilObjDataCache->lookupObjId((int) $start['item_ref_id']);
99 $ref_id = $start['item_ref_id'];
100 $type = $ilObjDataCache->lookupType($obj_id);
101
102 if (!$ilAccess->checkAccess("visible", "", $ref_id)) {
103 continue;
104 }
105
106 // start object status
107 if ($this->start_object->isFullfilled($ilUser->getId(), $ref_id)) {
108 $accomplished = 'accomplished';
109 } else {
110 $accomplished = 'not_accomplished';
111 }
112
113 // add/remove desktop
114 $actions = [];
115
116 if (isset($continue_data[$ref_id])) {
117 $url = ilLink::_getLink($ref_id, '', [
118 'obj_id',
119 $continue_data[$ref_id]['lm_page_id']
120 ]);
121 $actions[$url] = $this->lng->txt('continue_work');
122 }
123
124 if ($this->enable_desktop) {
125 $this->lng->loadLanguageModule('dash');
126 // add to desktop link
127 if (!$this->fav_manager->ifIsFavourite($ilUser->getId(), $ref_id)) {
128 if ($ilAccess->checkAccess('read', '', $ref_id)) {
129 $this->ctrl->setParameter($this->parent_obj, 'item_ref_id', $ref_id);
130 $this->ctrl->setParameter($this->parent_obj, 'item_id', $ref_id);
131 $this->ctrl->setParameter($this->parent_obj, 'type', $type);
132 $url = $this->ctrl->getLinkTarget($this->parent_obj, 'addToDesk');
133 $actions[$url] = $this->lng->txt("add_to_favourites");
134 }
135 } else {
136 $this->ctrl->setParameter($this->parent_obj, 'item_ref_id', $ref_id);
137 $this->ctrl->setParameter($this->parent_obj, 'item_id', $ref_id);
138 $this->ctrl->setParameter($this->parent_obj, 'type', $type);
139 $url = $this->ctrl->getLinkTarget($this->parent_obj, 'removeFromDesk');
140 $actions[$url] = $this->lng->txt("remove_from_favourites");
141 }
142 }
143
144 $default_params = null;
145 if ($type === "tst") {
146 $default_params["crs_show_result"] = $ref_id;
147 }
148 /* continue is currently inactive
149 if(isset($continue_data[$ref_id]))
150 {
151 // :TODO: should "continue" be default or 2nd link/action?
152 // $this->lng->txt('continue_work')
153 $default_params["obj_id"] = $continue_data[$ref_id]['lm_page_id'];
154 }
155 */
156
157 if ($accomplished === 'accomplished') {
158 $icon = "assets/images/standard/icon_ok.svg";
159 } else {
160 $icon = "assets/images/standard/icon_not_ok.svg";
161 }
162
163 $items[] = [
164 "nr" => ++$counter,
165 "obj_id" => $obj_id,
166 "ref_id" => $ref_id,
167 "type" => $type,
168 "append_default" => $default_params,
169 "title" => $ilObjDataCache->lookupTitle($obj_id),
170 "description" => $ilObjDataCache->lookupDescription($obj_id),
171 "status" => $this->lng->txt('crs_objective_' . $accomplished),
172 "status_img" => $icon,
173 "actions" => $actions
174 ];
175 }
176
178 foreach ($items as $item) {
179 $preloader->addItem($item["obj_id"], $item["type"], $item["ref_id"]);
180 }
181 $preloader->preload();
182 unset($preloader);
183
184 return $items;
185 }
186
187 protected function getItemListGUI(string $a_type): ?ilObjectListGUI
188 {
189 $objDefinition = $this->obj_definition;
190
191 if (!isset($this->item_list_guis[$a_type])) {
192 $class = $objDefinition->getClassName($a_type);
193 // Fixed problem with deactivated plugins and existing repo. object plugin objects on the user's desktop
194 if (!$class) {
195 return null;
196 }
197 // Fixed problem with deactivated plugins and existing repo. object plugin objects on the user's desktop
198 $location = $objDefinition->getLocation($a_type);
199 if (!$location) {
200 return null;
201 }
202 $full_class = "ilObj" . $class . "ListGUI";
203 $item_list_gui = new $full_class();
204 $this->item_list_guis[$a_type] = $item_list_gui;
205 } else {
206 $item_list_gui = $this->item_list_guis[$a_type];
207 }
208
209 $item_list_gui->setDefaultCommandParameters([]);
210
211 return $item_list_gui;
212 }
213
214 // Get list gui html
215 protected function getListItem(array $a_item): string
216 {
217 $item_list_gui = $this->getItemListGUI($a_item["type"]);
218 if (!$item_list_gui) {
219 return "";
220 }
221
222 $item_list_gui->setContainerObject($this);
223 $item_list_gui->enableCommands(true, true);
224
225 // ilObjectActivation::addListGUIActivationProperty($item_list_gui, $a_item);
226
227 // notes, comment currently do not work properly
228 $item_list_gui->enableNotes(false);
229 $item_list_gui->enableComments(false);
230 $item_list_gui->enableTags(false);
231
232 $item_list_gui->enableIcon(true);
233 $item_list_gui->enableDelete(false);
234 $item_list_gui->enableCut(false);
235 $item_list_gui->enableCopy(false);
236 $item_list_gui->enableLink(false);
237 $item_list_gui->enableInfoScreen(true);
238 $item_list_gui->enableSubscribe(false);
239
240 $level = 3;
241
242 if ($level < 3) {
243 $item_list_gui->enableDescription(false);
244 $item_list_gui->enableProperties(false);
245 $item_list_gui->enablePreconditions(false);
246 }
247
248 if ($a_item["append_default"]) {
249 $item_list_gui->setDefaultCommandParameters($a_item["append_default"]);
250 }
251 if (is_object($item_list_gui)) {
252 return $item_list_gui->getListItemHTML(
253 $a_item["ref_id"],
254 $a_item["obj_id"],
255 $a_item["title"],
256 $a_item["description"]
257 );
258 }
259 return "";
260 }
261
262 protected function getItemAsSubPanel(array $item): SubPanel
263 {
264 $status_icon = $this->ui_factory->symbol()->icon()->custom(
265 $item['status_img'],
266 $item['status']
267 );
268
269 $actions = [];
270 foreach ($item['actions'] as $url => $caption) {
271 $actions[] = $this->ui_factory->button()->shy($caption, $url);
272 }
273
274 $secondary_info = $this->ui_factory->listing()->property()->withItems([
275 [$this->lng->txt('crs_objective_accomplished'), $status_icon],
276 [$this->lng->txt('actions'), $this->ui_renderer->render($actions)]
277 ]);
278
279 return $this->ui_factory->panel()->sub(
280 '',
281 $this->ui_factory->legacy()->content($this->getListItem($item))
282 )->withFurtherInformation(
283 $this->ui_factory->panel()->secondary()->legacy(
284 '',
285 $this->ui_factory->legacy()->content($this->ui_renderer->render($secondary_info))
286 )
287 );
288 }
289
290 public function render(): string
291 {
292 $info = $this->ui_factory->panel()->sub(
293 '',
294 $this->ui_factory->legacy()->content($this->lng->txt('crs_info_start'))
295 );
296 $items = [$info];
297 foreach ($this->getData() as $datum) {
298 $items[] = $this->getItemAsSubPanel($datum);
299 }
300
301 $panel = $this->ui_factory->panel()->standard(
302 $this->lng->txt('crs_table_start_objects'),
303 $items
304 );
305 return $this->ui_renderer->render($panel);
306 }
307}
$location
Definition: buildRTE.php:22
__construct(ilContainerGUI $a_parent_obj, ilContainerStartObjects $a_start_objects, UIFactory $ui_factory, UIRenderer $ui_renderer, bool $a_enable_desktop=true)
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Class ilContainerGUI This is a base GUI class for all container objects in ILIAS: root folder,...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
class ilCourseLMHistory
Class ilCtrl provides processing control methods.
Manages favourites, currently the interface for other components, needs discussion.
language handling
User class.
class ilObjectDataCache
parses the objects.xml it handles the xml-description of all ilias objects
getClassName(string $obj_name)
Preloader for object list GUIs.
$info
Definition: entry_point.php:21
This describes a Sub Panel.
Definition: Sub.php:30
An entity that renders components to a string output.
Definition: Renderer.php:31
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
$ref_id
Definition: ltiauth.php:66
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26
$url
Definition: shib_logout.php:70
$counter