ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjectPluginGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/Object/classes/class.ilObject2GUI.php");
5 include_once("./Services/Component/classes/class.ilPlugin.php");
6 
7 /*
8 * Object GUI class for plugins
9 *
10 * @author Alex Killing <alex.killing@gmx.de>
11 * @version $Id$
12 * @ingroup ServicesRepository
13 */
14 abstract class ilObjectPluginGUI extends ilObject2GUI
15 {
19  function __construct($a_ref_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a_parent_node_id = 0)
20  {
21  parent::__construct($a_ref_id, $a_id_type, $a_parent_node_id);
22  $this->plugin =
23  ilPlugin::getPluginObject(IL_COMP_SERVICE, "Repository", "robj",
24  ilPlugin::lookupNameForId(IL_COMP_SERVICE, "Repository", "robj", $this->getType()));
25  if (!is_object($this->plugin))
26  {
27  die("ilObjectPluginGUI: Could not instantiate plugin object for type ".$this->getType().".");
28  }
29  }
30 
34  function &executeCommand()
35  {
36  global $ilCtrl, $tpl, $ilAccess, $lng, $ilNavigationHistory, $ilTabs;
37 
38  // get standard template (includes main menu and general layout)
39  $tpl->getStandardTemplate();
40 
41  // set title
42  if (!$this->getCreationMode())
43  {
44  $tpl->setTitle($this->object->getTitle());
45  $tpl->setTitleIcon($this->plugin->getImagePath("icon_".$this->object->getType()."_b.gif"),
46  $lng->txt("icon")." ".$this->txt("obj_".$this->object->getType()));
47 
48  // set tabs
49  if (strtolower($_GET["baseClass"]) != "iladministrationgui")
50  {
51  $this->setTabs();
52  $this->setLocator();
53  }
54  else
55  {
56  $this->addAdminLocatorItems();
57  $tpl->setLocator();
58  $this->setAdminTabs();
59  }
60 
61  // add entry to navigation history
62  if ($ilAccess->checkAccess("read", "", $_GET["ref_id"]))
63  {
64  $ilNavigationHistory->addItem($_GET["ref_id"],
65  $ilCtrl->getLinkTarget($this, $this->getStandardCmd()), $this->getType());
66  }
67 
68  }
69  else
70  {
71  // show info of parent
72  $tpl->setTitle(ilObject::_lookupTitle(ilObject::_lookupObjId($_GET["ref_id"])));
73  $tpl->setTitleIcon(
75  $lng->txt("obj_".ilObject::_lookupType($_GET["ref_id"], true)));
76  $this->setLocator();
77 
78  }
79 
80  $next_class = $this->ctrl->getNextClass($this);
81  $cmd = $this->ctrl->getCmd();
82 
83  switch($next_class)
84  {
85  case "ilinfoscreengui":
86  $this->checkPermission("visible");
87  $this->infoScreen(); // forwards command
88  break;
89 
90  case 'ilpermissiongui':
91  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
92  $perm_gui = new ilPermissionGUI($this);
93  $ilTabs->setTabActive("perm_settings");
94  $ret = $ilCtrl->forwardCommand($perm_gui);
95  break;
96 
97  case 'ilobjectcopygui':
98  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
99  $cp = new ilObjectCopyGUI($this);
100  $cp->setType($this->getType());
101  $this->ctrl->forwardCommand($cp);
102  break;
103 
104  default:
105  if (strtolower($_GET["baseClass"]) == "iladministrationgui")
106  {
107  $this->viewObject();
108  return;
109  }
110  if(!$cmd)
111  {
112  $cmd = $this->getStandardCmd();
113  }
114  if ($cmd == "infoScreen")
115  {
116  $ilCtrl->setCmd("showSummary");
117  $ilCtrl->setCmdClass("ilinfoscreengui");
118  $this->infoScreen();
119  }
120  else
121  {
122  if ($this->getCreationMode())
123  {
124  $this->$cmd();
125  }
126  else
127  {
128  $this->performCommand($cmd);
129  }
130  }
131  break;
132  }
133 
134  if (!$this->getCreationMode())
135  {
136  $tpl->show();
137  }
138  }
139 
143  function addLocatorItems()
144  {
145  global $ilLocator;
146 
147  if (!$this->getCreationMode())
148  {
149  $ilLocator->addItem($this->object->getTitle(),
150  $this->ctrl->getLinkTarget($this, $this->getStandardCmd()), "", $_GET["ref_id"]);
151  }
152  }
153 
159  final private function getPlugin()
160  {
161  return $this->plugin;
162  }
163 
167  final protected function txt($a_var)
168  {
169  return $this->getPlugin()->txt($a_var);
170  }
171 
178  protected function getCreationFormTitle($a_form_type)
179  {
180  switch($a_form_type)
181  {
182  case self::CFORM_NEW:
183  return $this->txt($this->getType()."_new");
184 
185  case self::CFORM_IMPORT:
186  return $this->lng->txt("import");
187 
188  case self::CFORM_CLONE:
189  return $this->txt("objs_".$this->getType()."_duplicate");
190  }
191  }
192 
201  protected function initCreationForms($a_new_type)
202  {
203  $forms = array(
204  self::CFORM_NEW => $this->initCreateForm($a_new_type),
205  // self::CFORM_IMPORT => $this->initImportForm($a_new_type),
206  self::CFORM_CLONE => $this->fillCloneTemplate(null, $a_new_type)
207  );
208 
209  return $forms;
210  }
211 
218  public function initCreateForm($a_new_type)
219  {
220  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
221  $form = new ilPropertyFormGUI();
222  $form->setTarget("_top");
223  $form->setFormAction($this->ctrl->getFormAction($this, "save"));
224  $form->setTitle($this->txt($a_new_type."_new"));
225 
226  // title
227  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
228  $ti->setMaxLength(128);
229  $ti->setSize(40);
230  $ti->setRequired(true);
231  $form->addItem($ti);
232 
233  // description
234  $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "desc");
235  $ta->setCols(40);
236  $ta->setRows(2);
237  $form->addItem($ta);
238 
239  $form->addCommandButton("save", $this->txt($a_new_type."_add"));
240  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
241 
242  return $form;
243  }
244 
250  public function initEditForm()
251  {
252  global $lng, $ilCtrl;
253 
254  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
255  $form = new ilPropertyFormGUI();
256  $form->setTarget("_top");
257  $form->setFormAction($ilCtrl->getFormAction($this, "update"));
258  $form->setTitle($lng->txt("edit"));
259 
260  // title
261  $ti = new ilTextInputGUI($lng->txt("title"), "title");
262  $ti->setMaxLength(128);
263  $ti->setSize(40);
264  $ti->setRequired(true);
265  $form->addItem($ti);
266 
267  // description
268  $ta = new ilTextAreaInputGUI($lng->txt("description"), "desc");
269  $ta->setCols(40);
270  $ta->setRows(2);
271  $form->addItem($ta);
272 
273  $form->addCommandButton("update", $lng->txt("save"));
274  // $this->form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
275 
276  return $form;
277  }
278 
285  protected function initImportForm($a_new_type)
286  {
287  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
288  $form = new ilPropertyFormGUI();
289  $form->setTarget("_top");
290  $form->setFormAction($this->ctrl->getFormAction($this, "importFile"));
291  $form->setTitle($this->lng->txt("import"));
292 
293  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
294  $fi = new ilFileInputGUI($this->lng->txt("import_file"), "importfile");
295  $fi->setSuffixes(array("zip"));
296  $fi->setRequired(true);
297  $form->addItem($fi);
298 
299  $form->addCommandButton("importFile", $this->lng->txt("import"));
300  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
301 
302  return $form;
303  }
304 
309  function afterSave($newObj)
310  {
311  global $ilCtrl;
312  // always send a message
313  ilUtil::sendSuccess($this->lng->txt("object_added"),true);
314 
315  $ilCtrl->initBaseClass("ilObjPluginDispatchGUI");
316  $ilCtrl->setTargetScript("ilias.php");
317  $ilCtrl->getCallStructure(strtolower("ilObjPluginDispatchGUI"));
318 
319 //var_dump($ilCtrl->call_node);
320 //var_dump($ilCtrl->forward);
321 //var_dump($ilCtrl->parent);
322 //var_dump($ilCtrl->root_class);
323 
324  $ilCtrl->setParameterByClass(get_class($this), "ref_id", $newObj->getRefId());
325  $ilCtrl->redirectByClass(array("ilobjplugindispatchgui", get_class($this)), $this->getAfterCreationCmd());
326  }
327 
331  abstract function getAfterCreationCmd();
332 
333  abstract function getStandardCmd();
334 
335 // abstract function performCommand();
336 
340  function addInfoTab()
341  {
342  global $ilAccess, $ilTabs;
343 
344  // info screen
345  if ($ilAccess->checkAccess('visible', "", $this->object->getRefId()))
346  {
347  $ilTabs->addTarget("info_short",
348  $this->ctrl->getLinkTargetByClass(
349  "ilinfoscreengui", "showSummary"),
350  "showSummary");
351  }
352  }
353 
357  function addPermissionTab()
358  {
359  global $ilAccess, $ilTabs, $ilCtrl;
360 
361  // edit permissions
362  if($ilAccess->checkAccess('edit_permission', "", $this->object->getRefId()))
363  {
364  $ilTabs->addTarget("perm_settings",
365  $ilCtrl->getLinkTargetByClass("ilpermissiongui", "perm"),
366  array("perm","info","owner"), 'ilpermissiongui');
367  }
368  }
369 
370 
374  function infoScreen()
375  {
376  global $ilAccess, $ilUser, $lng, $ilCtrl, $tpl, $ilTabs;
377 
378  $ilTabs->setTabActive("info_short");
379 
380  $this->checkPermission("visible");
381 
382  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
383  $info = new ilInfoScreenGUI($this);
384  $info->enablePrivateNotes();
385 
386  // general information
387  $lng->loadLanguageModule("meta");
388 
389  $this->addInfoItems($info);
390 
391  // forward the command
392  $ret = $ilCtrl->forwardCommand($info);
393  //$tpl->setContent($ret);
394  }
395 
399  function addInfoItems($info)
400  {
401  }
402 
406  function _goto($a_target)
407  {
408  global $ilCtrl, $ilAccess, $lng;
409 
410  $t = explode("_", $a_target[0]);
411  $ref_id = (int) $t[0];
412  $class_name = $a_target[1];
413 
414  if ($ilAccess->checkAccess("read", "", $ref_id))
415  {
416  $ilCtrl->initBaseClass("ilObjPluginDispatchGUI");
417  $ilCtrl->setTargetScript("ilias.php");
418  $ilCtrl->getCallStructure(strtolower("ilObjPluginDispatchGUI"));
419  $ilCtrl->setParameterByClass($class_name, "ref_id", $ref_id);
420  $ilCtrl->redirectByClass(array("ilobjplugindispatchgui", $class_name), "");
421  }
422  else if($ilAccess->checkAccess("visible", "", $ref_id))
423  {
424  $ilCtrl->initBaseClass("ilObjPluginDispatchGUI");
425  $ilCtrl->setTargetScript("ilias.php");
426  $ilCtrl->getCallStructure(strtolower("ilObjPluginDispatchGUI"));
427  $ilCtrl->setParameterByClass($class_name, "ref_id", $ref_id);
428  $ilCtrl->redirectByClass(array("ilobjplugindispatchgui", $class_name), "infoScreen");
429  }
430  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
431  {
432  $_GET["cmd"] = "frameset";
433  $_GET["target"] = "";
434  $_GET["ref_id"] = ROOT_FOLDER_ID;
435  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
437  include("repository.php");
438  exit;
439  }
440  }
441 
442 }