ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
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 ($next_class && $this->performNextClass($next_class)) {
163  break;
164  }
165 
166  if ($cmd === "save" || $this->getCreationMode()) {
167  $this->$cmd();
168  return;
169  }
170  if (!$cmd) {
171  $cmd = $this->getStandardCmd();
172  }
173  if ($cmd === "infoScreen") {
174  $this->ctrl->redirectByClass(ilInfoScreenGUI::class, "showSummary");
175  } else {
176  $this->performCommand($cmd);
177  }
178  break;
179  }
180 
181  if (!$this->getCreationMode()) {
182  $tpl->printToStdout();
183  }
184  }
185 
186  protected function addLocatorItems(): void
187  {
188  $ilLocator = $this->locator;
189 
190  if (!$this->getCreationMode()) {
191  $ilLocator->addItem(
192  $this->object->getTitle(),
193  $this->ctrl->getLinkTarget($this, $this->getStandardCmd()),
194  "",
195  $this->slot_request->getRefId()
196  );
197  }
198  }
199 
204  protected function getPlugin(): ilPlugin
205  {
206  if (!$this->plugin) {
207  $this->plugin = $this->component_factory->getPlugin($this->getType());
208  }
209  return $this->plugin;
210  }
211 
212  final protected function txt(string $a_var): string
213  {
214  return $this->getPlugin()->txt($a_var);
215  }
216 
220  protected function getCreationFormTitle(): string
221  {
222  return $this->txt($this->getType() . "_new");
223  }
224 
228  protected function supportsCloning(): bool
229  {
230  return true;
231  }
232 
236  protected function initEditForm(): ilPropertyFormGUI
237  {
238  $lng = $this->lng;
239  $ilCtrl = $this->ctrl;
240 
241  $form = new ilPropertyFormGUI();
242  $form->setTarget("_top");
243  $form->setFormAction($ilCtrl->getFormAction($this, "update"));
244  $form->setTitle($lng->txt("edit"));
245 
246  // title
247  $ti = new ilTextInputGUI($lng->txt("title"), "title");
248  $ti->setSize(min(40, ilObject::TITLE_LENGTH));
249  $ti->setMaxLength(ilObject::TITLE_LENGTH);
250  $ti->setRequired(true);
251  $form->addItem($ti);
252 
253  // description
254  $ta = new ilTextAreaInputGUI($lng->txt("description"), "desc");
255  $ta->setCols(40);
256  $ta->setRows(2);
257  $form->addItem($ta);
258 
259  $form->addCommandButton("update", $lng->txt("save"));
260  // $this->form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
261 
262  return $form;
263  }
264 
265  protected function afterSave(ilObject $new_object): void
266  {
267  $ilCtrl = $this->ctrl;
268  // always send a message
269  $this->tpl->setOnScreenMessage('success', $this->lng->txt("object_added"), true);
270 
271  $ilCtrl->setTargetScript('ilias.php');
272  $ilCtrl->setParameterByClass(get_class($this), "ref_id", $new_object->getRefId());
273  $ilCtrl->redirectByClass(["ilobjplugindispatchgui", get_class($this)], $this->getAfterCreationCmd());
274  }
275 
279  abstract public function getAfterCreationCmd(): string;
280 
281  abstract public function getStandardCmd(): string;
282 
283  abstract public function performCommand(string $cmd): void;
284 
285  public function addInilPluginAdminfoTab(): void
286  {
287  $ilAccess = $this->access;
288  $ilTabs = $this->tabs;
289 
290  // info screen
291  if ($ilAccess->checkAccess('visible', "", $this->object->getRefId())) {
292  $ilTabs->addTarget(
293  "info_short",
294  $this->ctrl->getLinkTargetByClass(
295  "ilinfoscreengui",
296  "showSummary"
297  ),
298  "showSummary"
299  );
300  }
301  }
302 
303  public function addPermissionTab(): void
304  {
305  $ilAccess = $this->access;
306  $ilTabs = $this->tabs;
307  $ilCtrl = $this->ctrl;
308 
309  // edit permissions
310  if ($ilAccess->checkAccess('edit_permission', "", $this->object->getRefId())) {
311  $ilTabs->addTarget(
312  "perm_settings",
313  $ilCtrl->getLinkTargetByClass("ilpermissiongui", "perm"),
314  ["perm", "info", "owner"],
315  'ilpermissiongui'
316  );
317  }
318  }
319 
320  public function addInfoTab(): void
321  {
322  $ilAccess = $this->access;
323  $ilTabs = $this->tabs;
324 
325  // info screen
326  if ($ilAccess->checkAccess('visible', "", $this->object->getRefId())) {
327  $ilTabs->addTarget(
328  "info_short",
329  $this->ctrl->getLinkTargetByClass(
330  "ilinfoscreengui",
331  "showSummary"
332  ),
333  "showSummary"
334  );
335  }
336  }
337 
338  public function addExportTab(): void
339  {
340  // write
341  if ($this->access->checkAccess('write', "", $this->object->getRefId())) {
342  $this->tabs->addTarget(
343  'export',
344  $this->ctrl->getLinkTargetByClass("ilexportgui", ''),
345  'export',
346  'ilexportgui'
347  );
348  }
349  }
350 
351  public function infoScreen(): void
352  {
353  $lng = $this->lng;
354  $ilCtrl = $this->ctrl;
355  $ilTabs = $this->tabs;
356 
357  $ilTabs->activateTab("info_short");
358 
359  $this->checkPermission("visible");
360 
361  $info = new ilInfoScreenGUI($this);
362  $info->enablePrivateNotes();
363 
364  // general information
365  $lng->loadLanguageModule("meta");
366 
367  $this->addInfoItems($info);
368 
369  // forward the command
370  $ilCtrl->forwardCommand($info);
371  }
372 
376  public function addInfoItems(ilInfoScreenGUI $info): void
377  {
378  }
379 
383  public static function _goto(array $a_target): void
384  {
385  global $DIC;
386  $main_tpl = $DIC->ui()->mainTemplate();
387 
388  $ilCtrl = $DIC->ctrl();
389  $ilAccess = $DIC->access();
390  $lng = $DIC->language();
391 
392  $t = explode("_", $a_target[0]);
393  $ref_id = (int) $t[0];
394  $class_name = $a_target[1];
395 
396  if ($ilAccess->checkAccess("read", "", $ref_id)) {
397  $ilCtrl->setTargetScript('ilias.php');
398  $ilCtrl->setParameterByClass($class_name, "ref_id", $ref_id);
399  $ilCtrl->redirectByClass(["ilobjplugindispatchgui", $class_name], "");
400  } elseif ($ilAccess->checkAccess("visible", "", $ref_id)) {
401  $ilCtrl->setTargetScript('ilias.php');
402  $ilCtrl->setParameterByClass($class_name, "ref_id", $ref_id);
403  $ilCtrl->redirectByClass(["ilobjplugindispatchgui", $class_name], "infoScreen");
404  } elseif ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) {
405  $main_tpl->setOnScreenMessage('failure', sprintf(
406  $lng->txt("msg_no_perm_read_item"),
408  ));
410  }
411  }
412 
413  protected function supportsExport(): bool
414  {
415  $component_repository = $this->component_repository;
416 
417  return $component_repository->getPluginSlotById("robj")->getPluginByName($this->getPlugin()->getPluginName())->supportsExport();
418  }
419 
420  protected function lookupParentTitleInCreationMode(): string
421  {
423  $this->slot_request->getRefId()
424  ));
425  }
426 
427  protected function performNextClass(string $next_class): bool
428  {
429  return false;
430  }
431 }
setLocator()
set Locator
ilNavigationHistory $nav_history
Readable part of repository interface to ilComponentDataDB.
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)
setTitle(string $a_title, bool $hidden=false)
Sets title in standard template.
loadLanguageModule(string $a_module)
Load language module.
setLocator()
Insert locator.
static _goto(array $a_target)
getPlugin()
Get plugin object.
static _lookupObjId(int $ref_id)
Object GUI class for repository plugins.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
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:26
ilGlobalTemplateInterface $tpl
loadStandardTemplate()
This loads the standard template "tpl.adm_content.html" and "tpl.statusline.html" the CONTENT and STA...
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)
Last visited history for repository items.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
checkPermission(string $perm, string $cmd="", string $type="", ?int $ref_id=null)
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
performNextClass(string $next_class)
$info
Definition: entry_point.php:21
static _lookupType(int $id, bool $reference=false)
Class ilObjUserTrackingGUI.
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