ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjItemGroupGUI.php
Go to the documentation of this file.
1<?php
2
21
31{
32 protected \ILIAS\ItemGroup\InternalGUIService $gui;
34 protected ilTabsGUI $tabs;
35 protected ilHelpGUI $help;
36
37 public function __construct(
38 int $a_id = 0,
39 int $a_id_type = self::REPOSITORY_NODE_ID,
40 int $a_parent_node_id = 0
41 ) {
42 global $DIC;
43 parent::__construct($a_id, $a_id_type, $a_parent_node_id);
44
45 $this->lng = $DIC->language();
46 $this->tabs = $DIC->tabs();
47 $this->access = $DIC->access();
48 $this->tpl = $DIC["tpl"];
49 $this->ctrl = $DIC->ctrl();
50 $this->locator = $DIC["ilLocator"];
51 $this->tree = $DIC->repositoryTree();
52 $this->help = $DIC["ilHelp"];
53 $this->gui = $DIC->itemGroup()->internal()->gui();
54 $this->ig_request = $this->gui
55 ->standardRequest();
56 }
57
58 protected function afterConstructor(): void
59 {
61
62 $lng->loadLanguageModule("itgr");
63 $this->ctrl->saveParameter($this, array("ref_id"));
64 }
65
66 final public function getType(): string
67 {
68 return "itgr";
69 }
70
71 public function executeCommand(): void
72 {
73 $ilTabs = $this->tabs;
74 $next_class = $this->ctrl->getNextClass($this);
75
76 switch ($next_class) {
77 case 'ilpermissiongui':
78 $this->prepareOutput();
79 $ilTabs->activateTab("perm_settings");
80 $this->addHeaderAction();
81 $perm_gui = new ilPermissionGUI($this);
82 $this->ctrl->forwardCommand($perm_gui);
83 break;
84
85 case "ilcommonactiondispatchergui":
87 $this->ctrl->forwardCommand($gui);
88 break;
89
90 case strtolower(TranslationGUI::class):
91 $this->checkPermissionBool("write");
92 $this->prepareOutput();
93 $this->setSettingsSubTabs("settings_trans");
94 $transgui = new TranslationGUI(
95 $this->getObject(),
96 $this->lng,
97 $this->access,
98 $this->user,
99 $this->ctrl,
100 $this->tpl,
101 $this->ui_factory,
102 $this->ui_renderer,
103 $this->http,
104 $this->refinery,
105 $this->toolbar
106 );
107 $transgui->supportContentTranslation(false);
108 $this->ctrl->forwardCommand($transgui);
109 break;
110
111 case 'ildidactictemplategui':
112 $this->checkPermissionBool("write");
113 $this->prepareOutput();
114 $this->ctrl->setReturn($this, 'edit');
115 $did = new ilDidacticTemplateGUI($this, $this->ig_request->getDidactivTemplateId());
116 $this->ctrl->forwardCommand($did);
117 break;
118
119 default:
120 $cmd = $this->ctrl->getCmd("listMaterials");
121 $this->prepareOutput();
122 $this->addHeaderAction();
123 $this->$cmd();
124 break;
125 }
126 }
127
128 public function addLocatorItems(): void
129 {
130 $ilLocator = $this->locator;
131 $ilAccess = $this->access;
132
133 if (is_object($this->object) && $ilAccess->checkAccess("write", "", $this->object->getRefId())) {
134 $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "listMaterials"), "", $this->requested_ref_id);
135 }
136 }
137
138 protected function initEditCustomForm(ilPropertyFormGUI $form): void
139 {
140 $form->removeItemByPostVar("desc");
141
142 // Show didactic template type
143 $this->initDidacticTemplate($form);
144
145 // presentation
146 $pres = new ilFormSectionHeaderGUI();
147 $pres->setTitle($this->lng->txt('obj_presentation'));
148 $form->addItem($pres);
149
150 // show title
151 $cb = new ilCheckboxInputGUI($this->lng->txt("itgr_show_title"), "show_title");
152 $cb->setInfo($this->lng->txt("itgr_show_title_info"));
153 $form->addItem($cb);
154
155 // behaviour
156 $options = ilItemGroupBehaviour::getAll();
157 $si = new ilSelectInputGUI($this->lng->txt("itgr_behaviour"), "behaviour");
158 $si->setInfo($this->lng->txt("itgr_behaviour_info"));
159 $si->setOptions($options);
160 $cb->addSubItem($si);
161
162 // tile/list
163 $lpres = new ilRadioGroupInputGUI($this->lng->txt('itgr_list_presentation'), "list_presentation");
164
165 $std_list = new ilRadioOption($this->lng->txt('itgr_list_default'), "");
166 $std_list->setInfo($this->lng->txt('itgr_list_default_info'));
167 $lpres->addOption($std_list);
168
169 $item_list = new ilRadioOption($this->lng->txt('itgr_list'), "list");
170 $lpres->addOption($item_list);
171
172 $tile_view = new ilRadioOption($this->lng->txt('itgr_tile'), "tile");
173 $lpres->addOption($tile_view);
174
175 // tile size
176 $si = new ilRadioGroupInputGUI($this->lng->txt("itgr_tile_size"), "tile_size");
177 $dummy_container = new ilContainer();
178 $this->lng->loadLanguageModule("cont");
179 foreach ($dummy_container->getTileSizes() as $key => $txt) {
180 $op = new ilRadioOption($txt, $key);
181 $si->addOption($op);
182 }
183 $tile_view->addSubItem($si);
184 $si->setValue($this->object->getTileSize());
185
186 $lpres->setValue($this->object->getListPresentation());
187 $form->addItem($lpres);
188 }
189
190 public function edit(): void
191 {
192 if (!$this->checkPermissionBool("write")) {
193 $this->error->raiseError($this->lng->txt("msg_no_perm_write"), $this->error->MESSAGE);
194 }
195
196 $this->tabs_gui->activateTab("settings");
197
198 $form = $this->initEditForm();
199 $values = $this->getEditFormValues();
200 if ($values) {
201 $form->setValuesByArray($values, true);
202 }
203
204 $this->addExternalEditFormCustom($form);
205
206 $this->tpl->setContent($form->getHTML());
207 $this->setSettingsSubTabs("general");
208 }
209
210 protected function afterUpdate(): void
211 {
212 // check if template is changed
214 $this->object->getRefId()
215 );
216 $new_tpl_id = $this->getDidacticTemplateVar('dtpl');
217
218 if ($new_tpl_id !== $current_tpl_id) {
219 $this->ctrl->setParameterByClass(ilDidacticTemplateGUI::class, "didactic_type", $new_tpl_id);
220 $this->ctrl->redirectByClass(ilDidacticTemplateGUI::class, "confirmTemplateSwitch");
221 return;
222 }
223 parent::afterUpdate();
224 }
225
226 public function listMaterials(): void
227 {
229 $ilTabs = $this->tabs;
231
232 $this->checkPermission("write");
233
234 $ilTabs->activateTab("materials");
235
236 $parent_ref_id = $tree->getParentId($this->object->getRefId());
237 $parent_type = ilObject::_lookupType($parent_ref_id, true);
238 $parent_gui_class = 'ilObj' . $this->obj_definition->getClassName($parent_type) . 'GUI';
239 $this->ctrl->setParameterByClass($parent_gui_class, 'ref_id', $parent_ref_id);
243 $parent_gui_class,
244 $this->object->getRefId()
245 )
246 );
247 $gui->render();
248 $this->ctrl->clearParameterByClass($parent_gui_class, 'ref_id');
249
250 $tab = new ilItemGroupItemsTableGUI($this->gui, $this, "listMaterials");
251 $tpl->setContent($tab->getHTML());
252 }
253
254 public function getCreatableObjectTypes(): array
255 {
256 $parent_ref_id = $this->tree->getParentId($this->object->getRefId());
257 $parent_type = ilObject::_lookupType($parent_ref_id, true);
258 $parent_gui_class = 'ilObj' . $this->obj_definition->getClassName($parent_type) . 'GUI';
259 $parent_gui = new $parent_gui_class('', $parent_ref_id, true, false);
260 $types = $parent_gui->getCreatableObjectTypes();
261 foreach (array_merge(['itgr', 'sess' ], $this->obj_definition->getSideBlockTypes()) as $type_to_remove) {
262 unset($types[$type_to_remove]);
263 }
264 return $types;
265 }
266
267 public function saveItemAssignment(): void
268 {
269 $ilCtrl = $this->ctrl;
270
271 $this->checkPermission("write");
272
273 $item_group_items = new ilItemGroupItems($this->object->getRefId());
274 $items = $this->ig_request->getItems();
275 $item_group_items->setItems($items);
276 $item_group_items->update();
277
278 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
279 $ilCtrl->redirect($this, "listMaterials");
280 }
281
282 public function getTemplate(): void
283 {
284 $this->tpl->loadStandardTemplate();
285 }
286
287 protected function setTabs(): void
288 {
289 $ilAccess = $this->access;
290 $ilTabs = $this->tabs;
291 $ilHelp = $this->help;
294
295 $ilHelp->setScreenIdComponent("itgr");
296
297 $parent_ref_id = $tree->getParentId($this->object->getRefId());
298 $parent_obj_id = ilObject::_lookupObjId($parent_ref_id);
299 $parent_type = ilObject::_lookupType($parent_obj_id);
300
301 $ilTabs->setBackTarget(
302 $lng->txt('obj_' . $parent_type),
303 ilLink::_getLink($parent_ref_id),
304 "_top"
305 );
306
307 if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) {
308 $ilTabs->addTab(
309 'materials',
310 $lng->txt('itgr_materials'),
311 $this->ctrl->getLinkTarget($this, 'listMaterials')
312 );
313
314 $ilTabs->addTab(
315 'settings',
316 $lng->txt('settings'),
317 $this->ctrl->getLinkTarget($this, 'edit')
318 );
319 }
320
321 if ($ilAccess->checkAccess("edit_permission", "", $this->object->getRefId())) {
322 $ilTabs->addTab(
323 "perm_settings",
324 $lng->txt('perm_settings'),
325 $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm")
326 );
327 }
328 }
329
330 protected function setSettingsSubTabs(string $active_tab = "general"): void
331 {
332 $this->tabs_gui->addSubTab(
333 "general",
334 $this->lng->txt("settings"),
335 $this->ctrl->getLinkTarget($this, "edit")
336 );
337
338 $this->tabs_gui->addSubTab(
339 "settings_trans",
340 $this->lng->txt("obj_multilinguality"),
341 $this->ctrl->getLinkTargetByClass(TranslationGUI::class, "")
342 );
343 $this->tabs_gui->activateTab("settings");
344 $this->tabs_gui->activateSubTab($active_tab);
345 }
346
347 public static function _goto(string $a_target): void
348 {
349 global $DIC;
350 $main_tpl = $DIC->ui()->mainTemplate();
351
352 $ilAccess = $DIC->access();
353 $lng = $DIC->language();
354 $tree = $DIC->repositoryTree();
355
356 $targets = explode('_', $a_target);
357 $ref_id = $targets[0];
358 $par_id = $tree->getParentId($ref_id);
359
360 if ($ilAccess->checkAccess("read", "", $par_id)) {
361 ilUtil::redirect(ilLink::_getLink($par_id));
362 exit;
363 } elseif ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
364 $main_tpl->setOnScreenMessage('failure', sprintf(
365 $lng->txt("msg_no_perm_read_item"),
367 ), true);
369 }
370
371 throw new ilPermissionException($lng->txt("msg_no_perm_read"));
372 }
373
374 public function gotoParent(): void
375 {
376 $ilAccess = $this->access;
378
379 $ref_id = $this->object->getRefId();
380 $par_id = $tree->getParentId($ref_id);
381
382 if ($ilAccess->checkAccess("read", "", $par_id)) {
383 ilUtil::redirect(ilLink::_getLink($par_id));
384 exit;
385 }
386 }
387
391 public function afterSaveCallback(ilObject $a_obj): void
392 {
393 // add new object to materials
394 $items = new ilItemGroupItems($this->object->getRefId());
395 $items->addItem($a_obj->getRefId());
396 $items->update();
397 }
398
402 protected function getEditFormCustomValues(array &$a_values): void
403 {
404 $a_values["show_title"] = !$this->object->getHideTitle();
405 $a_values["behaviour"] = $this->object->getBehaviour();
406 $a_values["list_presentation"] = $this->object->getListPresentation();
407 $a_values["tile_size"] = $this->object->getTileSize();
408 }
409
410 protected function updateCustom(ilPropertyFormGUI $form): void
411 {
412 $this->object->setHideTitle(!$form->getInput("show_title"));
413 $behaviour = ($form->getInput("show_title"))
414 ? $form->getInput("behaviour")
416 $this->object->setBehaviour($behaviour);
417 $this->object->setListPresentation($form->getInput("list_presentation"));
418 $this->object->setTileSize($form->getInput("tile_size"));
419 }
420
421 protected function initCreateForm(string $new_type): \ILIAS\UI\Component\Input\Container\Form\Standard
422 {
423 $object = $this->getObject();
424 if ($object === null) {
425 $object = new ilObject();
426 }
427 $form_fields['title'] = $this->ui_factory->input()->field()->text($this->lng->txt('title'))
428 ->withMaxLength(ilObject::TITLE_LENGTH)
429 ->withRequired(true);
430
431 $didactic_templates = $this->didacticTemplatesToForm();
432
433 if ($didactic_templates !== null) {
434 $form_fields['didactic_templates'] = $didactic_templates;
435 }
436
437 return $this->ui_factory->input()->container()->form()->standard(
438 $this->ctrl->getFormAction($this, 'save'),
439 $form_fields
440 )->withSubmitLabel($this->lng->txt($new_type . '_add'));
441 }
442
443 public function save(): void
444 {
445 // create permission is already checked in createObject. This check here is done to prevent hacking attempts
446 if (!$this->checkPermissionBool("create", "", $this->requested_new_type)) {
447 $this->error->raiseError($this->lng->txt("no_create_permission"), $this->error->MESSAGE);
448 }
449
450 $this->lng->loadLanguageModule($this->requested_new_type);
451 $this->ctrl->setParameter($this, "new_type", $this->requested_new_type);
452
453 $form = $this->initCreateForm($this->requested_new_type);
454 $data = $form->withRequest($this->request)->getData();
455 if ($data === null) {
456 $this->tpl->setContent($this->getCreationFormsHTML($form));
457 return;
458 }
459
460 $this->ctrl->setParameter($this, 'new_type', '');
461
462 $new_obj = new ilObjItemGroup();
463 $new_obj->setType($this->requested_new_type);
464 $new_obj->processAutoRating();
465 $new_obj->setTitle($data['title']);
466 $new_obj->create();
467
468 $this->putObjectInTree($new_obj);
469
470 $dtpl = $data['didactic_templates'] ?? null;
471 if ($dtpl !== null) {
472 $dtpl_id = $this->parseDidacticTemplateVar($dtpl, 'dtpl');
473 $new_obj->applyDidacticTemplate($dtpl_id);
474 }
475
476 $this->ctrl->setParameterByClass(self::class, 'ref_id', $new_obj->getRefId());
477 $this->tpl->setOnScreenMessage('success', $this->lng->txt("object_added"), true);
478 $this->ctrl->redirectByClass(self::class, "listMaterials");
479 }
480}
Render add new item selector.
error(string $a_errmsg)
This class represents a checkbox property in a property form.
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
Class ilContainer.
GUI class for didactic template settings inside repository objects.
This class represents a section header in a property form.
Help GUI class.
static getAll()
Get all behaviours.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
loadLanguageModule(string $a_module)
Load language module.
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...
User Interface class for item groups.
afterUpdate()
Post (successful) object update hook.
getType()
Functions that must be overwritten.
afterConstructor()
Do anything that should be done after constructor in here.
__construct(int $a_id=0, int $a_id_type=self::REPOSITORY_NODE_ID, int $a_parent_node_id=0)
addLocatorItems()
Functions to be overwritten.
ILIAS ItemGroup InternalGUIService $gui
setTabs()
create tabs (repository/workspace switch)
StandardGUIRequest $ig_request
getEditFormCustomValues(array &$a_values)
Get edit form values (custom part)
initEditCustomForm(ilPropertyFormGUI $form)
Add custom fields to update form.
initCreateForm(string $new_type)
executeCommand()
execute command
setSettingsSubTabs(string $active_tab="general")
afterSaveCallback(ilObject $a_obj)
Custom callback after object is created (in parent container)
static _goto(string $a_target)
updateCustom(ilPropertyFormGUI $form)
Insert custom update form values into object.
Class ilObjItemGroup.
New implementation of ilObjectGUI.
ilAccessHandler $access
ilGlobalTemplateInterface $tpl
checkPermissionBool(string $perm, string $cmd="", string $type="", ?int $node_id=null)
putObjectInTree(ilObject $obj, ?int $parent_node_id=null)
Add object to tree at given position.
checkPermission(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
ilLocatorGUI $locator
prepareOutput(bool $show_sub_objects=true)
buildAddNewItemElements(array $subtypes, string $create_target_class=ilRepositoryGUI::class, ?int $redirect_target_ref_id=null,)
static _gotoRepositoryRoot(bool $raise_error=false)
Goto repository root.
addExternalEditFormCustom(ilPropertyFormGUI $form)
getCreationFormsHTML(StandardForm|ilPropertyFormGUI|array $form)
initDidacticTemplate(ilPropertyFormGUI $form)
addHeaderAction()
Add header action menu.
getDidacticTemplateVar(string $type)
Get didactic template setting from creation screen.
parseDidacticTemplateVar(string $var, string $type)
Class ilObject Basic functions for all objects.
static _lookupType(int $id, bool $reference=false)
const TITLE_LENGTH
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
This class represents a property form user interface.
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-...
removeItemByPostVar(string $a_post_var, bool $a_remove_unused_headers=false)
This class represents a property in a property form.
This class represents an option in a radio group.
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...
getParentId(int $a_node_id)
get parent id of given node
static redirect(string $a_script)
const ROOT_FOLDER_ID
Definition: constants.php:32
exit
$txt
Definition: error.php:31
setContent(string $a_html)
Sets content for standard template.
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26