ILIAS  Release_4_4_x_branch Revision 61816
 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 
16 {
17  protected $obj_type; // [string]
18  protected $node_id; // [int]
19  protected $node_type; // [string]
20  protected $obj_id; // [int]
21  protected $sub_type; // [string]
22  protected $sub_id; // [int]
23  protected $enable_comments_settings; // [bool]
24  protected $rating_callback; // [array]
25 
26  const TYPE_REPOSITORY = 1;
27  const TYPE_WORKSPACE = 2;
28 
39  function __construct($a_node_type, $a_access_handler, $a_obj_type, $a_node_id, $a_obj_id)
40  {
41  $this->node_type = (int)$a_node_type;
42  $this->access_handler = $a_access_handler;
43  $this->obj_type = (string)$a_obj_type;
44  $this->node_id = (int)$a_node_id;
45  $this->obj_id = (int)$a_obj_id;
46  }
47 
53  function getAjaxHash()
54  {
55  return self::buildAjaxHash($this->node_type, $this->node_id, $this->obj_type,
56  $this->obj_id, $this->sub_type, $this->sub_id);
57  }
58 
70  static function buildAjaxHash($a_node_type, $a_node_id, $a_obj_type, $a_obj_id, $a_sub_type = null, $a_sub_id = null)
71  {
72  return $a_node_type.";".$a_node_id.";".$a_obj_type.";".
73  $a_obj_id.";".$a_sub_type.";".$a_sub_id;
74  }
75 
81  static function getInstanceFromAjaxCall()
82  {
83  global $ilAccess, $ilUser;
84 
85  if(isset($_GET["cadh"]))
86  {
87  $parts = explode(";", (string)$_GET["cadh"]);
88 
89  $node_type = $parts[0];
90  $node_id = $parts[1];
91  $obj_type = $parts[2];
92  $obj_id = $parts[3];
93  $sub_type = $parts[4];
94  $sub_id = $parts[5];
95 
96  switch($node_type)
97  {
98  case self::TYPE_REPOSITORY:
99  $access_handler = $ilAccess;
100  break;
101 
102  case self::TYPE_WORKSPACE:
103  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php";
104  $tree = new ilWorkspaceTree($ilUser->getId());
105  include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php";
106  $access_handler = new ilWorkspaceAccessHandler($tree);
107  break;
108 
109  default:
110  return null;
111  }
112 
113  $dispatcher = new self($node_type, $access_handler, $obj_type, $node_id, $obj_id);
114 
115  if($sub_type && $sub_id)
116  {
117  $dispatcher->setSubObject($sub_type, $sub_id);
118  }
119 
120  if($node_type == self::TYPE_REPOSITORY)
121  {
122  $dispatcher->enableCommentsSettings(true);
123  }
124 
125  return $dispatcher;
126  }
127  }
128 
129  function executeCommand()
130  {
131  global $ilCtrl;
132 
133  // check access for object
134  if ($this->node_id &&
135  !$this->access_handler->checkAccess("visible", "", $this->node_id) &&
136  !$this->access_handler->checkAccess("read", "", $this->node_id))
137  {
138  exit();
139  }
140 
141  $next_class = $ilCtrl->getNextClass($this);
142  $cmd = $ilCtrl->getCmd();
143 
144  $ilCtrl->saveParameter($this, "cadh");
145 
146  switch($next_class)
147  {
148  case "ilnotegui":
149 
151  if($this->sub_type)
152  {
154  }
155 
156  include_once "Services/Notes/classes/class.ilNoteGUI.php";
157  $note_gui = new ilNoteGUI($this->obj_id, $this->sub_id, $obj_type);
158  $note_gui->enablePrivateNotes(true);
159 
160  // comments cannot be turned off globally
161  if($this->enable_comments_settings)
162  {
163  // should only be shown if active or permission to toggle
164  if($this->access_handler->checkAccess("write", "", $this->node_id) ||
165  $this->access_handler->checkAccess("edit_permissions", "", $this->node_id))
166  {
167  $note_gui->enableCommentsSettings();
168  }
169  }
170  /* this is different to the info screen but we need this
171  for sub-object action menus, e.g. wiki page */
172  else if($this->sub_id)
173  {
174  $note_gui->enablePublicNotes(true);
175  }
176 
177  $ilCtrl->forwardCommand($note_gui);
178  break;
179 
180  case "iltagginggui":
181  include_once "Services/Tagging/classes/class.ilTaggingGUI.php";
182  $tags_gui = new ilTaggingGUI($this->node_id);
183  $tags_gui->setObject($this->obj_id, $this->obj_type);
184  $ilCtrl->forwardCommand($tags_gui);
185  break;
186 
187  case "ilobjectactivationgui":
188  $ilCtrl->setParameter($this, "parent_id", (int)$_REQUEST['parent_id']);
189  include_once 'Services/Object/classes/class.ilObjectActivationGUI.php';
190  $act_gui = new ilObjectActivationGUI((int)$_REQUEST['parent_id'],$this->node_id);
191  $ilCtrl->forwardCommand($act_gui);
192  break;
193 
194  case "ilratinggui":
195  include_once("./Services/Rating/classes/class.ilRatingGUI.php");
196  $rating_gui = new ilRatingGUI();
197  if(!$_GET["rnsb"])
198  {
199  $rating_gui->setObject($this->obj_id, $this->obj_type, $this->sub_id, $this->sub_type);
200  }
201  else
202  {
203  // coming from headaction ignore sub-objects
204  $rating_gui->setObject($this->obj_id, $this->obj_type);
205  }
206  $ilCtrl->forwardCommand($rating_gui);
207  if($this->rating_callback)
208  {
209  // as rating in categories is form-based we need to redirect
210  // somewhere after saving
211  $ilCtrl->redirect($this->rating_callback[0], $this->rating_callback[1]);
212  }
213  break;
214 
215  default:
216  break;
217  }
218 
219  exit();
220  }
221 
228  function setSubObject($a_sub_obj_type, $a_sub_obj_id)
229  {
230  $this->sub_type = (string)$a_sub_obj_type;
231  $this->sub_id = (int)$a_sub_obj_id;
232  }
233 
239  function enableCommentsSettings($a_value)
240  {
241  $this->enable_comments_settings = (bool)$a_value;
242  }
243 
250  function setRatingCallback($a_gui, $a_cmd)
251  {
252  $this->rating_callback = array($a_gui, $a_cmd);
253  }
254 
258  function initHeaderAction()
259  {
260  // check access for object
261  if ($this->node_id &&
262  !$this->access_handler->checkAccess("visible", "", $this->node_id) &&
263  !$this->access_handler->checkAccess("read", "", $this->node_id))
264  {
265  return;
266  }
267 
268  include_once 'Services/Object/classes/class.ilObjectListGUIFactory.php';
269  $this->header_action = ilObjectListGUIFactory::_getListGUIByType($this->obj_type);
270 
271  // remove all currently unwanted actions
272  $this->header_action->enableCopy(false);
273  $this->header_action->enableCut(false);
274  $this->header_action->enableDelete(false);
275  $this->header_action->enableLink(false);
276  $this->header_action->enableInfoscreen(false);
277  $this->header_action->enablePayment(false);
278  $this->header_action->enableTimings(false);
279 
280  switch($this->node_type)
281  {
282  case self::TYPE_REPOSITORY:
283  $this->header_action->enableSubscribe(true);
285  break;
286 
287  case self::TYPE_WORKSPACE:
288  $this->header_action->enableSubscribe(false);
290  break;
291  }
292 
293  $this->header_action->initItem($this->node_id, $this->obj_id, "", "",
294  $context);
295  $this->header_action->setHeaderSubObject($this->sub_type, $this->sub_id);
296  $this->header_action->setAjaxHash($this->getAjaxHash());
297 
298  return $this->header_action;
299  }
300 }
301 
302 ?>