ILIAS  Release_4_4_x_branch Revision 61816
 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.png"),
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  case 'ilcommonactiondispatchergui':
104  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
106  $this->ctrl->forwardCommand($gui);
107  break;
108  default:
109  if (strtolower($_GET["baseClass"]) == "iladministrationgui")
110  {
111  $this->viewObject();
112  return;
113  }
114  if(!$cmd)
115  {
116  $cmd = $this->getStandardCmd();
117  }
118  if ($cmd == "infoScreen")
119  {
120  $ilCtrl->setCmd("showSummary");
121  $ilCtrl->setCmdClass("ilinfoscreengui");
122  $this->infoScreen();
123  }
124  else
125  {
126  if ($this->getCreationMode())
127  {
128  $this->$cmd();
129  }
130  else
131  {
132  $this->performCommand($cmd);
133  }
134  }
135  break;
136  }
137 
138  if (!$this->getCreationMode())
139  {
140  $tpl->show();
141  }
142  }
143 
147  function addLocatorItems()
148  {
149  global $ilLocator;
150 
151  if (!$this->getCreationMode())
152  {
153  $ilLocator->addItem($this->object->getTitle(),
154  $this->ctrl->getLinkTarget($this, $this->getStandardCmd()), "", $_GET["ref_id"]);
155  }
156  }
157 
163  final private function getPlugin()
164  {
165  return $this->plugin;
166  }
167 
171  final protected function txt($a_var)
172  {
173  return $this->getPlugin()->txt($a_var);
174  }
175 
182  protected function getCreationFormTitle($a_form_type)
183  {
184  switch($a_form_type)
185  {
186  case self::CFORM_NEW:
187  return $this->txt($this->getType()."_new");
188 
189  case self::CFORM_IMPORT:
190  return $this->lng->txt("import");
191 
192  case self::CFORM_CLONE:
193  return $this->txt("objs_".$this->getType()."_duplicate");
194  }
195  }
196 
205  protected function initCreationForms($a_new_type)
206  {
207  $forms = array(
208  self::CFORM_NEW => $this->initCreateForm($a_new_type),
209  // self::CFORM_IMPORT => $this->initImportForm($a_new_type),
210  self::CFORM_CLONE => $this->fillCloneTemplate(null, $a_new_type)
211  );
212 
213  return $forms;
214  }
215 
222  public function initCreateForm($a_new_type)
223  {
224  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
225  $form = new ilPropertyFormGUI();
226  $form->setTarget("_top");
227  $form->setFormAction($this->ctrl->getFormAction($this, "save"));
228  $form->setTitle($this->txt($a_new_type."_new"));
229 
230  // title
231  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
232  $ti->setSize(min(40, ilObject::TITLE_LENGTH));
233  $ti->setMaxLength(ilObject::TITLE_LENGTH);
234  $ti->setRequired(true);
235  $form->addItem($ti);
236 
237  // description
238  $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "desc");
239  $ta->setCols(40);
240  $ta->setRows(2);
241  $form->addItem($ta);
242 
243  $form->addCommandButton("save", $this->txt($a_new_type."_add"));
244  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
245 
246  return $form;
247  }
248 
254  public function initEditForm()
255  {
256  global $lng, $ilCtrl;
257 
258  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
259  $form = new ilPropertyFormGUI();
260  $form->setTarget("_top");
261  $form->setFormAction($ilCtrl->getFormAction($this, "update"));
262  $form->setTitle($lng->txt("edit"));
263 
264  // title
265  $ti = new ilTextInputGUI($lng->txt("title"), "title");
266  $ti->setSize(min(40, ilObject::TITLE_LENGTH));
267  $ti->setMaxLength(ilObject::TITLE_LENGTH);
268  $ti->setRequired(true);
269  $form->addItem($ti);
270 
271  // description
272  $ta = new ilTextAreaInputGUI($lng->txt("description"), "desc");
273  $ta->setCols(40);
274  $ta->setRows(2);
275  $form->addItem($ta);
276 
277  $form->addCommandButton("update", $lng->txt("save"));
278  // $this->form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
279 
280  return $form;
281  }
282 
289  protected function initImportForm($a_new_type)
290  {
291  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
292  $form = new ilPropertyFormGUI();
293  $form->setTarget("_top");
294  $form->setFormAction($this->ctrl->getFormAction($this, "importFile"));
295  $form->setTitle($this->lng->txt("import"));
296 
297  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
298  $fi = new ilFileInputGUI($this->lng->txt("import_file"), "importfile");
299  $fi->setSuffixes(array("zip"));
300  $fi->setRequired(true);
301  $form->addItem($fi);
302 
303  $form->addCommandButton("importFile", $this->lng->txt("import"));
304  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
305 
306  return $form;
307  }
308 
313  function afterSave($newObj)
314  {
315  global $ilCtrl;
316  // always send a message
317  ilUtil::sendSuccess($this->lng->txt("object_added"),true);
318 
319  $ilCtrl->initBaseClass("ilObjPluginDispatchGUI");
320  $ilCtrl->setTargetScript("ilias.php");
321  $ilCtrl->getCallStructure(strtolower("ilObjPluginDispatchGUI"));
322 
323 //var_dump($ilCtrl->call_node);
324 //var_dump($ilCtrl->forward);
325 //var_dump($ilCtrl->parent);
326 //var_dump($ilCtrl->root_class);
327 
328  $ilCtrl->setParameterByClass(get_class($this), "ref_id", $newObj->getRefId());
329  $ilCtrl->redirectByClass(array("ilobjplugindispatchgui", get_class($this)), $this->getAfterCreationCmd());
330  }
331 
335  abstract function getAfterCreationCmd();
336 
337  abstract function getStandardCmd();
338 
339 // abstract function performCommand();
340 
344  function addInfoTab()
345  {
346  global $ilAccess, $ilTabs;
347 
348  // info screen
349  if ($ilAccess->checkAccess('visible', "", $this->object->getRefId()))
350  {
351  $ilTabs->addTarget("info_short",
352  $this->ctrl->getLinkTargetByClass(
353  "ilinfoscreengui", "showSummary"),
354  "showSummary");
355  }
356  }
357 
361  function addPermissionTab()
362  {
363  global $ilAccess, $ilTabs, $ilCtrl;
364 
365  // edit permissions
366  if($ilAccess->checkAccess('edit_permission', "", $this->object->getRefId()))
367  {
368  $ilTabs->addTarget("perm_settings",
369  $ilCtrl->getLinkTargetByClass("ilpermissiongui", "perm"),
370  array("perm","info","owner"), 'ilpermissiongui');
371  }
372  }
373 
374 
378  function infoScreen()
379  {
380  global $ilAccess, $ilUser, $lng, $ilCtrl, $tpl, $ilTabs;
381 
382  $ilTabs->setTabActive("info_short");
383 
384  $this->checkPermission("visible");
385 
386  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
387  $info = new ilInfoScreenGUI($this);
388  $info->enablePrivateNotes();
389 
390  // general information
391  $lng->loadLanguageModule("meta");
392 
393  $this->addInfoItems($info);
394 
395  // forward the command
396  $ret = $ilCtrl->forwardCommand($info);
397  //$tpl->setContent($ret);
398  }
399 
403  function addInfoItems($info)
404  {
405  }
406 
410  public static function _goto($a_target)
411  {
412  global $ilCtrl, $ilAccess, $lng;
413 
414  $t = explode("_", $a_target[0]);
415  $ref_id = (int) $t[0];
416  $class_name = $a_target[1];
417 
418  if ($ilAccess->checkAccess("read", "", $ref_id))
419  {
420  $ilCtrl->initBaseClass("ilObjPluginDispatchGUI");
421  $ilCtrl->setTargetScript("ilias.php");
422  $ilCtrl->getCallStructure(strtolower("ilObjPluginDispatchGUI"));
423  $ilCtrl->setParameterByClass($class_name, "ref_id", $ref_id);
424  $ilCtrl->redirectByClass(array("ilobjplugindispatchgui", $class_name), "");
425  }
426  else if($ilAccess->checkAccess("visible", "", $ref_id))
427  {
428  $ilCtrl->initBaseClass("ilObjPluginDispatchGUI");
429  $ilCtrl->setTargetScript("ilias.php");
430  $ilCtrl->getCallStructure(strtolower("ilObjPluginDispatchGUI"));
431  $ilCtrl->setParameterByClass($class_name, "ref_id", $ref_id);
432  $ilCtrl->redirectByClass(array("ilobjplugindispatchgui", $class_name), "infoScreen");
433  }
434  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
435  {
436  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
438  include_once("./Services/Object/classes/class.ilObjectGUI.php");
440  }
441  }
442 
443 }