ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCommonActionDispatcherGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
15 {
16  protected $obj_type; // [string]
17  protected $node_id; // [int]
18  protected $node_type; // [string]
19  protected $obj_id; // [int]
20  protected $sub_type; // [string]
21  protected $sub_id; // [int]
22  protected $enable_comments_settings; // [bool]
23 
24  const TYPE_REPOSITORY = 1;
25  const TYPE_WORKSPACE = 2;
26 
37  function __construct($a_node_type, $a_access_handler, $a_obj_type, $a_node_id, $a_obj_id)
38  {
39  $this->node_type = (int)$a_node_type;
40  $this->access_handler = $a_access_handler;
41  $this->obj_type = (string)$a_obj_type;
42  $this->node_id = (int)$a_node_id;
43  $this->obj_id = (int)$a_obj_id;
44  }
45 
51  function getAjaxHash()
52  {
53  return self::buildAjaxHash($this->node_type, $this->node_id, $this->obj_type,
54  $this->obj_id, $this->sub_type, $this->sub_id);
55  }
56 
68  static function buildAjaxHash($a_node_type, $a_node_id, $a_obj_type, $a_obj_id, $a_sub_type = null, $a_sub_id = null)
69  {
70  return $a_node_type.";".$a_node_id.";".$a_obj_type.";".
71  $a_obj_id.";".$a_sub_type.";".$a_sub_id;
72  }
73 
79  static function getInstanceFromAjaxCall()
80  {
81  global $ilAccess, $ilUser;
82 
83  if(isset($_GET["cadh"]))
84  {
85  $parts = explode(";", (string)$_GET["cadh"]);
86 
87  $node_type = $parts[0];
88  $node_id = $parts[1];
89  $obj_type = $parts[2];
90  $obj_id = $parts[3];
91  $sub_type = $parts[4];
92  $sub_id = $parts[5];
93 
94  switch($node_type)
95  {
96  case self::TYPE_REPOSITORY:
97  $access_handler = $ilAccess;
98  break;
99 
100  case self::TYPE_WORKSPACE:
101  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
102  $tree = new ilWorkspaceTree($ilUser->getId());
103  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
104  $access_handler = new ilWorkspaceAccessHandler($tree);
105  break;
106 
107  default:
108  return null;
109  }
110 
111  $dispatcher = new self($node_type, $access_handler, $obj_type, $node_id, $obj_id);
112 
113  if($sub_type && $sub_id)
114  {
115  $dispatcher->setSubObject($sub_type, $sub_id);
116  }
117 
118  if($node_type == self::TYPE_REPOSITORY)
119  {
120  $dispatcher->enableCommentsSettings(true);
121  }
122 
123  return $dispatcher;
124  }
125  }
126 
127  function executeCommand()
128  {
129  global $ilCtrl;
130 
131  // check access for object
132  if ($this->node_id &&
133  !$this->access_handler->checkAccess("visible", "", $this->node_id) &&
134  !$this->access_handler->checkAccess("read", "", $this->node_id))
135  {
136  exit();
137  }
138 
139  $next_class = $ilCtrl->getNextClass($this);
140  $cmd = $ilCtrl->getCmd();
141 
142  $ilCtrl->saveParameter($this, "cadh");
143 
144  switch($next_class)
145  {
146  case "ilnotegui":
147 
149  if($this->sub_type)
150  {
152  }
153 
154  include_once "Services/Notes/classes/class.ilNoteGUI.php";
155  $note_gui = new ilNoteGUI($this->obj_id, $this->sub_id, $obj_type);
156  $note_gui->enablePrivateNotes(true);
157 
158  // comments cannot be turned off globally
159  if($this->enable_comments_settings)
160  {
161  // should only be shown if active or permission to toggle
162  if($this->access_handler->checkAccess("write", "", $this->node_id) ||
163  $this->access_handler->checkAccess("edit_permissions", "", $this->node_id))
164  {
165  $note_gui->enableCommentsSettings();
166  }
167  }
168  /* this is different to the info screen but we need this
169  for sub-object action menus, e.g. wiki page */
170  else if($this->sub_id)
171  {
172  $note_gui->enablePublicNotes(true);
173  }
174 
175  $ilCtrl->forwardCommand($note_gui);
176  break;
177 
178  case "iltagginggui":
179  include_once "Services/Tagging/classes/class.ilTaggingGUI.php";
180  $tags_gui = new ilTaggingGUI($this->node_id);
181  $tags_gui->setObject($this->obj_id, $this->obj_type);
182  $ilCtrl->forwardCommand($tags_gui);
183  break;
184 
185  case "ilobjectactivationgui":
186  $ilCtrl->setParameter($this, "parent_id", (int)$_REQUEST['parent_id']);
187  include_once 'Services/Object/classes/class.ilObjectActivationGUI.php';
188  $act_gui = new ilObjectActivationGUI((int)$_REQUEST['parent_id'],$this->node_id);
189  $ilCtrl->forwardCommand($act_gui);
190  break;
191 
192  default:
193  break;
194  }
195 
196  exit();
197  }
198 
205  function setSubObject($a_sub_obj_type, $a_sub_obj_id)
206  {
207  $this->sub_type = (string)$a_sub_obj_type;
208  $this->sub_id = (int)$a_sub_obj_id;
209  }
210 
216  function enableCommentsSettings($a_value)
217  {
218  $this->enable_comments_settings = (bool)$a_value;
219  }
220 
224  function initHeaderAction()
225  {
226  // check access for object
227  if ($this->node_id &&
228  !$this->access_handler->checkAccess("visible", "", $this->node_id) &&
229  !$this->access_handler->checkAccess("read", "", $this->node_id))
230  {
231  return;
232  }
233 
234  include_once 'Services/Object/classes/class.ilObjectListGUIFactory.php';
235  $this->header_action = ilObjectListGUIFactory::_getListGUIByType($this->obj_type);
236 
237  // remove all currently unwanted actions
238  $this->header_action->enableCopy(false);
239  $this->header_action->enableCut(false);
240  $this->header_action->enableDelete(false);
241  $this->header_action->enableLink(false);
242  $this->header_action->enableInfoscreen(false);
243  $this->header_action->enablePayment(false);
244  $this->header_action->enableTimings(false);
245 
246  switch($this->node_type)
247  {
248  case self::TYPE_REPOSITORY:
249  $this->header_action->enableSubscribe(true);
251  break;
252 
253  case self::TYPE_WORKSPACE:
254  $this->header_action->enableSubscribe(false);
256  break;
257  }
258 
259  $this->header_action->initItem($this->node_id, $this->obj_id, "", "",
260  $context);
261  $this->header_action->setHeaderSubObject($this->sub_type, $this->sub_id);
262  $this->header_action->setAjaxHash($this->getAjaxHash());
263 
264  return $this->header_action;
265  }
266 }
267 
268 ?>