ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObject2GUI.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("./classes/class.ilObjectGUI.php");
5 
28 abstract class ilObject2GUI extends ilObjectGUI
29 {
30  protected $object_id;
31  protected $node_id;
32  protected $creation_forms = array();
33  protected $id_type = array();
34  protected $parent_id;
35  public $tree;
36  protected $access_handler;
37 
38  const OBJECT_ID = 0;
39  const REPOSITORY_NODE_ID = 1;
40  const WORKSPACE_NODE_ID = 2;
43 
51  function __construct($a_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a_parent_node_id = 0)
52  {
53  global $objDefinition, $tpl, $ilCtrl, $ilErr, $lng, $ilTabs, $tree, $ilAccess;
54 
55  if (!isset($ilErr))
56  {
57  $ilErr = new ilErrorHandling();
58  $ilErr->setErrorHandling(PEAR_ERROR_CALLBACK,array($ilErr,'errorHandler'));
59  }
60  else
61  {
62  $this->ilErr =& $ilErr;
63  }
64 
65  $this->id_type = $a_id_type;
66  $this->parent_id = $a_parent_node_id;
67  $this->type = $this->getType();
68  $this->html = "";
69 
70  // use globals instead?
71  $this->tabs_gui = $ilTabs;
72  $this->objDefinition = $objDefinition;
73  $this->tpl = $tpl;
74  $this->ctrl = $ilCtrl;
75  $this->lng = $lng;
76 
77  $params = array();
78  switch($this->id_type)
79  {
80  case self::REPOSITORY_NODE_ID:
81  $this->node_id = $a_id;
82  $this->object_id = ilObject::_lookupObjectId($this->node_id);
83  $this->tree = $tree;
84  $this->access_handler = $ilAccess;
85  $this->call_by_reference = true; // needed for prepareOutput()
86  $params[] = "ref_id";
87  break;
88 
89  case self::REPOSITORY_OBJECT_ID:
90  $this->object_id = $a_id;
91  $this->tree = $tree;
92  $this->access_handler = $ilAccess;
93  $params[] = "obj_id"; // ???
94  break;
95 
96  case self::WORKSPACE_NODE_ID:
97  global $ilUser;
98  $this->node_id = $a_id;
99  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
100  $this->tree = new ilWorkspaceTree($ilUser->getId());
101  $this->object_id = $this->tree->lookupObjectId($this->node_id);
102  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
103  $this->access_handler = new ilWorkspaceAccessHandler($this->tree);
104  $params[] = "wsp_id";
105  break;
106 
107  case self::WORKSPACE_OBJECT_ID:
108  global $ilUser;
109  $this->object_id = $a_id;
110  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
111  $this->tree = new ilWorkspaceTree($ilUser->getId());
112  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
113  $this->access_handler = new ilWorkspaceAccessHandler($this->tree);
114  $params[] = "obj_id"; // ???
115  break;
116 
117  case self::OBJECT_ID:
118  $this->object_id = $a_id;
119  include_once "Services/Objects/classes/class.ilDummyAccessHandler.php";
120  $this->access_handler = new ilDummyAccessHandler();
121  $params[] = "obj_id";
122  break;
123  }
124  $this->ctrl->saveParameter($this, $params);
125 
126 
127 
128  // old stuff for legacy code (obsolete?)
129  if(!$this->object_id)
130  {
131  $this->creation_mode = true;
132  }
133  if($this->node_id)
134  {
135  // add parent node id if missing
136  if(!$this->parent_id && $this->tree)
137  {
138  $this->parent_id = $this->tree->getParentId($this->node_id);
139  }
140  }
141  $this->ref_id = $this->node_id;
142  $this->obj_id = $this->object_id;
143 
144 
145 
146  $this->assignObject();
147 
148  // set context
149  if (is_object($this->object))
150  {
151  $this->ctrl->setContext($this->object->getId(), $this->object->getType());
152  }
153 
154  $this->afterConstructor();
155  }
156 
160  protected function afterConstructor()
161  {
162  }
163 
167  function &executeCommand()
168  {
169  $next_class = $this->ctrl->getNextClass($this);
170  $cmd = $this->ctrl->getCmd();
171 
172  $this->prepareOutput();
173 
174  switch($next_class)
175  {
176  case "ilworkspaceaccessgui";
177  if($this->node_id)
178  {
179  $this->tabs_gui->activateTab("id_permissions");
180 
181  include_once('./Services/PersonalWorkspace/classes/class.ilWorkspaceAccessGUI.php');
182  $wspacc = new ilWorkspaceAccessGUI($this->node_id, $this->getAccessHandler());
183  $this->ctrl->forwardCommand($wspacc);
184  break;
185  }
186 
187  default:
188  if(!$cmd)
189  {
190  $cmd = "render";
191  }
192  return $this->$cmd();
193  }
194 
195  return true;
196  }
197 
201  final protected function assignObject()
202  {
203  if ($this->object_id != 0)
204  {
205  switch($this->id_type)
206  {
207  case self::OBJECT_ID:
208  case self::REPOSITORY_OBJECT_ID:
209  case self::WORKSPACE_OBJECT_ID:
210  $this->object = ilObjectFactory::getInstanceByObjId($this->object_id);
211  break;
212 
213  case self::REPOSITORY_NODE_ID:
214  $this->object = ilObjectFactory::getInstanceByRefId($this->node_id);
215  break;
216 
217  case self::WORKSPACE_NODE_ID:
218  // to be discussed
219  $this->object = ilObjectFactory::getInstanceByObjId($this->object_id);
220  break;
221  }
222  }
223  }
224 
230  protected function getAccessHandler()
231  {
232  return $this->access_handler;
233  }
234 
238  final protected function setLocator()
239  {
240  global $ilLocator, $tpl;
241 
242  if ($this->omit_locator)
243  {
244  return;
245  }
246 
247  switch($this->id_type)
248  {
249  case self::REPOSITORY_NODE_ID:
250  $ref_id = $this->node_id
251  ? $this->node_id
253  $ilLocator->addRepositoryItems($ref_id);
254 
255  // not so nice workaround: todo: handle $ilLocator as tabs in ilTemplate
256  if ($_GET["admin_mode"] == "" &&
257  strtolower($this->ctrl->getCmdClass()) == "ilobjrolegui")
258  {
259  $this->ctrl->setParameterByClass("ilobjrolegui",
260  "rolf_ref_id", $_GET["rolf_ref_id"]);
261  $this->ctrl->setParameterByClass("ilobjrolegui",
262  "obj_id", $_GET["obj_id"]);
263  $ilLocator->addItem($this->lng->txt("role"),
264  $this->ctrl->getLinkTargetByClass(array("ilpermissiongui",
265  "ilobjrolegui"), "perm"));
266  }
267 
268  // in workspace this is done in ilPersonalWorkspaceGUI
269  if($this->object_id)
270  {
271  $this->addLocatorItems();
272  }
273  $tpl->setLocator();
274 
275  break;
276 
277  case self::WORKSPACE_NODE_ID:
278  // :TODO:
279  break;
280  }
281 
282 
283  }
284 
288  public function delete()
289  {
290  switch($this->id_type)
291  {
292  case self::REPOSITORY_NODE_ID:
293  case self::REPOSITORY_OBJECT_ID:
294  return parent::deleteObject();
295 
296  case self::WORKSPACE_NODE_ID:
297  case self::WORKSPACE_OBJECT_ID:
298  return $this->deleteConfirmation();
299 
300  case self::OBJECT_ID:
301  // :TODO: should this ever occur?
302  break;
303  }
304  }
305 
311  protected function deleteConfirmation()
312  {
313  global $lng, $tpl, $objDefinition;
314 
315  $node_id = $_REQUEST["item_ref_id"];
316  if (!$node_id)
317  {
318  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
319  $this->ctrl->redirect($this, "");
320  }
321 
322  // on cancel or fail we return to parent node
323  $parent_node = $this->tree->getParentId($node_id);
324  $this->ctrl->setParameter($this, "wsp_id", $parent_node);
325 
326  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
327  $cgui = new ilConfirmationGUI();
328  $cgui->setHeaderText($lng->txt("info_delete_sure")."<br/>".
329  $lng->txt("info_delete_warning_no_trash"));
330 
331  $cgui->setFormAction($this->ctrl->getFormAction($this));
332  $cgui->setCancel($lng->txt("cancel"), "cancelDelete");
333  $cgui->setConfirm($lng->txt("confirm"), "confirmedDelete");
334 
335  $a_ids = array($node_id);
336  foreach ($a_ids as $node_id)
337  {
338  $children = $this->tree->getSubTree($this->tree->getNodeData($node_id));
339  foreach($children as $child)
340  {
341  $node_id = $child["wsp_id"];
342  $obj_id = $this->tree->lookupObjectId($node_id);
344  $title = call_user_func(array(ilObjectFactory::getClassByType($type),'_lookupTitle'), $obj_id);
345 
346  // if anything fails, abort the whole process
347  if(!$this->checkPermissionBool("delete", "", "", $node_id))
348  {
349  ilUtil::sendFailure($lng->txt("msg_no_perm_delete")." ".$title, true);
350  $this->ctrl->redirect($this);
351  }
352 
353  $cgui->addItem("id[]", $node_id, $title,
354  ilObject::_getIcon($obj_id, "small", $type),
355  $lng->txt("icon")." ".$lng->txt("obj_".$type));
356  }
357  }
358 
359  $tpl->setContent($cgui->getHTML());
360  }
361 
365  public function confirmedDelete()
366  {
367  switch($this->id_type)
368  {
369  case self::REPOSITORY_NODE_ID:
370  case self::REPOSITORY_OBJECT_ID:
372 
373  case self::WORKSPACE_NODE_ID:
374  case self::WORKSPACE_OBJECT_ID:
375  return $this->deleteConfirmedObjects();
376 
377  case self::OBJECT_ID:
378  // :TODO: should this ever occur?
379  break;
380  }
381  }
382 
388  protected function deleteConfirmedObjects()
389  {
390  global $lng, $objDefinition;
391 
392  if(sizeof($_POST["id"]))
393  {
394  foreach($_POST["id"] as $node_id)
395  {
396  $node = $this->tree->getNodeData($node_id);
397 
398  // tree/reference
399  $this->tree->deleteReference($node_id);
400  $this->tree->deleteTree($node);
401 
402  // permission
403  $this->getAccessHandler()->removePermission($node_id);
404 
405  // object
406  $object = ilObjectFactory::getInstanceByObjId($node["obj_id"], false);
407  if($object)
408  {
409  $object->delete();
410  }
411  }
412 
413  ilUtil::sendSuccess($lng->txt("msg_removed"), true);
414  }
415  else
416  {
417  ilUtil::sendFailure($lng->txt("no_checkbox"), true);
418  }
419 
420  $this->ctrl->redirect($this, "");
421  }
422 
423  public function getHTML() { return parent::getHTML(); }
424 
428  final public function withReferences() { return parent::withReferences(); }
429  final public function setCreationMode($a_mode = true) { return parent::setCreationMode($a_mode); }
430  final public function getCreationMode() { return parent::getCreationMode(); }
431  final protected function prepareOutput() { return parent::prepareOutput(); }
432  protected function setTitleAndDescription() { return parent::setTitleAndDescription(); }
433  final protected function showUpperIcon() { return parent::showUpperIcon(); }
434 // final private function showMountWebfolderIcon() { return parent::showMountWebfolderIcon(); }
435  final protected function omitLocator($a_omit = true) { return parent::omitLocator($a_omit); }
436  final protected function getTargetFrame($a_cmd, $a_target_frame = "") { return parent::getTargetFrame($a_cmd, $a_target_frame); }
437  final protected function setTargetFrame($a_cmd, $a_target_frame) { return parent::setTargetFrame($a_cmd, $a_target_frame); }
438  final public function isVisible() { return parent::isVisible(); }
439  final protected function getCenterColumnHTML() { return parent::getCenterColumnHTML(); }
440  final protected function getRightColumnHTML() { return parent::getRightColumnHTML(); }
441  final protected function setColumnSettings($column_gui) { return parent::setColumnSettings($column_gui); }
442  final protected function checkPermission($a_perm, $a_cmd = "") { return parent::checkPermission($a_perm, $a_cmd); }
443 
444  // -> ilContainerGUI
445  final protected function showPossibleSubObjects() { return parent::showPossibleSubObjects(); }
446  // -> ilRepUtilGUI
447  final public function trash() { return parent::trashObject(); } // done
448  // -> ilRepUtil
449  final public function undelete() { return parent::undeleteObject(); } // done
450  final public function cancelDelete() { return parent::cancelDeleteObject(); } // ok
451  final public function removeFromSystem() { return parent::removeFromSystemObject(); } // done
452  final protected function redirectToRefId() { return parent::redirectToRefId(); } // ok
453 
454  // -> stefan
455  final protected function fillCloneTemplate($a_tpl_varname,$a_type) { return parent::fillCloneTemplate($a_tpl_varname,$a_type); }
456  final protected function fillCloneSearchTemplate($a_tpl_varname,$a_type) { return parent::fillCloneSearchTemplate($a_tpl_varname,$a_type); }
457  final protected function searchCloneSource() { return parent::searchCloneSourceObject(); }
458  final public function cloneAll() { return parent::cloneAllObject(); }
459  final protected function buildCloneSelect($existing_objs) { return parent::buildCloneSelect($existing_objs); }
460 
461  // -> ilAdministration
462  final private function displayList() { return parent::displayList(); }
463 // final private function setAdminTabs() { return parent::setAdminTabs(); }
464  final public function getAdminTabs($a) { return parent::getAdminTabs($a); }
465  final protected function addAdminLocatorItems() { return parent::addAdminLocatorItems(); }
466 
470  public function view()
471  {
472  switch($this->id_type)
473  {
474  case self::REPOSITORY_NODE_ID:
475  case self::REPOSITORY_OBJECT_ID:
476  return parent::viewObject();
477 
478  case self::WORKSPACE_NODE_ID:
479  case self::WORKSPACE_OBJECT_ID:
480  return $this->render();
481 
482  case self::OBJECT_ID:
483  // :TODO: should this ever occur? do nothing or edit() ?!
484  break;
485  }
486  }
487 
493  protected function setTabs()
494  {
495  global $ilTabs, $lng;
496 
497  switch($this->id_type)
498  {
499  case self::REPOSITORY_NODE_ID:
500  case self::REPOSITORY_OBJECT_ID:
501  if ($this->checkPermissionBool("edit_permission"))
502  {
503  $ilTabs->addTab("id_permissions",
504  $lng->txt("perm_settings"),
505  $this->ctrl->getLinkTargetByClass(array(get_class($this), "ilpermissiongui"), "perm"));
506  }
507  break;
508 
509  case self::WORKSPACE_NODE_ID:
510  case self::WORKSPACE_OBJECT_ID:
511  // only files and blogs can be shared for now
512  if ($this->checkPermissionBool("edit_permission") && in_array($this->type, array("file", "blog")) && $this->node_id)
513  {
514  $ilTabs->addTab("id_permissions",
515  $lng->txt("wsp_permissions"),
516  $this->ctrl->getLinkTargetByClass(array(get_class($this), "ilworkspaceaccessgui"), "share"));
517  }
518  break;
519  }
520  }
521 
525 // final private function setSubObjects() { die("ilObject2GUI::setSubObjects() is deprecated."); }
526 // final public function getFormAction() { die("ilObject2GUI::getFormAction() is deprecated."); }
527 // final protected function setFormAction() { die("ilObject2GUI::setFormAction() is deprecated."); }
528  final protected function getReturnLocation() { die("ilObject2GUI::getReturnLocation() is deprecated."); }
529  final protected function setReturnLocation() { die("ilObject2GUI::setReturnLocation() is deprecated."); }
530  final protected function showActions() { die("ilObject2GUI::showActions() is deprecated."); }
531  final public function getTemplateFile() {mk(); die("ilObject2GUI::getTemplateFile() is deprecated."); }
532  final protected function getTitlesByRefId() { die("ilObject2GUI::getTitlesByRefId() is deprecated."); }
533  final protected function getTabs() {nj(); die("ilObject2GUI::getTabs() is deprecated."); }
534  final protected function __showButton() { die("ilObject2GUI::__showButton() is deprecated."); }
535  final protected function hitsperpageObject() { die("ilObject2GUI::hitsperpageObject() is deprecated."); }
536  final protected function __initTableGUI() { die("ilObject2GUI::__initTableGUI() is deprecated."); }
537  final protected function __setTableGUIBasicData() { die("ilObject2GUI::__setTableGUIBasicData() is deprecated."); }
538  final protected function __showClipboardTable() { die("ilObject2GUI::__showClipboardTable() is deprecated."); }
539 
543  protected function addLocatorItems() {}
544  public function copyWizardHasOptions($a_mode) { return false; }
545 
549  abstract function getType();
550 
554 // final private function permObject() { parent::permObject(); }
555 // final private function permSaveObject() { parent::permSaveObject(); }
556 // final private function infoObject() { parent::infoObject(); }
557 // final private function __buildRoleFilterSelect() { parent::__buildRoleFilterSelect(); }
558 // final private function __filterRoles() { parent::__filterRoles(); }
559 // final private function ownerObject() { parent::ownerObject(); }
560 // final private function changeOwnerObject() { parent::changeOwnerObject(); }
561 // final private function addRoleObject() { parent::addRoleObject(); }
562 // final private function setActions() { die("ilObject2GUI::setActions() is deprecated."); }
563 // final protected function getActions() { die("ilObject2GUI::getActions() is deprecated."); }
564 
568  public function create() { parent::createObject(); }
569  public function save() { parent::saveObject(); }
570  public function edit() { parent::editObject(); }
571  public function update() { parent::updateObject(); }
572  public function cancel() { parent::cancelObject(); }
573 
582  protected function initCreationForms($a_new_type)
583  {
584  $forms = parent::initCreationForms($a_new_type);
585 
586  // cloning doesn't work in workspace yet
587  if($this->id_type == self::WORKSPACE_NODE_ID)
588  {
589  unset($forms[self::CFORM_CLONE]);
590  }
591 
592  return $forms;
593  }
594 
600  function importFile()
601  {
602  parent::importFileObject($this->parent_id);
603  }
604 
611  protected function putObjectInTree(ilObject $a_obj, $a_parent_node_id = null)
612  {
613  global $rbacreview, $ilUser;
614 
615  $this->object_id = $a_obj->getId();
616 
617  if(!$a_parent_node_id)
618  {
619  $a_parent_node_id = $this->parent_id;
620  }
621 
622  switch($this->id_type)
623  {
624  case self::REPOSITORY_NODE_ID:
625  case self::REPOSITORY_OBJECT_ID:
626  if(!$this->node_id)
627  {
628  $a_obj->createReference();
629  $this->node_id = $a_obj->getRefId();
630  }
631  $a_obj->putInTree($a_parent_node_id);
632  $a_obj->setPermissions($a_parent_node_id);
633 
634  // rbac log
635  include_once "Services/AccessControl/classes/class.ilRbacLog.php";
636  $rbac_log_roles = $rbacreview->getParentRoleIds($this->node_id, false);
637  $rbac_log = ilRbacLog::gatherFaPa($this->node_id, array_keys($rbac_log_roles), true);
638  ilRbacLog::add(ilRbacLog::CREATE_OBJECT, $this->node_id, $rbac_log);
639 
640  $this->ctrl->setParameter($this, "ref_id", $this->node_id);
641  break;
642 
643  case self::WORKSPACE_NODE_ID:
644  case self::WORKSPACE_OBJECT_ID:
645  if(!$this->node_id)
646  {
647  $this->node_id = $this->tree->insertObject($a_parent_node_id, $this->object_id);
648  }
649  $this->getAccessHandler()->setPermissions($a_parent_node_id, $this->node_id);
650 
651  $this->ctrl->setParameter($this, "wsp_id", $this->node_id);
652  break;
653 
654  case self::OBJECT_ID:
655  // do nothing
656  break;
657  }
658 
659  // BEGIN ChangeEvent: Record save object.
660  require_once('Services/Tracking/classes/class.ilChangeEvent.php');
661  ilChangeEvent::_recordWriteEvent($this->object_id, $ilUser->getId(), 'create');
662  // END ChangeEvent: Record save object.
663  }
664 
674  protected function checkPermissionBool($a_perm, $a_cmd = "", $a_type = "", $a_node_id = null)
675  {
676  global $ilUser;
677 
678  if($a_perm == "create")
679  {
680  if(!$a_node_id)
681  {
682  $a_node_id = $this->parent_id;
683  }
684  if($a_node_id)
685  {
686  return $this->getAccessHandler()->checkAccess($a_perm."_".$a_type, $a_cmd, $a_node_id, $a_type);
687  }
688  }
689  else
690  {
691 
692  if (!$a_node_id)
693  {
694  $a_node_id = $this->node_id;
695  }
696  if($a_node_id)
697  {
698  return $this->getAccessHandler()->checkAccess($a_perm, $a_cmd, $a_node_id);
699  }
700  }
701 
702  // if we do not have a node id, check if current user is owner
703  if($this->obj_id && $this->object->getOwner() == $ilUser->getId())
704  {
705  return true;
706  }
707  return false;
708  }
709 
717  protected function initHeaderAction($a_sub_type = null, $a_sub_id = null)
718  {
719  global $ilAccess;
720 
721  if($this->id_type == self::WORKSPACE_NODE_ID)
722  {
723  if(!$this->creation_mode && $this->object_id)
724  {
725  include_once "Services/Object/classes/class.ilCommonActionDispatcherGUI.php";
727  $this->getAccessHandler(), $this->getType(), $this->node_id, $this->object_id);
728 
729  $dispatcher->setSubObject($a_sub_type, $a_sub_id);
730 
731  include_once "Services/Object/classes/class.ilObjectListGUI.php";
732  ilObjectListGUI::prepareJSLinks($this->ctrl->getLinkTarget($this, "redrawHeaderAction", "", true),
733  $this->ctrl->getLinkTargetByClass(array("ilcommonactiondispatchergui", "ilnotegui"), "", "", true, false),
734  $this->ctrl->getLinkTargetByClass(array("ilcommonactiondispatchergui", "iltagginggui"), "", "", true, false));
735 
736  $lg = $dispatcher->initHeaderAction();
737 
738  if(is_object($lg))
739  {
740  // to enable add to desktop / remove from desktop
741  if($this instanceof ilDesktopItemHandling)
742  {
743  $lg->setContainerObject($this);
744  }
745 
746  // for activation checks see ilObjectGUI
747  // $lg->enableComments(true);
748  $lg->enableNotes(true);
749  // $lg->enableTags(true);
750  }
751 
752  return $lg;
753  }
754  }
755  else
756  {
757  return parent::initHeaderAction();
758  }
759  }
760 
764  protected function redrawHeaderAction()
765  {
767  }
768 
769  protected function getPermanentLinkWidget($a_append = null, $a_center = false)
770  {
771  if($this->id_type == self::WORKSPACE_NODE_ID)
772  {
773  $a_append .= "_wsp";
774  }
775 
776  include_once('Services/PermanentLink/classes/class.ilPermanentLinkGUI.php');
777  $plink = new ilPermanentLinkGUI($this->getType(), $this->node_id , $a_append);
778  $plink->setIncludePermanentLinkText(false);
779  $plink->setAlignCenter($a_center);
780  return $plink->getHTML();
781  }
782 }
783 
784 ?>