ILIAS  Release_5_0_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(ilObject::_getIcon($this->object->getId()));
46 
47  // set tabs
48  if (strtolower($_GET["baseClass"]) != "iladministrationgui")
49  {
50  $this->setTabs();
51  $this->setLocator();
52  }
53  else
54  {
55  $this->addAdminLocatorItems();
56  $tpl->setLocator();
57  $this->setAdminTabs();
58  }
59 
60  // add entry to navigation history
61  if ($ilAccess->checkAccess("read", "", $_GET["ref_id"]))
62  {
63  $ilNavigationHistory->addItem($_GET["ref_id"],
64  $ilCtrl->getLinkTarget($this, $this->getStandardCmd()), $this->getType());
65  }
66 
67  }
68  else
69  {
70  // show info of parent
71  $tpl->setTitle(ilObject::_lookupTitle(ilObject::_lookupObjId($_GET["ref_id"])));
72  $tpl->setTitleIcon(
74  $lng->txt("obj_".ilObject::_lookupType($_GET["ref_id"], true)));
75  $this->setLocator();
76 
77  }
78 
79  $next_class = $this->ctrl->getNextClass($this);
80  $cmd = $this->ctrl->getCmd();
81 
82  switch($next_class)
83  {
84  case "ilinfoscreengui":
85  $this->checkPermission("visible");
86  $this->infoScreen(); // forwards command
87  break;
88 
89  case 'ilpermissiongui':
90  include_once("Services/AccessControl/classes/class.ilPermissionGUI.php");
91  $perm_gui = new ilPermissionGUI($this);
92  $ilTabs->setTabActive("perm_settings");
93  $ret = $ilCtrl->forwardCommand($perm_gui);
94  break;
95 
96  case 'ilobjectcopygui':
97  include_once './Services/Object/classes/class.ilObjectCopyGUI.php';
98  $cp = new ilObjectCopyGUI($this);
99  $cp->setType($this->getType());
100  $this->ctrl->forwardCommand($cp);
101  break;
102 
103  case 'illearningprogressgui':
104  $ilTabs->setTabActive("learning_progress");
105  include_once './Services/Tracking/classes/class.ilLearningProgressGUI.php';
107  $this->object->getRefId(),
108  $_GET['user_id'] ? $_GET['user_id'] : $GLOBALS['ilUser']->getId());
109  $this->ctrl->forwardCommand($new_gui);
110  break;
111  case 'ilcommonactiondispatchergui':
112  include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php");
114  $this->ctrl->forwardCommand($gui);
115  break;
116  default:
117  if (strtolower($_GET["baseClass"]) == "iladministrationgui")
118  {
119  $this->viewObject();
120  return;
121  }
122  if(!$cmd)
123  {
124  $cmd = $this->getStandardCmd();
125  }
126  if ($cmd == "infoScreen")
127  {
128  $ilCtrl->setCmd("showSummary");
129  $ilCtrl->setCmdClass("ilinfoscreengui");
130  $this->infoScreen();
131  }
132  else
133  {
134  if ($this->getCreationMode())
135  {
136  $this->$cmd();
137  }
138  else
139  {
140  $this->performCommand($cmd);
141  }
142  }
143  break;
144  }
145 
146  if (!$this->getCreationMode())
147  {
148  $tpl->show();
149  }
150  }
151 
155  function addLocatorItems()
156  {
157  global $ilLocator;
158 
159  if (!$this->getCreationMode())
160  {
161  $ilLocator->addItem($this->object->getTitle(),
162  $this->ctrl->getLinkTarget($this, $this->getStandardCmd()), "", $_GET["ref_id"]);
163  }
164  }
165 
171  final private function getPlugin()
172  {
173  return $this->plugin;
174  }
175 
179  final protected function txt($a_var)
180  {
181  return $this->getPlugin()->txt($a_var);
182  }
183 
190  protected function getCreationFormTitle($a_form_type)
191  {
192  switch($a_form_type)
193  {
194  case self::CFORM_NEW:
195  return $this->txt($this->getType()."_new");
196 
197  case self::CFORM_IMPORT:
198  return $this->lng->txt("import");
199 
200  case self::CFORM_CLONE:
201  return $this->txt("objs_".$this->getType()."_duplicate");
202  }
203  }
204 
213  protected function initCreationForms($a_new_type)
214  {
215  $forms = array(
216  self::CFORM_NEW => $this->initCreateForm($a_new_type),
217  // self::CFORM_IMPORT => $this->initImportForm($a_new_type),
218  self::CFORM_CLONE => $this->fillCloneTemplate(null, $a_new_type)
219  );
220 
221  return $forms;
222  }
223 
230  public function initCreateForm($a_new_type)
231  {
232  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
233  $form = new ilPropertyFormGUI();
234  $form->setTarget("_top");
235  $form->setFormAction($this->ctrl->getFormAction($this, "save"));
236  $form->setTitle($this->txt($a_new_type."_new"));
237 
238  // title
239  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
240  $ti->setSize(min(40, ilObject::TITLE_LENGTH));
241  $ti->setMaxLength(ilObject::TITLE_LENGTH);
242  $ti->setRequired(true);
243  $form->addItem($ti);
244 
245  // description
246  $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "desc");
247  $ta->setCols(40);
248  $ta->setRows(2);
249  $form->addItem($ta);
250 
251  $form->addCommandButton("save", $this->txt($a_new_type."_add"));
252  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
253 
254  return $form;
255  }
256 
262  public function initEditForm()
263  {
264  global $lng, $ilCtrl;
265 
266  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
267  $form = new ilPropertyFormGUI();
268  $form->setTarget("_top");
269  $form->setFormAction($ilCtrl->getFormAction($this, "update"));
270  $form->setTitle($lng->txt("edit"));
271 
272  // title
273  $ti = new ilTextInputGUI($lng->txt("title"), "title");
274  $ti->setSize(min(40, ilObject::TITLE_LENGTH));
275  $ti->setMaxLength(ilObject::TITLE_LENGTH);
276  $ti->setRequired(true);
277  $form->addItem($ti);
278 
279  // description
280  $ta = new ilTextAreaInputGUI($lng->txt("description"), "desc");
281  $ta->setCols(40);
282  $ta->setRows(2);
283  $form->addItem($ta);
284 
285  $form->addCommandButton("update", $lng->txt("save"));
286  // $this->form->addCommandButton("cancelUpdate", $lng->txt("cancel"));
287 
288  return $form;
289  }
290 
297  protected function initImportForm($a_new_type)
298  {
299  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
300  $form = new ilPropertyFormGUI();
301  $form->setTarget("_top");
302  $form->setFormAction($this->ctrl->getFormAction($this, "importFile"));
303  $form->setTitle($this->lng->txt("import"));
304 
305  include_once("./Services/Form/classes/class.ilFileInputGUI.php");
306  $fi = new ilFileInputGUI($this->lng->txt("import_file"), "importfile");
307  $fi->setSuffixes(array("zip"));
308  $fi->setRequired(true);
309  $form->addItem($fi);
310 
311  $form->addCommandButton("importFile", $this->lng->txt("import"));
312  $form->addCommandButton("cancel", $this->lng->txt("cancel"));
313 
314  return $form;
315  }
316 
321  function afterSave($newObj)
322  {
323  global $ilCtrl;
324  // always send a message
325  ilUtil::sendSuccess($this->lng->txt("object_added"),true);
326 
327  $ilCtrl->initBaseClass("ilObjPluginDispatchGUI");
328  $ilCtrl->setTargetScript("ilias.php");
329  $ilCtrl->getCallStructure(strtolower("ilObjPluginDispatchGUI"));
330 
331 //var_dump($ilCtrl->call_node);
332 //var_dump($ilCtrl->forward);
333 //var_dump($ilCtrl->parent);
334 //var_dump($ilCtrl->root_class);
335 
336  $ilCtrl->setParameterByClass(get_class($this), "ref_id", $newObj->getRefId());
337  $ilCtrl->redirectByClass(array("ilobjplugindispatchgui", get_class($this)), $this->getAfterCreationCmd());
338  }
339 
343  abstract function getAfterCreationCmd();
344 
345  abstract function getStandardCmd();
346 
347 // abstract function performCommand();
348 
352  function addInfoTab()
353  {
354  global $ilAccess, $ilTabs;
355 
356  // info screen
357  if ($ilAccess->checkAccess('visible', "", $this->object->getRefId()))
358  {
359  $ilTabs->addTarget("info_short",
360  $this->ctrl->getLinkTargetByClass(
361  "ilinfoscreengui", "showSummary"),
362  "showSummary");
363  }
364  }
365 
369  function addPermissionTab()
370  {
371  global $ilAccess, $ilTabs, $ilCtrl;
372 
373  // edit permissions
374  if($ilAccess->checkAccess('edit_permission', "", $this->object->getRefId()))
375  {
376  $ilTabs->addTarget("perm_settings",
377  $ilCtrl->getLinkTargetByClass("ilpermissiongui", "perm"),
378  array("perm","info","owner"), 'ilpermissiongui');
379  }
380  }
381 
382 
386  function infoScreen()
387  {
388  global $ilAccess, $ilUser, $lng, $ilCtrl, $tpl, $ilTabs;
389 
390  $ilTabs->setTabActive("info_short");
391 
392  $this->checkPermission("visible");
393 
394  include_once("./Services/InfoScreen/classes/class.ilInfoScreenGUI.php");
395  $info = new ilInfoScreenGUI($this);
396  $info->enablePrivateNotes();
397 
398  // general information
399  $lng->loadLanguageModule("meta");
400 
401  $this->addInfoItems($info);
402 
403  // forward the command
404  $ret = $ilCtrl->forwardCommand($info);
405  //$tpl->setContent($ret);
406  }
407 
411  function addInfoItems($info)
412  {
413  }
414 
418  public static function _goto($a_target)
419  {
420  global $ilCtrl, $ilAccess, $lng;
421 
422  $t = explode("_", $a_target[0]);
423  $ref_id = (int) $t[0];
424  $class_name = $a_target[1];
425 
426  if ($ilAccess->checkAccess("read", "", $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), "");
433  }
434  else if($ilAccess->checkAccess("visible", "", $ref_id))
435  {
436  $ilCtrl->initBaseClass("ilObjPluginDispatchGUI");
437  $ilCtrl->setTargetScript("ilias.php");
438  $ilCtrl->getCallStructure(strtolower("ilObjPluginDispatchGUI"));
439  $ilCtrl->setParameterByClass($class_name, "ref_id", $ref_id);
440  $ilCtrl->redirectByClass(array("ilobjplugindispatchgui", $class_name), "infoScreen");
441  }
442  else if ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID))
443  {
444  ilUtil::sendFailure(sprintf($lng->txt("msg_no_perm_read_item"),
446  include_once("./Services/Object/classes/class.ilObjectGUI.php");
448  }
449  }
450 
451 }