ILIAS  Release_4_2_x_branch Revision 61807
 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, $ilAccess;
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 
183  $ilCtrl->forwardCommand($tags_gui);
184  break;
185 
186  default:
187  break;
188  }
189 
190  exit();
191  }
192 
199  function setSubObject($a_sub_obj_type, $a_sub_obj_id)
200  {
201  $this->sub_type = (string)$a_sub_obj_type;
202  $this->sub_id = (int)$a_sub_obj_id;
203  }
204 
210  function enableCommentsSettings($a_value)
211  {
212  $this->enable_comments_settings = (bool)$a_value;
213  }
214 
218  function initHeaderAction()
219  {
220  // check access for object
221  if ($this->node_id &&
222  !$this->access_handler->checkAccess("visible", "", $this->node_id) &&
223  !$this->access_handler->checkAccess("read", "", $this->node_id))
224  {
225  return;
226  }
227 
228  include_once 'Services/Object/classes/class.ilObjectListGUIFactory.php';
229  $this->header_action = ilObjectListGUIFactory::_getListGUIByType($this->obj_type);
230 
231  // remove all currently unwanted actions
232  $this->header_action->enableCopy(false);
233  $this->header_action->enableCut(false);
234  $this->header_action->enableDelete(false);
235  $this->header_action->enableLink(false);
236  $this->header_action->enableInfoscreen(false);
237  $this->header_action->enablePayment(false);
238 
239  switch($this->node_type)
240  {
241  case self::TYPE_REPOSITORY:
242  $this->header_action->enableSubscribe(true);
244  break;
245 
246  case self::TYPE_WORKSPACE:
247  $this->header_action->enableSubscribe(false);
249  break;
250  }
251 
252  $this->header_action->initItem($this->node_id, $this->obj_id, "", "",
253  $context);
254  $this->header_action->setHeaderSubObject($this->sub_type, $this->sub_id);
255  $this->header_action->setAjaxHash($this->getAjaxHash());
256 
257  return $this->header_action;
258  }
259 }
260 
261 ?>