ILIAS  trunk Revision v11.0_alpha-1713-gd8962da2f67
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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->checkPermissionBool("write");
101  $this->prepareOutput();
102  $this->ctrl->setReturn($this, 'edit');
103  $did = new ilDidacticTemplateGUI($this, $this->ig_request->getDidactivTemplateId());
104  $this->ctrl->forwardCommand($did);
105  break;
106 
107  default:
108  $cmd = $this->ctrl->getCmd("listMaterials");
109  $this->prepareOutput();
110  $this->addHeaderAction();
111  $this->$cmd();
112  break;
113  }
114  }
115 
116  public function addLocatorItems(): void
117  {
118  $ilLocator = $this->locator;
119  $ilAccess = $this->access;
120 
121  if (is_object($this->object) && $ilAccess->checkAccess("write", "", $this->object->getRefId())) {
122  $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "listMaterials"), "", $this->requested_ref_id);
123  }
124  }
125 
126  protected function initEditCustomForm(ilPropertyFormGUI $form): void
127  {
128  $form->removeItemByPostVar("desc");
129 
130  // Show didactic template type
131  $this->initDidacticTemplate($form);
132 
133  // presentation
134  $pres = new ilFormSectionHeaderGUI();
135  $pres->setTitle($this->lng->txt('obj_presentation'));
136  $form->addItem($pres);
137 
138  // show title
139  $cb = new ilCheckboxInputGUI($this->lng->txt("itgr_show_title"), "show_title");
140  $cb->setInfo($this->lng->txt("itgr_show_title_info"));
141  $form->addItem($cb);
142 
143  // behaviour
144  $options = ilItemGroupBehaviour::getAll();
145  $si = new ilSelectInputGUI($this->lng->txt("itgr_behaviour"), "behaviour");
146  $si->setInfo($this->lng->txt("itgr_behaviour_info"));
147  $si->setOptions($options);
148  $cb->addSubItem($si);
149 
150  // tile/list
151  $lpres = new ilRadioGroupInputGUI($this->lng->txt('itgr_list_presentation'), "list_presentation");
152 
153  $std_list = new ilRadioOption($this->lng->txt('itgr_list_default'), "");
154  $std_list->setInfo($this->lng->txt('itgr_list_default_info'));
155  $lpres->addOption($std_list);
156 
157  $item_list = new ilRadioOption($this->lng->txt('itgr_list'), "list");
158  $lpres->addOption($item_list);
159 
160  $tile_view = new ilRadioOption($this->lng->txt('itgr_tile'), "tile");
161  $lpres->addOption($tile_view);
162 
163  // tile size
164  $si = new ilRadioGroupInputGUI($this->lng->txt("itgr_tile_size"), "tile_size");
165  $dummy_container = new ilContainer();
166  $this->lng->loadLanguageModule("cont");
167  foreach ($dummy_container->getTileSizes() as $key => $txt) {
168  $op = new ilRadioOption($txt, $key);
169  $si->addOption($op);
170  }
171  $tile_view->addSubItem($si);
172  $si->setValue($this->object->getTileSize());
173 
174  $lpres->setValue($this->object->getListPresentation());
175  $form->addItem($lpres);
176  }
177 
178  public function edit(): void
179  {
180  if (!$this->checkPermissionBool("write")) {
181  $this->error->raiseError($this->lng->txt("msg_no_perm_write"), $this->error->MESSAGE);
182  }
183 
184  $this->tabs_gui->activateTab("settings");
185 
186  $form = $this->initEditForm();
187  $values = $this->getEditFormValues();
188  if ($values) {
189  $form->setValuesByArray($values, true);
190  }
191 
192  $this->addExternalEditFormCustom($form);
193 
194  $this->tpl->setContent($form->getHTML());
195  $this->setSettingsSubTabs("general");
196  }
197 
198  protected function afterUpdate(): void
199  {
200  // check if template is changed
202  $this->object->getRefId()
203  );
204  $new_tpl_id = $this->getDidacticTemplateVar('dtpl');
205 
206  if ($new_tpl_id !== $current_tpl_id) {
207  $this->ctrl->setParameterByClass(ilDidacticTemplateGUI::class, "didactic_type", $new_tpl_id);
208  $this->ctrl->redirectByClass(ilDidacticTemplateGUI::class, "confirmTemplateSwitch");
209  return;
210  }
211  parent::afterUpdate();
212  }
213 
214  public function listMaterials(): void
215  {
216  $tree = $this->tree;
217  $ilTabs = $this->tabs;
218  $tpl = $this->tpl;
219 
220  $this->checkPermission("write");
221 
222  $ilTabs->activateTab("materials");
223 
224  $parent_ref_id = $tree->getParentId($this->object->getRefId());
225  $parent_type = ilObject::_lookupType($parent_ref_id, true);
226  $parent_gui_class = 'ilObj' . $this->obj_definition->getClassName($parent_type) . 'GUI';
227  $this->ctrl->setParameterByClass($parent_gui_class, 'ref_id', $parent_ref_id);
230  $this->getCreatableObjectTypes(),
231  $parent_gui_class,
232  $this->object->getRefId()
233  )
234  );
235  $gui->render();
236  $this->ctrl->clearParameterByClass($parent_gui_class, 'ref_id');
237 
238  $tab = new ilItemGroupItemsTableGUI($this->gui, $this, "listMaterials");
239  $tpl->setContent($tab->getHTML());
240  }
241 
242  public function getCreatableObjectTypes(): array
243  {
244  $parent_ref_id = $this->tree->getParentId($this->object->getRefId());
245  $parent_type = ilObject::_lookupType($parent_ref_id, true);
246  $parent_gui_class = 'ilObj' . $this->obj_definition->getClassName($parent_type) . 'GUI';
247  $parent_gui = new $parent_gui_class('', $parent_ref_id, true, false);
248  $types = $parent_gui->getCreatableObjectTypes();
249  foreach (array_merge(['itgr', 'sess' ], $this->obj_definition->getSideBlockTypes()) as $type_to_remove) {
250  unset($types[$type_to_remove]);
251  }
252  return $types;
253  }
254 
255  public function saveItemAssignment(): void
256  {
257  $ilCtrl = $this->ctrl;
258 
259  $this->checkPermission("write");
260 
261  $item_group_items = new ilItemGroupItems($this->object->getRefId());
262  $items = $this->ig_request->getItems();
263  $item_group_items->setItems($items);
264  $item_group_items->update();
265 
266  $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
267  $ilCtrl->redirect($this, "listMaterials");
268  }
269 
270  public function getTemplate(): void
271  {
272  $this->tpl->loadStandardTemplate();
273  }
274 
275  protected function setTabs(): void
276  {
277  $ilAccess = $this->access;
278  $ilTabs = $this->tabs;
279  $ilHelp = $this->help;
280  $lng = $this->lng;
281  $tree = $this->tree;
282 
283  $ilHelp->setScreenIdComponent("itgr");
284 
285  $parent_ref_id = $tree->getParentId($this->object->getRefId());
286  $parent_obj_id = ilObject::_lookupObjId($parent_ref_id);
287  $parent_type = ilObject::_lookupType($parent_obj_id);
288 
289  $ilTabs->setBackTarget(
290  $lng->txt('obj_' . $parent_type),
291  ilLink::_getLink($parent_ref_id),
292  "_top"
293  );
294 
295  if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
296  $ilTabs->addTab(
297  'materials',
298  $lng->txt('itgr_materials'),
299  $this->ctrl->getLinkTarget($this, 'listMaterials')
300  );
301 
302  $ilTabs->addTab(
303  'settings',
304  $lng->txt('settings'),
305  $this->ctrl->getLinkTarget($this, 'edit')
306  );
307  }
308 
309  if ($ilAccess->checkAccess("edit_permission", "", $this->object->getRefId())) {
310  $ilTabs->addTab(
311  "perm_settings",
312  $lng->txt('perm_settings'),
313  $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm")
314  );
315  }
316  }
317 
318  protected function setSettingsSubTabs(string $active_tab = "general"): void
319  {
320  $this->tabs_gui->addSubTab(
321  "general",
322  $this->lng->txt("settings"),
323  $this->ctrl->getLinkTarget($this, "edit")
324  );
325 
326  $this->tabs_gui->addSubTab(
327  "settings_trans",
328  $this->lng->txt("obj_multilinguality"),
329  $this->ctrl->getLinkTargetByClass("ilobjecttranslationgui", "")
330  );
331  $this->tabs_gui->activateTab("settings");
332  $this->tabs_gui->activateSubTab($active_tab);
333  }
334 
335  public static function _goto(string $a_target): void
336  {
337  global $DIC;
338  $main_tpl = $DIC->ui()->mainTemplate();
339 
340  $ilAccess = $DIC->access();
341  $lng = $DIC->language();
342  $tree = $DIC->repositoryTree();
343 
344  $targets = explode('_', $a_target);
345  $ref_id = $targets[0];
346  $par_id = $tree->getParentId($ref_id);
347 
348  if ($ilAccess->checkAccess("read", "", $par_id)) {
349  ilUtil::redirect(ilLink::_getLink($par_id));
350  exit;
351  } elseif ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
352  $main_tpl->setOnScreenMessage('failure', sprintf(
353  $lng->txt("msg_no_perm_read_item"),
355  ), true);
357  }
358 
359  throw new ilPermissionException($lng->txt("msg_no_perm_read"));
360  }
361 
362  public function gotoParent(): void
363  {
364  $ilAccess = $this->access;
365  $tree = $this->tree;
366 
367  $ref_id = $this->object->getRefId();
368  $par_id = $tree->getParentId($ref_id);
369 
370  if ($ilAccess->checkAccess("read", "", $par_id)) {
371  ilUtil::redirect(ilLink::_getLink($par_id));
372  exit;
373  }
374  }
375 
379  public function afterSaveCallback(ilObject $a_obj): void
380  {
381  // add new object to materials
382  $items = new ilItemGroupItems($this->object->getRefId());
383  $items->addItem($a_obj->getRefId());
384  $items->update();
385  }
386 
390  protected function getEditFormCustomValues(array &$a_values): void
391  {
392  $a_values["show_title"] = !$this->object->getHideTitle();
393  $a_values["behaviour"] = $this->object->getBehaviour();
394  $a_values["list_presentation"] = $this->object->getListPresentation();
395  $a_values["tile_size"] = $this->object->getTileSize();
396  }
397 
398  protected function updateCustom(ilPropertyFormGUI $form): void
399  {
400  $this->object->setHideTitle(!$form->getInput("show_title"));
401  $behaviour = ($form->getInput("show_title"))
402  ? $form->getInput("behaviour")
404  $this->object->setBehaviour($behaviour);
405  $this->object->setListPresentation($form->getInput("list_presentation"));
406  $this->object->setTileSize($form->getInput("tile_size"));
407  }
408 
409  protected function initCreateForm(string $new_type): \ILIAS\UI\Component\Input\Container\Form\Standard
410  {
411  $object = $this->getObject();
412  if ($object === null) {
413  $object = new ilObject();
414  }
415  $form_fields['title'] = $this->ui_factory->input()->field()->text($this->lng->txt('title'))
416  ->withMaxLength(ilObject::TITLE_LENGTH)
417  ->withRequired(true);
418 
419  $didactic_templates = $this->didacticTemplatesToForm();
420 
421  if ($didactic_templates !== null) {
422  $form_fields['didactic_templates'] = $didactic_templates;
423  }
424 
425  return $this->ui_factory->input()->container()->form()->standard(
426  $this->ctrl->getFormAction($this, 'save'),
427  $form_fields
428  )->withSubmitLabel($this->lng->txt($new_type . '_add'));
429  }
430 
431  public function save(): void
432  {
433  // create permission is already checked in createObject. This check here is done to prevent hacking attempts
434  if (!$this->checkPermissionBool("create", "", $this->requested_new_type)) {
435  $this->error->raiseError($this->lng->txt("no_create_permission"), $this->error->MESSAGE);
436  }
437 
438  $this->lng->loadLanguageModule($this->requested_new_type);
439  $this->ctrl->setParameter($this, "new_type", $this->requested_new_type);
440 
441  $form = $this->initCreateForm($this->requested_new_type);
442  $data = $form->withRequest($this->request)->getData();
443  if ($data === null) {
444  $this->tpl->setContent($this->getCreationFormsHTML($form));
445  return;
446  }
447 
448  $this->ctrl->setParameter($this, 'new_type', '');
449 
450  $new_obj = new ilObjItemGroup();
451  $new_obj->setType($this->requested_new_type);
452  $new_obj->processAutoRating();
453  $new_obj->setTitle($data['title']);
454  $new_obj->create();
455 
456  $this->putObjectInTree($new_obj);
457 
458  $dtpl = $data['didactic_templates'] ?? null;
459  if ($dtpl !== null) {
460  $dtpl_id = $this->parseDidacticTemplateVar($dtpl, 'dtpl');
461  $new_obj->applyDidacticTemplate($dtpl_id);
462  }
463 
464  $this->ctrl->setParameterByClass(self::class, 'ref_id', $new_obj->getRefId());
465  $this->tpl->setOnScreenMessage('success', $this->lng->txt("object_added"), true);
466  $this->ctrl->redirectByClass(self::class, "listMaterials");
467  }
468 }
This class represents an option in a radio group.
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...
New implementation of ilObjectGUI.
getCreationFormsHTML(StandardForm|ilPropertyFormGUI|array $form)
const ROOT_FOLDER_ID
Definition: constants.php:32
const TITLE_LENGTH
removeItemByPostVar(string $a_post_var, bool $a_remove_unused_headers=false)
Interface Observer Contains several chained tasks and infos about them.
Help GUI class.
getDidacticTemplateVar(string $type)
Get didactic template setting from creation screen.
setContent(string $a_html)
Sets content for standard template.
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-...
addExternalEditFormCustom(ilPropertyFormGUI $form)
static _lookupObjId(int $ref_id)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
addItem(int $a_item_ref_id)
This class represents a property in a property form.
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $node_id=null)
static _lookupTitle(int $obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
initDidacticTemplate(ilPropertyFormGUI $form)
global $DIC
Definition: shib_login.php:22
ilGlobalTemplateInterface $tpl
static getAll()
Get all behaviours.
putObjectInTree(ilObject $obj, ?int $parent_node_id=null)
Add object to tree at given position.
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:31
checkPermission(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
static redirect(string $a_script)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
buildAddNewItemElements(array $subtypes, string $create_target_class=ilRepositoryGUI::class, ?int $redirect_target_ref_id=null,)
Render add new item selector.
User Interface class for item groups.
__construct(Container $dic, ilPlugin $plugin)
updateCustom(ilPropertyFormGUI $form)
ilLocatorGUI $locator
__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)
parseDidacticTemplateVar(string $var, string $type)
exit
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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