ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilObjectPluginGUI.php
Go to the documentation of this file.
1 <?php
2 
20 
25 abstract 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;
65  $tpl = $this->tpl;
66  $ilAccess = $this->access;
67  $lng = $this->lng;
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();
85  $tpl->setLocator();
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"),
103  $lng->txt("obj_" . ilObject::_lookupType(
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  $this->ctrl->redirectByClass(ilInfoScreenGUI::class, "showSummary");
171  } else {
172  $this->performCommand($cmd);
173  }
174  break;
175  }
176 
177  if (!$this->getCreationMode()) {
178  $tpl->printToStdout();
179  }
180  }
181 
182  protected function addLocatorItems(): void
183  {
184  $ilLocator = $this->locator;
185 
186  if (!$this->getCreationMode()) {
187  $ilLocator->addItem(
188  $this->object->getTitle(),
189  $this->ctrl->getLinkTarget($this, $this->getStandardCmd()),
190  "",
191  $this->slot_request->getRefId()
192  );
193  }
194  }
195 
200  protected function getPlugin(): ilPlugin
201  {
202  if (!$this->plugin) {
203  $this->plugin = $this->component_factory->getPlugin($this->getType());
204  }
205  return $this->plugin;
206  }
207 
208  final protected function txt(string $a_var): string
209  {
210  return $this->getPlugin()->txt($a_var);
211  }
212 
216  protected function getCreationFormTitle(): string
217  {
218  return $this->txt($this->getType() . "_new");
219  }
220 
224  protected function supportsCloning(): bool
225  {
226  return true;
227  }
228 
232  protected function initEditForm(): ilPropertyFormGUI
233  {
234  $lng = $this->lng;
235  $ilCtrl = $this->ctrl;
236 
237  $form = new ilPropertyFormGUI();
238  $form->setTarget("_top");
239  $form->setFormAction($ilCtrl->getFormAction($this, "update"));
240  $form->setTitle($lng->txt("edit"));
241 
242  // title
243  $ti = new ilTextInputGUI($lng->txt("title"), "title");
244  $ti->setSize(min(40, ilObject::TITLE_LENGTH));
245  $ti->setMaxLength(ilObject::TITLE_LENGTH);
246  $ti->setRequired(true);
247  $form->addItem($ti);
248 
249  // description
250  $ta = new ilTextAreaInputGUI($lng->txt("description"), "desc");
251  $ta->setCols(40);
252  $ta->setRows(2);
253  $form->addItem($ta);
254 
255  $form->addCommandButton("update", $lng->txt("save"));
256  // $this->form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
257 
258  return $form;
259  }
260 
261  protected function afterSave(ilObject $new_object): void
262  {
263  $ilCtrl = $this->ctrl;
264  // always send a message
265  $this->tpl->setOnScreenMessage('success', $this->lng->txt("object_added"), true);
266 
267  $ilCtrl->setTargetScript('ilias.php');
268  $ilCtrl->setParameterByClass(get_class($this), "ref_id", $new_object->getRefId());
269  $ilCtrl->redirectByClass(["ilobjplugindispatchgui", get_class($this)], $this->getAfterCreationCmd());
270  }
271 
275  abstract public function getAfterCreationCmd(): string;
276 
277  abstract public function getStandardCmd(): string;
278 
279  abstract public function performCommand(string $cmd): void;
280 
281  public function addInilPluginAdminfoTab(): void
282  {
283  $ilAccess = $this->access;
284  $ilTabs = $this->tabs;
285 
286  // info screen
287  if ($ilAccess->checkAccess('visible', "", $this->object->getRefId())) {
288  $ilTabs->addTarget(
289  "info_short",
290  $this->ctrl->getLinkTargetByClass(
291  "ilinfoscreengui",
292  "showSummary"
293  ),
294  "showSummary"
295  );
296  }
297  }
298 
299  public function addPermissionTab(): void
300  {
301  $ilAccess = $this->access;
302  $ilTabs = $this->tabs;
303  $ilCtrl = $this->ctrl;
304 
305  // edit permissions
306  if ($ilAccess->checkAccess('edit_permission', "", $this->object->getRefId())) {
307  $ilTabs->addTarget(
308  "perm_settings",
309  $ilCtrl->getLinkTargetByClass("ilpermissiongui", "perm"),
310  ["perm", "info", "owner"],
311  'ilpermissiongui'
312  );
313  }
314  }
315 
316  public function addInfoTab(): void
317  {
318  $ilAccess = $this->access;
319  $ilTabs = $this->tabs;
320 
321  // info screen
322  if ($ilAccess->checkAccess('visible', "", $this->object->getRefId())) {
323  $ilTabs->addTarget(
324  "info_short",
325  $this->ctrl->getLinkTargetByClass(
326  "ilinfoscreengui",
327  "showSummary"
328  ),
329  "showSummary"
330  );
331  }
332  }
333 
334  public function addExportTab(): void
335  {
336  // write
337  if ($this->access->checkAccess('write', "", $this->object->getRefId())) {
338  $this->tabs->addTarget(
339  'export',
340  $this->ctrl->getLinkTargetByClass("ilexportgui", ''),
341  'export',
342  'ilexportgui'
343  );
344  }
345  }
346 
347  public function infoScreen(): void
348  {
349  $lng = $this->lng;
350  $ilCtrl = $this->ctrl;
351  $ilTabs = $this->tabs;
352 
353  $ilTabs->activateTab("info_short");
354 
355  $this->checkPermission("visible");
356 
357  $info = new ilInfoScreenGUI($this);
358  $info->enablePrivateNotes();
359 
360  // general information
361  $lng->loadLanguageModule("meta");
362 
363  $this->addInfoItems($info);
364 
365  // forward the command
366  $ilCtrl->forwardCommand($info);
367  }
368 
372  public function addInfoItems(ilInfoScreenGUI $info): void
373  {
374  }
375 
379  public static function _goto(array $a_target): void
380  {
381  global $DIC;
382  $main_tpl = $DIC->ui()->mainTemplate();
383 
384  $ilCtrl = $DIC->ctrl();
385  $ilAccess = $DIC->access();
386  $lng = $DIC->language();
387 
388  $t = explode("_", $a_target[0]);
389  $ref_id = (int) $t[0];
390  $class_name = $a_target[1];
391 
392  if ($ilAccess->checkAccess("read", "", $ref_id)) {
393  $ilCtrl->setTargetScript('ilias.php');
394  $ilCtrl->setParameterByClass($class_name, "ref_id", $ref_id);
395  $ilCtrl->redirectByClass(["ilobjplugindispatchgui", $class_name], "");
396  } elseif ($ilAccess->checkAccess("visible", "", $ref_id)) {
397  $ilCtrl->setTargetScript('ilias.php');
398  $ilCtrl->setParameterByClass($class_name, "ref_id", $ref_id);
399  $ilCtrl->redirectByClass(["ilobjplugindispatchgui", $class_name], "infoScreen");
400  } elseif ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
401  $main_tpl->setOnScreenMessage('failure', sprintf(
402  $lng->txt("msg_no_perm_read_item"),
404  ));
406  }
407  }
408 
409  protected function supportsExport(): bool
410  {
411  $component_repository = $this->component_repository;
412 
413  return $component_repository->getPluginSlotById("robj")->getPluginByName($this->getPlugin()->getPluginName())->supportsExport();
414  }
415 
416  protected function lookupParentTitleInCreationMode(): string
417  {
419  $this->slot_request->getRefId()
420  ));
421  }
422 }
printToStdout(string $part=self::DEFAULT_BLOCK, bool $has_tabs=true, bool $skip_main_menu=false)
setLocator()
set Locator
checkPermission(string $perm, string $cmd="", string $type="", int $ref_id=null)
ilNavigationHistory $nav_history
Readable part of repository interface to ilComponentDataDB.
setLocator()
Insert locator.
static _getIcon(int $obj_id=0, string $size="big", string $type="", bool $offline=false)
Get icon for repository item.
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.
GUI class for the workflow of copying objects.
ilComponentRepository $component_repository
addTarget(string $a_text, string $a_link, $a_cmd="", $a_cmdClass="", string $a_frame="", bool $a_activate=false, bool $a_dir_text=false)
const ROOT_FOLDER_ID
Definition: constants.php:32
const TITLE_LENGTH
afterSave(ilObject $new_object)
performCommand(string $cmd)
loadLanguageModule(string $a_module)
Load language module.
setTitleIcon(string $a_icon_path, string $a_icon_desc="")
set title icon
static _goto(array $a_target)
getPlugin()
Get plugin object.
static _lookupObjId(int $ref_id)
Object GUI class for repository plugins.
getAfterCreationCmd()
Cmd that will be redirected to after creation of a new object.
ilComponentFactory $component_factory
static _lookupTitle(int $obj_id)
getType()
Functions that must be overwritten.
getPluginSlotById(string $id)
Get pluginslot by id.
__construct(int $id=0, int $id_type=self::REPOSITORY_NODE_ID, int $parent_node_id=0)
global $DIC
Definition: shib_login.php:25
ilGlobalTemplateInterface $tpl
loadStandardTemplate()
This loads the standard template "tpl.adm_content.html" and "tpl.statusline.html" the CONTENT and STA...
setTitle(string $a_title, bool $hidden=false)
Sets title in standard template.
Last visited history for repository items.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTabs()
create tabs (repository/workspace switch)
getCreationFormTitle()
Use custom creation form titles.
activateTab(string $a_id)
setTargetScript(string $a_target_script)
__construct(Container $dic, ilPlugin $plugin)
This class represents a text area property in a property form.
PluginSlotGUIRequest $slot_request
initEditForm()
Init object update form.
ilLocatorGUI $locator
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addAdminLocatorItems(bool $do_not_add_object=false)
static getInstanceFromAjaxCall()
(Re-)Build instance from ajax call
addInfoItems(ilInfoScreenGUI $info)
Add items to info screen.
setAdminTabs()
set admin tabs
static _gotoRepositoryRoot(bool $raise_error=false)
Goto repository root.
ilAccessHandler $access