1<?php 2/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4/** 5* Class ilCommonActionDispatcherGUI 6* 7* @author Jörg Lützenkirchen <luetzenkirchen@leifos.com> 8* @version $Id: class.ilInfoScreenGUI.php 30682 2011-09-16 19:33:22Z akill $ 9* 10* @ilCtrl_Calls ilCommonActionDispatcherGUI: ilNoteGUI, ilTaggingGUI, ilObjectActivationGUI 11* @ilCtrl_Calls ilCommonActionDispatcherGUI: ilRatingGUI 12* 13* @ingroup ServicesObject 14*/ 15class ilCommonActionDispatcherGUI 16{ 17 /** 18 * @var ilCtrl 19 */ 20 protected $ctrl; 21 22 /** 23 * @var ilSetting 24 */ 25 protected $settings; 26 27 protected $obj_type; // [string] 28 protected $node_id; // [int] 29 protected $node_type; // [string] 30 protected $obj_id; // [int] 31 protected $sub_type; // [string] 32 protected $sub_id; // [int] 33 34 /** 35 * @var int 36 */ 37 protected $news_id = 0; 38 39 protected $enable_comments_settings; // [bool] 40 protected $rating_callback; // [array] 41 42 const TYPE_REPOSITORY = 1; 43 const TYPE_WORKSPACE = 2; 44 45 /** 46 * Constructor 47 * 48 * @param int $a_node_type 49 * @param object $a_access_handler 50 * @param string $a_obj_type 51 * @param int $a_node_id 52 * @param int $a_obj_id 53 * @return object 54 */ 55 public function __construct($a_node_type, $a_access_handler, $a_obj_type, $a_node_id, $a_obj_id, $a_news_id = 0) 56 { 57 global $DIC; 58 59 $this->ctrl = $DIC->ctrl(); 60 $this->settings = $DIC->settings(); 61 $this->node_type = (int) $a_node_type; 62 $this->access_handler = $a_access_handler; 63 $this->obj_type = (string) $a_obj_type; 64 $this->node_id = (int) $a_node_id; 65 $this->obj_id = (int) $a_obj_id; 66 $this->news_id = (int) $a_news_id; 67 } 68 69 /** 70 * Build ajax hash for current (object/node) properties 71 * 72 * @return string 73 */ 74 public function getAjaxHash() 75 { 76 return self::buildAjaxHash( 77 $this->node_type, 78 $this->node_id, 79 $this->obj_type, 80 $this->obj_id, 81 $this->sub_type, 82 $this->sub_id, 83 $this->news_id 84 ); 85 } 86 87 /** 88 * Build ajax hash 89 * 90 * @param int $a_node_type 91 * @param int $a_node_id 92 * @param string $a_obj_type 93 * @param int $a_obj_id 94 * @param string $a_sub_type 95 * @param int $a_sub_id 96 * @return string 97 */ 98 public static function buildAjaxHash( 99 $a_node_type, 100 $a_node_id, 101 $a_obj_type, 102 $a_obj_id, 103 $a_sub_type = null, 104 $a_sub_id = null, 105 $a_news_id = 0 106 ) { 107 return $a_node_type . ";" . $a_node_id . ";" . $a_obj_type . ";" . 108 $a_obj_id . ";" . $a_sub_type . ";" . $a_sub_id . ";" . $a_news_id; 109 } 110 111 /** 112 * (Re-)Build instance from ajax call 113 * 114 * @return object 115 */ 116 public static function getInstanceFromAjaxCall() 117 { 118 global $DIC; 119 120 $ilAccess = $DIC->access(); 121 $ilUser = $DIC->user(); 122 if (isset($_GET["cadh"])) { 123 $parts = explode(";", (string) $_GET["cadh"]); 124 125 $node_type = $parts[0]; 126 $node_id = $parts[1]; 127 $obj_type = $parts[2]; 128 $obj_id = $parts[3]; 129 $sub_type = $parts[4]; 130 $sub_id = $parts[5]; 131 $news_id = $parts[6]; 132 133 switch ($node_type) { 134 case self::TYPE_REPOSITORY: 135 $access_handler = $ilAccess; 136 break; 137 138 case self::TYPE_WORKSPACE: 139 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceTree.php"; 140 $tree = new ilWorkspaceTree($ilUser->getId()); 141 include_once "Services/PersonalWorkspace/classes/class.ilWorkspaceAccessHandler.php"; 142 $access_handler = new ilWorkspaceAccessHandler($tree); 143 break; 144 145 default: 146 return null; 147 } 148 149 $dispatcher = new self($node_type, $access_handler, $obj_type, $node_id, $obj_id, $news_id); 150 151 if ($sub_type && $sub_id) { 152 $dispatcher->setSubObject($sub_type, $sub_id); 153 } 154 155 // poll comments have specific settings 156 157 if ($node_type == self::TYPE_REPOSITORY && $obj_type != "poll") { 158 $dispatcher->enableCommentsSettings(true); 159 } 160 161 return $dispatcher; 162 } 163 } 164 165 public function executeCommand() 166 { 167 $ilCtrl = $this->ctrl; 168 $ilSetting = $this->settings; 169 170 // check access for object 171 if ($this->node_id && 172 !$this->access_handler->checkAccess("visible", "", $this->node_id) && 173 !$this->access_handler->checkAccess("read", "", $this->node_id)) { 174 exit(); 175 } 176 177 $next_class = $ilCtrl->getNextClass($this); 178 $cmd = $ilCtrl->getCmd(); 179 180 $ilCtrl->saveParameter($this, "cadh"); 181 182 switch ($next_class) { 183 case "ilnotegui": 184 185 $obj_type = $this->obj_type; 186 if ($this->sub_type) { 187 $obj_type = $this->sub_type; 188 } 189 190 include_once "Services/Notes/classes/class.ilNoteGUI.php"; 191 $note_gui = new ilNoteGUI($this->obj_id, $this->sub_id, $obj_type, false, $this->news_id); 192 $note_gui->enablePrivateNotes(true); 193 194 $has_write = $this->access_handler->checkAccess("write", "", $this->node_id); 195 if ($has_write && $ilSetting->get("comments_del_tutor", 1)) { 196 $note_gui->enablePublicNotesDeletion(true); 197 } 198 199 // comments cannot be turned off globally 200 if ($this->enable_comments_settings) { 201 // should only be shown if active or permission to toggle 202 if ($has_write || 203 $this->access_handler->checkAccess("edit_permissions", "", $this->node_id)) { 204 $note_gui->enableCommentsSettings(); 205 } 206 } 207 /* this is different to the info screen but we need this 208 for sub-object action menus, e.g. wiki page */ 209 elseif ($this->sub_id) { 210 $note_gui->enablePublicNotes(true); 211 } 212 213 $ilCtrl->forwardCommand($note_gui); 214 break; 215 216 case "iltagginggui": 217 include_once "Services/Tagging/classes/class.ilTaggingGUI.php"; 218 $tags_gui = new ilTaggingGUI($this->node_id); 219 $tags_gui->setObject($this->obj_id, $this->obj_type); 220 $ilCtrl->forwardCommand($tags_gui); 221 break; 222 223 case "ilobjectactivationgui": 224 $ilCtrl->setParameter($this, "parent_id", (int) $_REQUEST['parent_id']); 225 include_once 'Services/Object/classes/class.ilObjectActivationGUI.php'; 226 $act_gui = new ilObjectActivationGUI((int) $_REQUEST['parent_id'], $this->node_id); 227 $ilCtrl->forwardCommand($act_gui); 228 break; 229 230 case "ilratinggui": 231 include_once("./Services/Rating/classes/class.ilRatingGUI.php"); 232 $rating_gui = new ilRatingGUI(); 233 if (!$_GET["rnsb"]) { 234 $rating_gui->setObject($this->obj_id, $this->obj_type, $this->sub_id, $this->sub_type); 235 } else { 236 // coming from headaction ignore sub-objects 237 $rating_gui->setObject($this->obj_id, $this->obj_type); 238 } 239 $ilCtrl->forwardCommand($rating_gui); 240 if ($this->rating_callback) { 241 // as rating in categories is form-based we need to redirect 242 // somewhere after saving 243 $ilCtrl->redirect($this->rating_callback[0], $this->rating_callback[1]); 244 } 245 break; 246 247 default: 248 break; 249 } 250 251 exit(); 252 } 253 254 /** 255 * Set sub object attributes 256 * 257 * @param string $a_sub_obj_type 258 * @param int $a_sub_obj_id 259 */ 260 public function setSubObject($a_sub_obj_type, $a_sub_obj_id) 261 { 262 $this->sub_type = (string) $a_sub_obj_type; 263 $this->sub_id = (int) $a_sub_obj_id; 264 } 265 266 /** 267 * Toggle comments settings 268 * 269 * @param bool $a_value 270 */ 271 public function enableCommentsSettings($a_value) 272 { 273 $this->enable_comments_settings = (bool) $a_value; 274 } 275 276 /** 277 * Add callback for rating gui 278 * 279 * @param object $a_gui 280 * @param string $a_cmd 281 */ 282 public function setRatingCallback($a_gui, $a_cmd) 283 { 284 $this->rating_callback = array($a_gui, $a_cmd); 285 } 286 287 /** 288 * Set header action menu 289 */ 290 public function initHeaderAction() 291 { 292 // check access for object 293 if ($this->node_id && 294 !$this->access_handler->checkAccess("visible", "", $this->node_id) && 295 !$this->access_handler->checkAccess("read", "", $this->node_id)) { 296 return; 297 } 298 299 include_once 'Services/Object/classes/class.ilObjectListGUIFactory.php'; 300 $this->header_action = ilObjectListGUIFactory::_getListGUIByType( 301 $this->obj_type, 302 ($this->node_type == self::TYPE_REPOSITORY) 303 ? ilObjectListGUI::CONTEXT_REPOSITORY 304 : ilObjectListGUI::CONTEXT_WORKSPACE 305 ); 306 307 // remove all currently unwanted actions 308 $this->header_action->enableCopy(false); 309 $this->header_action->enableCut(false); 310 $this->header_action->enableDelete(false); 311 $this->header_action->enableLink(false); 312 $this->header_action->enableInfoscreen(false); 313 $this->header_action->enableTimings(false); 314 $this->header_action->enableSubscribe($this->node_type == self::TYPE_REPOSITORY); 315 316 $this->header_action->initItem($this->node_id, $this->obj_id); 317 $this->header_action->setHeaderSubObject($this->sub_type, $this->sub_id); 318 $this->header_action->setAjaxHash($this->getAjaxHash()); 319 320 return $this->header_action; 321 } 322} 323