ILIAS  trunk Revision v11.0_alpha-1702-gfd3ecb7f852
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ItemRenderer.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
25 
31 {
32  public const CHECKBOX_NONE = 0;
33  public const CHECKBOX_ADMIN = 1;
34  public const CHECKBOX_DOWNLOAD = 2;
35 
36  protected \ilContainerGUI $container_gui;
37  protected \ilContainer $container;
38  protected string $view_mode;
41  protected array $list_gui = [];
42 
43  public function __construct(
44  InternalDomainService $domain,
45  InternalGUIService $gui,
46  string $view_mode,
47  \ilContainerGUI $container_gui
48  ) {
49  $this->domain = $domain; // setting and access (visible, read, write access)
50  $this->gui = $gui; // getting ilCtrl
52  $container = $container_gui->getObject();
53  $this->view_mode = $view_mode; // tile/list (of container)
54  $this->container_gui = $container_gui; // tile/list (of container)
56  $container = $container_gui->getObject();
57  $this->container = $container; // id, refid, other stuff
58  }
59 
64  public function renderItem(
65  array $a_item_data,
66  int $a_position = 0,
67  bool $a_force_icon = false,
68  string $a_pos_prefix = "",
69  string $item_group_list_presentation = "",
70  int $checkbox = self::CHECKBOX_NONE,
71  bool $item_ordering = false,
72  int $details_level = \ilObjectListGUI::DETAILS_ALL
73  ) {
74  $ilSetting = $this->domain->settings();
75  $ilAccess = $this->domain->access();
76  $ilCtrl = $this->gui->ctrl();
77 
78  // Pass type, obj_id and tree to checkAccess method to improve performance
79  /* deactivated, this should have been checked before
80  if (!$ilAccess->checkAccess('visible', '', $a_item_data['ref_id'], $a_item_data['type'], $a_item_data['obj_id'], $a_item_data['tree'])) {
81  return '';
82  }*/
83  $view_mode = $this->view_mode;
84  if ($item_group_list_presentation != "") {
85  $view_mode = ($item_group_list_presentation === "tile")
88  }
89 
90  if ($view_mode == \ilContainerContentGUI::VIEW_MODE_TILE) {
91  return $this->renderCard($a_item_data, $a_position, $a_force_icon, $a_pos_prefix);
92  }
93 
94  $item_list_gui = $this->getItemGUI($a_item_data);
95  if ($ilSetting->get("icon_position_in_lists") === "item_rows" ||
96  $a_item_data["type"] === "sess" || $a_force_icon) {
97  $item_list_gui->enableIcon(true);
98  }
99  if ($checkbox === self::CHECKBOX_ADMIN) {
100  $item_list_gui->enableCheckbox(true);
101  } elseif ($checkbox === self::CHECKBOX_DOWNLOAD) {
102  // display multi download checkboxes
103  $item_list_gui->enableDownloadCheckbox((int) $a_item_data["ref_id"]);
104  }
105 
106  if ($item_ordering && $a_item_data['type'] !== 'sess') {
107  $item_list_gui->setPositionInputField(
108  $a_pos_prefix . "[" . $a_item_data["ref_id"] . "]",
109  sprintf('%d', $a_position * 10)
110  );
111  }
112 
113  if ($a_item_data['type'] === 'sess') {
114  switch ($details_level) {
115  case \ilContainerContentGUI::DETAILS_TITLE:
116  $item_list_gui->setDetailsLevel(\ilObjectListGUI::DETAILS_MINIMAL);
117  $item_list_gui->enableExpand(true);
118  $item_list_gui->setExpanded(false);
119  $item_list_gui->enableDescription(false);
120  $item_list_gui->enableProperties(true);
121  break;
122 
123  case \ilContainerContentGUI::DETAILS_ALL:
124  $item_list_gui->setDetailsLevel(\ilObjectListGUI::DETAILS_ALL);
125  $item_list_gui->enableExpand(true);
126  $item_list_gui->setExpanded(true);
127  $item_list_gui->enableDescription(true);
128  $item_list_gui->enableProperties(true);
129  break;
130 
131  case \ilContainerContentGUI::DETAILS_DEACTIVATED:
132  break;
133 
134  default:
135  $item_list_gui->setDetailsLevel(\ilObjectListGUI::DETAILS_ALL);
136  $item_list_gui->enableExpand(true);
137  $item_list_gui->enableDescription(true);
138  $item_list_gui->enableProperties(true);
139  break;
140  }
141  }
142 
143  if (method_exists($this, "addItemDetails")) {
144  $this->addItemDetails($item_list_gui, $a_item_data);
145  }
146 
147  // show subitems of sessions
148  if ($a_item_data['type'] === 'sess' and (
149  $details_level !== \ilContainerContentGUI::DETAILS_TITLE or
150  $this->container_gui->isActiveAdministrationPanel() or
151  $this->container_gui->isActiveItemOrdering()
152  )
153  ) {
154  $pos = 1;
155 
156  $items = \ilObjectActivation::getItemsByEvent((int) $a_item_data['obj_id']);
157  $items = \ilContainerSorting::_getInstance($this->container->getId())->sortSubItems('sess', (int) $a_item_data['obj_id'], $items);
158  $items = \ilContainer::getCompleteDescriptions($items);
159 
160  $item_readable = $ilAccess->checkAccess('read', '', (int) $a_item_data['ref_id']);
161 
162  foreach ($items as $item) {
163  // TODO: this should be removed and be handled by if(strlen($sub_item_html))
164  // see mantis: 0003944
165  if (!$ilAccess->checkAccess('visible', '', (int) $item['ref_id'])) {
166  continue;
167  }
168 
169  $item_list_gui2 = $this->getItemGUI($item);
170  $item_list_gui2->enableIcon(true);
171  $item_list_gui2->enableItemDetailLinks(false);
172 
173  // unique js-ids
174  $item_list_gui2->setParentRefId((int) ($a_item_data['ref_id'] ?? 0));
175 
176  // @see mantis 10488
177  if (!$item_readable and !$ilAccess->checkAccess('write', '', $item['ref_id'])) {
178  $item_list_gui2->forceVisibleOnly(true);
179  }
180 
181  if ($checkbox === self::CHECKBOX_ADMIN) {
182  $item_list_gui2->enableCheckbox(true);
183  } elseif ($checkbox === self::CHECKBOX_DOWNLOAD) {
184  // display multi download checkbox
185  $item_list_gui2->enableDownloadCheckbox((int) $item['ref_id']);
186  }
187 
188  if ($this->container_gui->isActiveItemOrdering()) {
189  $item_list_gui2->setPositionInputField(
190  "[sess][" . $a_item_data['obj_id'] . "][" . $item["ref_id"] . "]",
191  sprintf('%d', $pos * 10)
192  );
193  $pos++;
194  }
195 
196  // #10611
198 
199  $sub_item_html = $item_list_gui2->getListItemHTML(
200  (int) $item['ref_id'],
201  (int) $item['obj_id'],
202  $item['title'],
203  $item['description']
204  );
205 
206  if (strlen($sub_item_html)) {
207  $item_list_gui->addSubItemHTML($sub_item_html);
208  }
209  }
210  }
211 
212  $asynch = false;
213  $asynch_url = '';
214  if ($ilSetting->get("item_cmd_asynch")) {
215  $asynch = true;
216  $ilCtrl->setParameter($this->container_gui, "cmdrefid", $a_item_data['ref_id']);
217  $asynch_url = $ilCtrl->getLinkTarget(
218  $this->container_gui,
219  "getAsynchItemList",
220  "",
221  true,
222  false
223  );
224  $ilCtrl->setParameter($this->container_gui, "cmdrefid", "");
225  }
226 
227  \ilObjectActivation::addListGUIActivationProperty($item_list_gui, $a_item_data);
228 
229  $html = $item_list_gui->getListItemHTML(
230  (int) $a_item_data['ref_id'],
231  (int) $a_item_data['obj_id'],
232  (string) $a_item_data['title'],
233  (string) $a_item_data['description'],
234  $asynch,
235  false,
236  $asynch_url
237  );
238 
239  return $html;
240  }
241 
242  public function renderCard(
243  array $a_item_data,
244  int $a_position = 0,
245  bool $a_force_icon = false,
246  string $a_pos_prefix = ""
248  $item_list_gui = $this->getItemGUI($a_item_data);
249  $item_list_gui->setAjaxHash(\ilCommonActionDispatcherGUI::buildAjaxHash(
251  (int) $a_item_data['ref_id'],
252  $a_item_data['type'],
253  (int) $a_item_data['obj_id']
254  ));
255  $item_list_gui->initItem(
256  (int) $a_item_data['ref_id'],
257  (int) $a_item_data['obj_id'],
258  $a_item_data['type'],
259  $a_item_data['title'],
260  $a_item_data['description']
261  );
262 
263  return $item_list_gui->getAsCard(
264  (int) $a_item_data['ref_id'],
265  (int) $a_item_data['obj_id'],
266  (string) $a_item_data['type'],
267  (string) $a_item_data['title'],
268  (string) $a_item_data['description']
269  );
270  }
271 
272  public function getItemGUI(array $item_data): \ilObjectListGUI
273  {
274  // get item list gui object
275  if (!isset($this->list_gui[$item_data["type"]])) {
276  $item_list_gui = \ilObjectListGUIFactory::_getListGUIByType($item_data["type"]);
277  $item_list_gui->setContainerObject($this->container_gui);
278  $this->list_gui[$item_data["type"]] = $item_list_gui;
279  } else {
280  $item_list_gui = $this->list_gui[$item_data["type"]];
281  }
282 
283  // unique js-ids
284  $item_list_gui->setParentRefId((int) ($item_data["parent"] ?? 0));
285 
286  $item_list_gui->setDefaultCommandParameters(array());
287  $item_list_gui->disableTitleLink(false);
288  $item_list_gui->resetConditionTarget();
289 
290  if ($this->container->isClassificationFilterActive()) {
291  $item_list_gui->enablePath(
292  true,
293  $this->container->getRefId(),
294  new \ilSessionClassificationPathGUI()
295  );
296  }
297 
298  // show administration command buttons (or not)
299  /*
300  if (!$this->container_gui->isActiveAdministrationPanel()) {
301  // $item_list_gui->enableDelete(false);
302 // $item_list_gui->enableLink(false);
303 // $item_list_gui->enableCut(false);
304  }*/
305 
306  // activate common social commands
307  $item_list_gui->enableComments(true);
308  $item_list_gui->enableNotes(true);
309  $item_list_gui->enableTags(true);
310  $item_list_gui->enableRating(true);
311 
312  // reset
313  $item_list_gui->forceVisibleOnly(false);
314 
315  // container specific modifications
316  $this->container_gui->modifyItemGUI($item_list_gui, $item_data);
317 
318  return $item_list_gui;
319  }
320 }
static getItemsByEvent(int $event_id)
Get session material / event items.
Interface Observer Contains several chained tasks and infos about them.
renderItem(array $a_item_data, int $a_position=0, bool $a_force_icon=false, string $a_pos_prefix="", string $item_group_list_presentation="", int $checkbox=self::CHECKBOX_NONE, bool $item_ordering=false, int $details_level=\ilObjectListGUI::DETAILS_ALL)
Render an item.
static buildAjaxHash(int $node_type, ?int $node_id, string $obj_type, int $obj_id, ?string $sub_type=null, ?int $sub_id=null, int $news_id=0)
Build ajax hash.
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:76
static addListGUIActivationProperty(ilObjectListGUI $list_gui, array &$item)
Get timing details for list gui.
static _getListGUIByType(string $type, int $context=ilObjectListGUI::CONTEXT_REPOSITORY)
renderCard(array $a_item_data, int $a_position=0, bool $a_force_icon=false, string $a_pos_prefix="")
global $ilSetting
Definition: privfeed.php:31
static _getInstance(int $a_obj_id)
Class ilContainerGUI This is a base GUI class for all container objects in ILIAS: root folder...
static getCompleteDescriptions(array $objects)
overwrites description fields to long or short description in an assoc array keys needed (obj_id and ...