ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ObjectsContent.php
Go to the documentation of this file.
1 <?php
2 
20 
24 use ilObjUser;
26 use ilAccessHandler;
28 use ilLanguage;
29 use ilCtrl;
31 use ilContainerGUI;
34 use ilLink;
36 use ilObjectListGUI;
37 
42 {
43  protected ilObjUser $user;
47  protected ilLanguage $lng;
48  protected ilCtrl $ctrl;
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  // add to desktop link
126  if (!$this->fav_manager->ifIsFavourite($ilUser->getId(), $ref_id)) {
127  if ($ilAccess->checkAccess('read', '', $ref_id)) {
128  $this->ctrl->setParameter($this->parent_obj, 'item_ref_id', $ref_id);
129  $this->ctrl->setParameter($this->parent_obj, 'item_id', $ref_id);
130  $this->ctrl->setParameter($this->parent_obj, 'type', $type);
131  $url = $this->ctrl->getLinkTarget($this->parent_obj, 'addToDesk');
132  $actions[$url] = $this->lng->txt("rep_add_to_favourites");
133  }
134  } else {
135  $this->ctrl->setParameter($this->parent_obj, 'item_ref_id', $ref_id);
136  $this->ctrl->setParameter($this->parent_obj, 'item_id', $ref_id);
137  $this->ctrl->setParameter($this->parent_obj, 'type', $type);
138  $url = $this->ctrl->getLinkTarget($this->parent_obj, 'removeFromDesk');
139  $actions[$url] = $this->lng->txt("rep_remove_from_favourites");
140  }
141  }
142 
143  $default_params = null;
144  if ($type === "tst") {
145  $default_params["crs_show_result"] = $ref_id;
146  }
147  /* continue is currently inactive
148  if(isset($continue_data[$ref_id]))
149  {
150  // :TODO: should "continue" be default or 2nd link/action?
151  // $this->lng->txt('continue_work')
152  $default_params["obj_id"] = $continue_data[$ref_id]['lm_page_id'];
153  }
154  */
155 
156  if ($accomplished === 'accomplished') {
157  $icon = "assets/images/standard/icon_ok.svg";
158  } else {
159  $icon = "assets/images/standard/icon_not_ok.svg";
160  }
161 
162  $items[] = [
163  "nr" => ++$counter,
164  "obj_id" => $obj_id,
165  "ref_id" => $ref_id,
166  "type" => $type,
167  "append_default" => $default_params,
168  "title" => $ilObjDataCache->lookupTitle($obj_id),
169  "description" => $ilObjDataCache->lookupDescription($obj_id),
170  "status" => $this->lng->txt('crs_objective_' . $accomplished),
171  "status_img" => $icon,
172  "actions" => $actions
173  ];
174  }
175 
177  foreach ($items as $item) {
178  $preloader->addItem($item["obj_id"], $item["type"], $item["ref_id"]);
179  }
180  $preloader->preload();
181  unset($preloader);
182 
183  return $items;
184  }
185 
186  protected function getItemListGUI(string $a_type): ?ilObjectListGUI
187  {
188  $objDefinition = $this->obj_definition;
189 
190  if (!isset($this->item_list_guis[$a_type])) {
191  $class = $objDefinition->getClassName($a_type);
192  // Fixed problem with deactivated plugins and existing repo. object plugin objects on the user's desktop
193  if (!$class) {
194  return null;
195  }
196  // Fixed problem with deactivated plugins and existing repo. object plugin objects on the user's desktop
197  $location = $objDefinition->getLocation($a_type);
198  if (!$location) {
199  return null;
200  }
201  $full_class = "ilObj" . $class . "ListGUI";
202  $item_list_gui = new $full_class();
203  $this->item_list_guis[$a_type] = $item_list_gui;
204  } else {
205  $item_list_gui = $this->item_list_guis[$a_type];
206  }
207 
208  $item_list_gui->setDefaultCommandParameters([]);
209 
210  return $item_list_gui;
211  }
212 
213  // Get list gui html
214  protected function getListItem(array $a_item): string
215  {
216  $item_list_gui = $this->getItemListGUI($a_item["type"]);
217  if (!$item_list_gui) {
218  return "";
219  }
220 
221  $item_list_gui->setContainerObject($this);
222  $item_list_gui->enableCommands(true, true);
223 
224  // ilObjectActivation::addListGUIActivationProperty($item_list_gui, $a_item);
225 
226  // notes, comment currently do not work properly
227  $item_list_gui->enableNotes(false);
228  $item_list_gui->enableComments(false);
229  $item_list_gui->enableTags(false);
230 
231  $item_list_gui->enableIcon(true);
232  $item_list_gui->enableDelete(false);
233  $item_list_gui->enableCut(false);
234  $item_list_gui->enableCopy(false);
235  $item_list_gui->enableLink(false);
236  $item_list_gui->enableInfoScreen(true);
237  $item_list_gui->enableSubscribe(false);
238 
239  $level = 3;
240 
241  if ($level < 3) {
242  $item_list_gui->enableDescription(false);
243  $item_list_gui->enableProperties(false);
244  $item_list_gui->enablePreconditions(false);
245  }
246 
247  if ($a_item["append_default"]) {
248  $item_list_gui->setDefaultCommandParameters($a_item["append_default"]);
249  }
250  if (is_object($item_list_gui)) {
251  return $item_list_gui->getListItemHTML(
252  $a_item["ref_id"],
253  $a_item["obj_id"],
254  $a_item["title"],
255  $a_item["description"]
256  );
257  }
258  return "";
259  }
260 
261  protected function getItemAsSubPanel(array $item): SubPanel
262  {
263  $status_icon = $this->ui_factory->symbol()->icon()->custom(
264  $item['status_img'],
265  $item['status']
266  );
267 
268  $actions = [];
269  foreach ($item['actions'] as $url => $caption) {
270  $actions[] = $this->ui_factory->button()->shy($caption, $url);
271  }
272 
273  $secondary_info = $this->ui_factory->listing()->property()->withItems([
274  [$this->lng->txt('crs_objective_accomplished'), $status_icon],
275  [$this->lng->txt('actions'), $this->ui_renderer->render($actions)]
276  ]);
277 
278  return $this->ui_factory->panel()->sub(
279  '',
280  $this->ui_factory->legacy()->content($this->getListItem($item))
281  )->withFurtherInformation(
282  $this->ui_factory->panel()->secondary()->legacy(
283  '',
284  $this->ui_factory->legacy()->content($this->ui_renderer->render($secondary_info))
285  )
286  );
287  }
288 
289  public function render(): string
290  {
291  $info = $this->ui_factory->panel()->sub(
292  '',
293  $this->ui_factory->legacy()->content($this->lng->txt('crs_info_start'))
294  );
295  $items = [$info];
296  foreach ($this->getData() as $datum) {
297  $items[] = $this->getItemAsSubPanel($datum);
298  }
299 
300  $panel = $this->ui_factory->panel()->standard(
301  $this->lng->txt('crs_table_start_objects'),
302  $items
303  );
304  return $this->ui_renderer->render($panel);
305  }
306 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$location
Definition: buildRTE.php:22
$url
Definition: shib_logout.php:68
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
$ref_id
Definition: ltiauth.php:65
global $DIC
Definition: shib_login.php:26
getClassName(string $obj_name)
__construct(ilContainerGUI $a_parent_obj, ilContainerStartObjects $a_start_objects, UIFactory $ui_factory, UIRenderer $ui_renderer, bool $a_enable_desktop=true)
$info
Definition: entry_point.php:21