ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilObjItemGroupGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
29 {
30  protected \ILIAS\ItemGroup\InternalGUIService $gui;
32  protected ilTabsGUI $tabs;
33  protected ilHelpGUI $help;
34 
35  public function __construct(
36  int $a_id = 0,
37  int $a_id_type = self::REPOSITORY_NODE_ID,
38  int $a_parent_node_id = 0
39  ) {
40  global $DIC;
41  parent::__construct($a_id, $a_id_type, $a_parent_node_id);
42 
43  $this->lng = $DIC->language();
44  $this->tabs = $DIC->tabs();
45  $this->access = $DIC->access();
46  $this->tpl = $DIC["tpl"];
47  $this->ctrl = $DIC->ctrl();
48  $this->locator = $DIC["ilLocator"];
49  $this->tree = $DIC->repositoryTree();
50  $this->help = $DIC["ilHelp"];
51  $this->gui = $DIC->itemGroup()->internal()->gui();
52  $this->ig_request = $this->gui
53  ->standardRequest();
54  }
55 
56  protected function afterConstructor(): void
57  {
58  $lng = $this->lng;
59 
60  $lng->loadLanguageModule("itgr");
61  $this->ctrl->saveParameter($this, array("ref_id"));
62  }
63 
64  final public function getType(): string
65  {
66  return "itgr";
67  }
68 
69  public function executeCommand(): void
70  {
71  $ilTabs = $this->tabs;
72  $next_class = $this->ctrl->getNextClass($this);
73 
74  switch ($next_class) {
75  case 'ilpermissiongui':
76  $this->prepareOutput();
77  $ilTabs->activateTab("perm_settings");
78  $this->addHeaderAction();
79  $perm_gui = new ilPermissionGUI($this);
80  $this->ctrl->forwardCommand($perm_gui);
81  break;
82 
83  case "ilcommonactiondispatchergui":
85  $this->ctrl->forwardCommand($gui);
86  break;
87 
88  case 'ilobjecttranslationgui':
89  $this->checkPermissionBool("write");
90  $this->prepareOutput();
91  $this->setSettingsSubTabs("settings_trans");
92  $transgui = new ilObjectTranslationGUI($this);
93  $transgui->setEnableFallbackLanguage(false);
94  $transgui->supportContentTranslation(false);
95  $transgui->hideDescription(true);
96  $this->ctrl->forwardCommand($transgui);
97  break;
98 
99  case 'ildidactictemplategui':
100  $this->ctrl->setReturn($this, 'edit');
101  $did = new ilDidacticTemplateGUI($this);
102  $this->ctrl->forwardCommand($did);
103  break;
104 
105  default:
106  $cmd = $this->ctrl->getCmd("listMaterials");
107  $this->prepareOutput();
108  $this->addHeaderAction();
109  $this->$cmd();
110  break;
111  }
112  }
113 
114  public function addLocatorItems(): void
115  {
116  $ilLocator = $this->locator;
117  $ilAccess = $this->access;
118 
119  if (is_object($this->object) && $ilAccess->checkAccess("write", "", $this->object->getRefId())) {
120  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "listMaterials"), "", $this->requested_ref_id);
121  }
122  }
123 
124  protected function initCreationForms(string $new_type): array
125  {
126  $forms = array(self::CFORM_NEW => $this->initCreateForm($new_type));
127 
128  return $forms;
129  }
130 
131  protected function initEditCustomForm(ilPropertyFormGUI $form): void
132  {
133  $form->removeItemByPostVar("desc");
134 
135  // Show didactic template type
136  $this->initDidacticTemplate($form);
137 
138  // presentation
139  $pres = new ilFormSectionHeaderGUI();
140  $pres->setTitle($this->lng->txt('obj_presentation'));
141  $form->addItem($pres);
142 
143  // show title
144  $cb = new ilCheckboxInputGUI($this->lng->txt("itgr_show_title"), "show_title");
145  $cb->setInfo($this->lng->txt("itgr_show_title_info"));
146  $form->addItem($cb);
147 
148  // behaviour
149  $options = ilItemGroupBehaviour::getAll();
150  $si = new ilSelectInputGUI($this->lng->txt("itgr_behaviour"), "behaviour");
151  $si->setInfo($this->lng->txt("itgr_behaviour_info"));
152  $si->setOptions($options);
153  $cb->addSubItem($si);
154 
155  // tile/list
156  $lpres = new ilRadioGroupInputGUI($this->lng->txt('itgr_list_presentation'), "list_presentation");
157 
158  $std_list = new ilRadioOption($this->lng->txt('itgr_list_default'), "");
159  $std_list->setInfo($this->lng->txt('itgr_list_default_info'));
160  $lpres->addOption($std_list);
161 
162  $item_list = new ilRadioOption($this->lng->txt('itgr_list'), "list");
163  $lpres->addOption($item_list);
164 
165  $tile_view = new ilRadioOption($this->lng->txt('itgr_tile'), "tile");
166  $lpres->addOption($tile_view);
167 
168  // tile size
169  $si = new ilRadioGroupInputGUI($this->lng->txt("itgr_tile_size"), "tile_size");
170  $dummy_container = new ilContainer();
171  $this->lng->loadLanguageModule("cont");
172  foreach ($dummy_container->getTileSizes() as $key => $txt) {
173  $op = new ilRadioOption($txt, $key);
174  $si->addOption($op);
175  }
176  $tile_view->addSubItem($si);
177  $si->setValue($this->object->getTileSize());
178 
179  $lpres->setValue($this->object->getListPresentation());
180  $form->addItem($lpres);
181  }
182 
183  protected function afterSave(ilObject $new_object): void
184  {
185  $ilCtrl = $this->ctrl;
186 
187  $this->tpl->setOnScreenMessage('success', $this->lng->txt("object_added"), true);
188  $ilCtrl->redirect($this, "listMaterials");
189  }
190 
191  public function edit(): void
192  {
193  if (!$this->checkPermissionBool("write")) {
194  $this->error->raiseError($this->lng->txt("msg_no_perm_write"), $this->error->MESSAGE);
195  }
196 
197  $this->tabs_gui->activateTab("settings");
198 
199  $form = $this->initEditForm();
200  $values = $this->getEditFormValues();
201  if ($values) {
202  $form->setValuesByArray($values, true);
203  }
204 
205  $this->addExternalEditFormCustom($form);
206 
207  $this->tpl->setContent($form->getHTML());
208  $this->setSettingsSubTabs("general");
209  }
210 
211  protected function afterUpdate(): void
212  {
213  // check if template is changed
215  $this->object->getRefId()
216  );
217  $new_tpl_id = $this->getDidacticTemplateVar('dtpl');
218 
219  if ($new_tpl_id !== $current_tpl_id) {
220  // redirect to didactic template confirmation
221  $this->ctrl->setReturn($this, 'edit');
222  $this->ctrl->setCmdClass('ildidactictemplategui');
223  $this->ctrl->setCmd('confirmTemplateSwitch');
224  $dtpl_gui = new ilDidacticTemplateGUI($this, $new_tpl_id);
225  $this->ctrl->forwardCommand($dtpl_gui);
226  return;
227  }
228  parent::afterUpdate();
229  }
230 
231  public function listMaterials(): void
232  {
233  $tree = $this->tree;
234  $ilTabs = $this->tabs;
235  $tpl = $this->tpl;
236 
237  $this->checkPermission("write");
238 
239  $ilTabs->activateTab("materials");
240 
241  $parent_ref_id = $tree->getParentId($this->object->getRefId());
242 
243  $gui = new ilObjectAddNewItemGUI($parent_ref_id);
244  $gui->setDisabledObjectTypes(array("itgr", "sess"));
245  $gui->setAfterCreationCallback($this->object->getRefId());
246  $gui->render();
247 
248  $tab = new ilItemGroupItemsTableGUI($this->gui, $this, "listMaterials");
249  $tpl->setContent($tab->getHTML());
250  }
251 
252  public function saveItemAssignment(): void
253  {
254  $ilCtrl = $this->ctrl;
255 
256  $this->checkPermission("write");
257 
258  $item_group_items = new ilItemGroupItems($this->object->getRefId());
259  $items = $this->ig_request->getItems();
260  $item_group_items->setItems($items);
261  $item_group_items->update();
262 
263  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
264  $ilCtrl->redirect($this, "listMaterials");
265  }
266 
267  public function getTemplate(): void
268  {
269  $this->tpl->loadStandardTemplate();
270  }
271 
272  protected function setTabs(): void
273  {
274  $ilAccess = $this->access;
275  $ilTabs = $this->tabs;
276  $ilHelp = $this->help;
277  $lng = $this->lng;
278  $tree = $this->tree;
279 
280  $ilHelp->setScreenIdComponent("itgr");
281 
282  $parent_ref_id = $tree->getParentId($this->object->getRefId());
283  $parent_obj_id = ilObject::_lookupObjId($parent_ref_id);
284  $parent_type = ilObject::_lookupType($parent_obj_id);
285 
286  $ilTabs->setBackTarget(
287  $lng->txt('obj_' . $parent_type),
288  ilLink::_getLink($parent_ref_id),
289  "_top"
290  );
291 
292  if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
293  $ilTabs->addTab(
294  'materials',
295  $lng->txt('itgr_materials'),
296  $this->ctrl->getLinkTarget($this, 'listMaterials')
297  );
298 
299  $ilTabs->addTab(
300  'settings',
301  $lng->txt('settings'),
302  $this->ctrl->getLinkTarget($this, 'edit')
303  );
304  }
305 
306  if ($ilAccess->checkAccess("edit_permission", "", $this->object->getRefId())) {
307  $ilTabs->addTab(
308  "perm_settings",
309  $lng->txt('perm_settings'),
310  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm")
311  );
312  }
313  }
314 
315  protected function setSettingsSubTabs(string $active_tab = "general"): void
316  {
317  $this->tabs_gui->addSubTab(
318  "general",
319  $this->lng->txt("settings"),
320  $this->ctrl->getLinkTarget($this, "edit")
321  );
322 
323  $this->tabs_gui->addSubTab(
324  "settings_trans",
325  $this->lng->txt("obj_multilinguality"),
326  $this->ctrl->getLinkTargetByClass("ilobjecttranslationgui", "")
327  );
328  $this->tabs_gui->activateTab("settings");
329  $this->tabs_gui->activateSubTab($active_tab);
330  }
331 
332  public static function _goto(string $a_target): void
333  {
334  global $DIC;
335  $main_tpl = $DIC->ui()->mainTemplate();
336 
337  $ilAccess = $DIC->access();
338  $lng = $DIC->language();
339  $tree = $DIC->repositoryTree();
340 
341  $targets = explode('_', $a_target);
342  $ref_id = $targets[0];
343  $par_id = $tree->getParentId($ref_id);
344 
345  if ($ilAccess->checkAccess("read", "", $par_id)) {
346  ilUtil::redirect(ilLink::_getLink($par_id));
347  exit;
348  } elseif ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
349  $main_tpl->setOnScreenMessage('failure', sprintf(
350  $lng->txt("msg_no_perm_read_item"),
352  ), true);
354  }
355 
356  throw new ilPermissionException($lng->txt("msg_no_perm_read"));
357  }
358 
359  public function gotoParent(): void
360  {
361  $ilAccess = $this->access;
362  $tree = $this->tree;
363 
364  $ref_id = $this->object->getRefId();
365  $par_id = $tree->getParentId($ref_id);
366 
367  if ($ilAccess->checkAccess("read", "", $par_id)) {
368  ilUtil::redirect(ilLink::_getLink($par_id));
369  exit;
370  }
371  }
372 
376  public function afterSaveCallback(ilObject $a_obj): void
377  {
378  // add new object to materials
379  $items = new ilItemGroupItems($this->object->getRefId());
380  $items->addItem($a_obj->getRefId());
381  $items->update();
382  }
383 
387  protected function getEditFormCustomValues(array &$a_values): void
388  {
389  $a_values["show_title"] = !$this->object->getHideTitle();
390  $a_values["behaviour"] = $this->object->getBehaviour();
391  $a_values["list_presentation"] = $this->object->getListPresentation();
392  $a_values["tile_size"] = $this->object->getTileSize();
393  }
394 
395  protected function updateCustom(ilPropertyFormGUI $form): void
396  {
397  $this->object->setHideTitle(!$form->getInput("show_title"));
398  $behaviour = ($form->getInput("show_title"))
399  ? $form->getInput("behaviour")
401  $this->object->setBehaviour($behaviour);
402  $this->object->setListPresentation($form->getInput("list_presentation"));
403  $this->object->setTileSize($form->getInput("tile_size"));
404  }
405 
406  protected function initCreateForm(string $new_type): ilPropertyFormGUI
407  {
408  $form = parent::initCreateForm($new_type);
409  $form->removeItemByPostVar("desc");
410  return $form;
411  }
412 }
checkPermission(string $perm, string $cmd="", string $type="", int $ref_id=null)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
exit
Definition: login.php:29
ILIAS ItemGroup InternalGUIService $gui
This class represents a selection list property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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...
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
New implementation of ilObjectGUI.
const ROOT_FOLDER_ID
Definition: constants.php:32
afterSave(ilObject $new_object)
removeItemByPostVar(string $a_post_var, bool $a_remove_unused_headers=false)
Help GUI class.
getDidacticTemplateVar(string $type)
Get didactic template setting from creation screen.
initEditCustomForm(ilPropertyFormGUI $form)
setSettingsSubTabs(string $active_tab="general")
prepareOutput(bool $show_sub_objects=true)
loadLanguageModule(string $a_module)
Load language module.
getEditFormCustomValues(array &$a_values)
Get edit form values (custom part)
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
initCreationForms(string $new_type)
addExternalEditFormCustom(ilPropertyFormGUI $form)
static _lookupObjId(int $ref_id)
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addItem(int $a_item_ref_id)
This class represents a property in a property form.
__construct(VocabulariesInterface $vocabularies)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $node_id=null)
static _lookupTitle(int $obj_id)
setContent(string $a_html)
Sets content for standard template.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initDidacticTemplate(ilPropertyFormGUI $form)
ilGlobalTemplateInterface $tpl
static getAll()
Get all behaviours.
string $key
Consumer key/client ID value.
Definition: System.php:193
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...
initCreateForm(string $new_type)
getParentId(int $a_node_id)
get parent id of given node
$txt
Definition: error.php:14
static redirect(string $a_script)
User Interface class for item groups.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
updateCustom(ilPropertyFormGUI $form)
ilLocatorGUI $locator
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
__construct(int $a_id=0, int $a_id_type=self::REPOSITORY_NODE_ID, int $a_parent_node_id=0)
static _lookupType(int $id, bool $reference=false)
static _goto(string $a_target)
addHeaderAction()
Add header action menu.
afterSaveCallback(ilObject $a_obj)
Custom callback after object is created (in parent container)
StandardGUIRequest $ig_request
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
GUI class for object translation handling.
static _gotoRepositoryRoot(bool $raise_error=false)
Goto repository root.
ilAccessHandler $access