ILIAS  release_8 Revision v8.24
class.ilObjectPluginGUI.php
Go to the documentation of this file.
1<?php
2
20
25abstract class ilObjectPluginGUI extends ilObject2GUI
26{
29 protected ilTabsGUI $tabs;
30 protected ?ilPlugin $plugin = null;
33
34 public function __construct(
35 int $a_ref_id = 0,
36 int $a_id_type = self::REPOSITORY_NODE_ID,
37 int $a_parent_node_id = 0
38 ) {
40 global $DIC;
41
42 $this->slot_request = $DIC->repository()
43 ->internal()
44 ->gui()
45 ->pluginSlot()
46 ->request();
47
48 $this->ctrl = $DIC->ctrl();
49 $this->tpl = $DIC["tpl"];
50 $this->access = $DIC->access();
51 $this->lng = $DIC->language();
52 $this->nav_history = $DIC["ilNavigationHistory"];
53 $this->tabs = $DIC->tabs();
54 $this->locator = $DIC["ilLocator"];
55 $this->user = $DIC->user();
56 $this->component_factory = $DIC["component.factory"];
57 $this->component_repository = $DIC["component.repository"];
58 parent::__construct($a_ref_id, $a_id_type, $a_parent_node_id);
59 $this->plugin = $this->getPlugin();
60 }
61
62 public function executeCommand(): void
63 {
64 $ilCtrl = $this->ctrl;
66 $ilAccess = $this->access;
68 $ilNavigationHistory = $this->nav_history;
69 $ilTabs = $this->tabs;
70
71 // get standard template (includes main menu and general layout)
73
74 // set title
75 if (!$this->getCreationMode()) {
76 $tpl->setTitle($this->object->getTitle());
77 $tpl->setTitleIcon(ilObject::_getIcon($this->object->getId()));
78
79 // set tabs
80 if (strtolower($this->slot_request->getBaseClass()) !== "iladministrationgui") {
81 $this->setTabs();
82 $this->setLocator();
83 } else {
84 $this->addAdminLocatorItems();
86 $this->setAdminTabs();
87 }
88
89 if ($ilAccess->checkAccess('read', '', $this->object->getRefId())) {
90 $ilNavigationHistory->addItem(
91 $this->object->getRefId(),
92 ilLink::_getLink($this->object->getRefId(), $this->object->getType()),
93 $this->object->getType()
94 );
95 }
96 } else {
97 // show info of parent
101 $this->slot_request->getRefId()
102 ), "big"),
104 $this->slot_request->getRefId(),
105 true
106 ))
107 );
108 $this->setLocator();
109 }
110
111 $next_class = $this->ctrl->getNextClass($this);
112 $cmd = $this->ctrl->getCmd();
113
114 switch ($next_class) {
115 case "ilinfoscreengui":
116 $this->checkPermission("visible");
117 $this->infoScreen(); // forwards command
118 break;
119
120 case 'ilpermissiongui':
121 $perm_gui = new ilPermissionGUI($this);
122 $ilTabs->setTabActive("perm_settings");
123 $ilCtrl->forwardCommand($perm_gui);
124 break;
125
126 case 'ilobjectcopygui':
127 $cp = new ilObjectCopyGUI($this);
128 $cp->setType($this->getType());
129 $this->ctrl->forwardCommand($cp);
130 break;
131
132 case 'ilexportgui':
133 // only if plugin supports it?
134 $this->tabs->setTabActive("export");
135 $exp = new ilExportGUI($this);
136 $exp->addFormat('xml');
137 $this->ctrl->forwardCommand($exp);
138 break;
139
140 case 'illearningprogressgui':
141 $user_id = $this->user->getId();
142 if ($this->slot_request->getUserId() > 0 && $this->access->checkAccess(
143 'write',
144 "",
145 $this->object->getRefId()
146 )) {
147 $user_id = $this->slot_request->getUserId();
148 }
149 $ilTabs->setTabActive("learning_progress");
150 $new_gui = new ilLearningProgressGUI(
152 $this->object->getRefId(),
153 $user_id
154 );
155 $this->ctrl->forwardCommand($new_gui);
156 break;
157 case 'ilcommonactiondispatchergui':
159 $this->ctrl->forwardCommand($gui);
160 break;
161 default:
162 if ($cmd === "save" || $this->getCreationMode()) {
163 $this->$cmd();
164 return;
165 }
166 if (!$cmd) {
167 $cmd = $this->getStandardCmd();
168 }
169 if ($cmd === "infoScreen") {
170 $ilCtrl->setCmd("showSummary");
171 $ilCtrl->setCmdClass("ilinfoscreengui");
172 $this->infoScreen();
173 } else {
174 $this->performCommand($cmd);
175 }
176 break;
177 }
178
179 if (!$this->getCreationMode()) {
181 }
182 }
183
184 protected function addLocatorItems(): void
185 {
186 $ilLocator = $this->locator;
187
188 if (!$this->getCreationMode()) {
189 $ilLocator->addItem(
190 $this->object->getTitle(),
191 $this->ctrl->getLinkTarget($this, $this->getStandardCmd()),
192 "",
193 $this->slot_request->getRefId()
194 );
195 }
196 }
197
202 protected function getPlugin(): ilPlugin
203 {
204 if (!$this->plugin) {
205 $this->plugin = $this->component_factory->getPlugin($this->getType());
206 }
207 return $this->plugin;
208 }
209
210 final protected function txt(string $a_var): string
211 {
212 return $this->getPlugin()->txt($a_var);
213 }
214
218 protected function getCreationFormTitle(int $a_form_type): string
219 {
220 switch ($a_form_type) {
221 case self::CFORM_NEW:
222 return $this->txt($this->getType() . "_new");
223
225 return $this->lng->txt("import");
226
228 return $this->txt("objs_" . $this->getType() . "_duplicate");
229 }
230 return "";
231 }
232
237 protected function initCreationForms(string $new_type): array
238 {
239 $forms = [];
240 $forms[self::CFORM_NEW] = $this->initCreateForm($new_type);
241
242 if ($this->supportsExport()) {
243 $forms[self::CFORM_IMPORT] = $this->initImportForm($new_type);
244 }
245 if ($this->supportsCloning()) {
246 $forms[self::CFORM_CLONE] = $this->fillCloneTemplate(null, $new_type);
247 }
248
249 return $forms;
250 }
251
255 protected function supportsCloning(): bool
256 {
257 return true;
258 }
259
263 protected function initCreateForm(string $new_type): ilPropertyFormGUI
264 {
265 $form = new ilPropertyFormGUI();
266 $form->setTarget("_top");
267 $form->setFormAction($this->ctrl->getFormAction($this, "save"));
268 $form->setTitle($this->txt($new_type . "_new"));
269
270 // title
271 $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
272 $ti->setSize(min(40, ilObject::TITLE_LENGTH));
273 $ti->setMaxLength(ilObject::TITLE_LENGTH);
274 $ti->setRequired(true);
275 $form->addItem($ti);
276
277 // description
278 $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "desc");
279 $ta->setCols(40);
280 $ta->setRows(2);
281 $form->addItem($ta);
282
283 $form->addCommandButton("save", $this->txt($new_type . "_add"));
284 $form->addCommandButton("cancel", $this->lng->txt("cancel"));
285
286 return $form;
287 }
288
292 protected function initEditForm(): ilPropertyFormGUI
293 {
295 $ilCtrl = $this->ctrl;
296
297 $form = new ilPropertyFormGUI();
298 $form->setTarget("_top");
299 $form->setFormAction($ilCtrl->getFormAction($this, "update"));
300 $form->setTitle($lng->txt("edit"));
301
302 // title
303 $ti = new ilTextInputGUI($lng->txt("title"), "title");
304 $ti->setSize(min(40, ilObject::TITLE_LENGTH));
305 $ti->setMaxLength(ilObject::TITLE_LENGTH);
306 $ti->setRequired(true);
307 $form->addItem($ti);
308
309 // description
310 $ta = new ilTextAreaInputGUI($lng->txt("description"), "desc");
311 $ta->setCols(40);
312 $ta->setRows(2);
313 $form->addItem($ta);
314
315 $form->addCommandButton("update", $lng->txt("save"));
316 // $this->form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
317
318 return $form;
319 }
320
326 protected function initImportForm(string $new_type): ilPropertyFormGUI
327 {
328 $form = new ilPropertyFormGUI();
329 $form->setTarget("_top");
330 $form->setFormAction($this->ctrl->getFormAction($this, "importFile"));
331 $form->setTitle($this->lng->txt("import"));
332
333 $fi = new ilFileInputGUI($this->lng->txt("import_file"), "importfile");
334 $fi->setSuffixes(["zip"]);
335 $fi->setRequired(true);
336 $form->addItem($fi);
337
338 $form->addCommandButton("importFile", $this->lng->txt("import"));
339 $form->addCommandButton("cancel", $this->lng->txt("cancel"));
340
341 return $form;
342 }
343
344 protected function afterSave(ilObject $new_object): void
345 {
346 $ilCtrl = $this->ctrl;
347 // always send a message
348 $this->tpl->setOnScreenMessage('success', $this->lng->txt("object_added"), true);
349
350 $ilCtrl->setTargetScript('ilias.php');
351 $ilCtrl->setParameterByClass(get_class($this), "ref_id", $new_object->getRefId());
352 $ilCtrl->redirectByClass(["ilobjplugindispatchgui", get_class($this)], $this->getAfterCreationCmd());
353 }
354
358 abstract public function getAfterCreationCmd(): string;
359
360 abstract public function getStandardCmd(): string;
361
362 abstract public function performCommand(string $cmd): void;
363
364 public function addInilPluginAdminfoTab(): void
365 {
366 $ilAccess = $this->access;
367 $ilTabs = $this->tabs;
368
369 // info screen
370 if ($ilAccess->checkAccess('visible', "", $this->object->getRefId())) {
371 $ilTabs->addTarget(
372 "info_short",
373 $this->ctrl->getLinkTargetByClass(
374 "ilinfoscreengui",
375 "showSummary"
376 ),
377 "showSummary"
378 );
379 }
380 }
381
382 public function addPermissionTab(): void
383 {
384 $ilAccess = $this->access;
385 $ilTabs = $this->tabs;
386 $ilCtrl = $this->ctrl;
387
388 // edit permissions
389 if ($ilAccess->checkAccess('edit_permission', "", $this->object->getRefId())) {
390 $ilTabs->addTarget(
391 "perm_settings",
392 $ilCtrl->getLinkTargetByClass("ilpermissiongui", "perm"),
393 ["perm", "info", "owner"],
394 'ilpermissiongui'
395 );
396 }
397 }
398
399 public function addInfoTab(): void
400 {
401 $ilAccess = $this->access;
402 $ilTabs = $this->tabs;
403
404 // info screen
405 if ($ilAccess->checkAccess('visible', "", $this->object->getRefId())) {
406 $ilTabs->addTarget(
407 "info_short",
408 $this->ctrl->getLinkTargetByClass(
409 "ilinfoscreengui",
410 "showSummary"
411 ),
412 "showSummary"
413 );
414 }
415 }
416
417 public function addExportTab(): void
418 {
419 // write
420 if ($this->access->checkAccess('write', "", $this->object->getRefId())) {
421 $this->tabs->addTarget(
422 'export',
423 $this->ctrl->getLinkTargetByClass("ilexportgui", ''),
424 'export',
425 'ilexportgui'
426 );
427 }
428 }
429
430 public function infoScreen(): void
431 {
433 $ilCtrl = $this->ctrl;
434 $ilTabs = $this->tabs;
435
436 $ilTabs->activateTab("info_short");
437
438 $this->checkPermission("visible");
439
440 $info = new ilInfoScreenGUI($this);
441 $info->enablePrivateNotes();
442
443 // general information
444 $lng->loadLanguageModule("meta");
445
446 $this->addInfoItems($info);
447
448 // forward the command
449 $ilCtrl->forwardCommand($info);
450 }
451
455 public function addInfoItems(ilInfoScreenGUI $info): void
456 {
457 }
458
462 public static function _goto(array $a_target): void
463 {
464 global $DIC;
465 $main_tpl = $DIC->ui()->mainTemplate();
466
467 $ilCtrl = $DIC->ctrl();
468 $ilAccess = $DIC->access();
469 $lng = $DIC->language();
470
471 $t = explode("_", $a_target[0]);
472 $ref_id = (int) $t[0];
473 $class_name = $a_target[1];
474
475 if ($ilAccess->checkAccess("read", "", $ref_id)) {
476 $ilCtrl->setTargetScript('ilias.php');
477 $ilCtrl->setParameterByClass($class_name, "ref_id", $ref_id);
478 $ilCtrl->redirectByClass(["ilobjplugindispatchgui", $class_name], "");
479 } elseif ($ilAccess->checkAccess("visible", "", $ref_id)) {
480 $ilCtrl->setTargetScript('ilias.php');
481 $ilCtrl->setParameterByClass($class_name, "ref_id", $ref_id);
482 $ilCtrl->redirectByClass(["ilobjplugindispatchgui", $class_name], "infoScreen");
483 } elseif ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
484 $main_tpl->setOnScreenMessage('failure', sprintf(
485 $lng->txt("msg_no_perm_read_item"),
487 ));
489 }
490 }
491
492 protected function supportsExport(): bool
493 {
495
496 return $component_repository->getPluginSlotById("robj")->getPluginByName($this->getPlugin()->getPluginName())->supportsExport();
497 }
498
499 protected function lookupParentTitleInCreationMode(): string
500 {
502 $this->slot_request->getRefId()
503 ));
504 }
505}
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
setTargetScript(string $a_target_script)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a file property in a property form.
Class ilInfoScreenGUI.
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addItem(string $a_title, string $a_link, string $a_frame="", int $a_ref_id=0, ?string $type=null)
Navigation History of Repository Items.
New implementation of ilObjectGUI.
getType()
Functions that must be overwritten.
setTabs()
create tabs (repository/workspace switch)
ilAccessHandler $access
__construct(int $id=0, int $id_type=self::REPOSITORY_NODE_ID, int $parent_node_id=0)
ilGlobalTemplateInterface $tpl
addAdminLocatorItems(bool $do_not_add_object=false)
should be overwritten to add object specific items (repository items are preloaded)
ilLocatorGUI $locator
setLocator()
set Locator
checkPermission(string $perm, string $cmd="", string $type="", int $ref_id=null)
fillCloneTemplate(?string $tpl_varname, string $type)
Fill object clone template This method can be called from any object GUI class that wants to offer ob...
GUI class for the workflow of copying objects.
static _gotoRepositoryRoot(bool $raise_error=false)
Goto repository root.
setAdminTabs()
set admin tabs
Object GUI class for repository plugins.
initEditForm()
Init object update form.
addInfoItems(ilInfoScreenGUI $info)
Add items to info screen.
getPlugin()
Get plugin object.
executeCommand()
execute command
static _goto(array $a_target)
getAfterCreationCmd()
Cmd that will be redirected to after creation of a new object.
ilComponentRepository $component_repository
ilComponentFactory $component_factory
ilNavigationHistory $nav_history
initCreationForms(string $new_type)
Init creation forms this will create the default creation forms: new, import, clone.
afterSave(ilObject $new_object)
Post (successful) object creation hook.
PluginSlotGUIRequest $slot_request
addLocatorItems()
Functions to be overwritten.
getCreationFormTitle(int $a_form_type)
Use custom creation form titles.
initCreateForm(string $new_type)
Init object creation form.
performCommand(string $cmd)
initImportForm(string $new_type)
Init object import form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupType(int $id, bool $reference=false)
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
const TITLE_LENGTH
static _lookupObjId(int $ref_id)
static _lookupTitle(int $obj_id)
New PermissionGUI (extends from old ilPermission2GUI) RBAC related output.
This class represents a property form user interface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addTarget(string $a_text, string $a_link, $a_cmd="", $a_cmdClass="", string $a_frame="", bool $a_activate=false, bool $a_dir_text=false)
activateTab(string $a_id)
This class represents a text area property in a property form.
This class represents a text property in a property form.
const ROOT_FOLDER_ID
Definition: constants.php:32
global $DIC
Definition: feed.php:28
Readable part of repository interface to ilComponentDataDB.
getPluginSlotById(string $id)
Get pluginslot by id.
setTitleIcon(string $a_icon_path, string $a_icon_desc="")
set title icon
printToStdout(string $part=self::DEFAULT_BLOCK, bool $has_tabs=true, bool $skip_main_menu=false)
setTitle(string $a_title, bool $hidden=false)
Sets title in standard template.
loadStandardTemplate()
This loads the standard template "tpl.adm_content.html" and "tpl.statusline.html" the CONTENT and STA...
setLocator()
Insert locator.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc