1<?php 2 3/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */ 4 5include_once("./Services/Object/classes/class.ilObject2GUI.php"); 6include_once("./Modules/ItemGroup/classes/class.ilObjItemGroup.php"); 7 8/** 9 * User Interface class for item groups 10 * 11 * @author Alex Killing <alex.killing@gmx.de> 12 * 13 * $Id$ 14 * 15 * @ilCtrl_Calls ilObjItemGroupGUI: ilPermissionGUI 16 * @ilCtrl_Calls ilObjItemGroupGUI: ilCommonActionDispatcherGUI, ilObjectCopyGUI 17 * @ilCtrl_isCalledBy ilObjItemGroupGUI: ilRepositoryGUI, ilAdministrationGUI 18 * @ingroup ModulesItemGroup 19 */ 20class ilObjItemGroupGUI extends ilObject2GUI 21{ 22 /** 23 * @var ilTabsGUI 24 */ 25 protected $tabs; 26 27 /** 28 * @var ilHelpGUI 29 */ 30 protected $help; 31 32 /** 33 * @var ilErrorHandling 34 */ 35 protected $error; 36 37 38 /** 39 * Constructor 40 */ 41 public function __construct($a_id = 0, $a_id_type = self::REPOSITORY_NODE_ID, $a_parent_node_id = 0) 42 { 43 global $DIC; 44 parent::__construct($a_id, $a_id_type, $a_parent_node_id); 45 46 $this->lng = $DIC->language(); 47 $this->tabs = $DIC->tabs(); 48 $this->access = $DIC->access(); 49 $this->tpl = $DIC["tpl"]; 50 $this->ctrl = $DIC->ctrl(); 51 $this->locator = $DIC["ilLocator"]; 52 $this->tree = $DIC->repositoryTree(); 53 $this->help = $DIC["ilHelp"]; 54 $this->error = $DIC["ilErr"]; 55 } 56 57 /** 58 * Initialisation 59 */ 60 protected function afterConstructor() 61 { 62 $lng = $this->lng; 63 64 $lng->loadLanguageModule("itgr"); 65 66 $this->ctrl->saveParameter($this, array("ref_id")); 67 } 68 69 /** 70 * Get type 71 */ 72 final public function getType() 73 { 74 return "itgr"; 75 } 76 77 /** 78 * execute command 79 */ 80 public function executeCommand() 81 { 82 $ilTabs = $this->tabs; 83 $lng = $this->lng; 84 $ilAccess = $this->access; 85 $tpl = $this->tpl; 86 $ilCtrl = $this->ctrl; 87 $ilLocator = $this->locator; 88 89 $next_class = $this->ctrl->getNextClass($this); 90 $cmd = $this->ctrl->getCmd(); 91 92 switch ($next_class) { 93 case 'ilinfoscreengui': 94 $this->prepareOutput(); 95 $this->addHeaderAction(); 96 $this->infoScreen(); 97 break; 98 99 case 'ilpermissiongui': 100 $this->prepareOutput(); 101 $ilTabs->activateTab("perm_settings"); 102 $this->addHeaderAction(); 103 include_once("Services/AccessControl/classes/class.ilPermissionGUI.php"); 104 $perm_gui = new ilPermissionGUI($this); 105 $ret = $this->ctrl->forwardCommand($perm_gui); 106 break; 107 108 case "ilcommonactiondispatchergui": 109 include_once("Services/Object/classes/class.ilCommonActionDispatcherGUI.php"); 110 $gui = ilCommonActionDispatcherGUI::getInstanceFromAjaxCall(); 111 $this->ctrl->forwardCommand($gui); 112 break; 113 114 default: 115 $cmd = $this->ctrl->getCmd("listMaterials"); 116 $this->prepareOutput(); 117 $this->addHeaderAction(); 118 $this->$cmd(); 119 break; 120 } 121 } 122 123 /** 124 * Add session locator 125 * 126 * @access public 127 * 128 */ 129 public function addLocatorItems() 130 { 131 $ilLocator = $this->locator; 132 $ilAccess = $this->access; 133 134 if (is_object($this->object) && $ilAccess->checkAccess("write", "", $this->object->getRefId())) { 135 $ilLocator->addItem($this->object->getTitle(), $this->ctrl->getLinkTarget($this, "listMaterials"), "", $_GET["ref_id"]); 136 } 137 } 138 139 protected function initCreationForms($a_new_type) 140 { 141 $forms = array(self::CFORM_NEW => $this->initCreateForm($a_new_type) 142 ); 143 144 return $forms; 145 } 146 147 /** 148 * Init edit form, custom part 149 * 150 * @param ilPropertyFormGUI $a_form form object 151 */ 152 public function initEditCustomForm(ilPropertyFormGUI $a_form) 153 { 154 $a_form->removeItemByPostVar("desc"); 155 156 // description 157 $ta = new ilTextAreaInputGUI($this->lng->txt("description"), "desc"); 158 $ta->setRows(2); 159 $ta->setInfo($this->lng->txt("itgr_desc_info")); 160 $a_form->addItem($ta); 161 162 // show title 163 $cb = new ilCheckboxInputGUI($this->lng->txt("itgr_show_title"), "show_title"); 164 $cb->setInfo($this->lng->txt("itgr_show_title_info")); 165 $a_form->addItem($cb); 166 167 // behaviour 168 include_once("./Modules/ItemGroup/classes/class.ilItemGroupBehaviour.php"); 169 $options = ilItemGroupBehaviour::getAll(); 170 $si = new ilSelectInputGUI($this->lng->txt("itgr_behaviour"), "behaviour"); 171 $si->setInfo($this->lng->txt("itgr_behaviour_info")); 172 $si->setOptions($options); 173 $cb->addSubItem($si); 174 } 175 176 177 /** 178 * After save 179 */ 180 protected function afterSave(ilObject $a_new_object) 181 { 182 $ilCtrl = $this->ctrl; 183 184 ilUtil::sendSuccess($this->lng->txt("object_added"), true); 185 $ilCtrl->redirect($this, "listMaterials"); 186 } 187 188 /** 189 * show material assignment 190 * 191 * @access protected 192 * @param 193 * @return 194 */ 195 public function listMaterials() 196 { 197 $tree = $this->tree; 198 $ilTabs = $this->tabs; 199 $tpl = $this->tpl; 200 201 $this->checkPermission("write"); 202 203 $ilTabs->activateTab("materials"); 204 205 $parent_ref_id = $tree->getParentId($this->object->getRefId()); 206 207 include_once "Services/Object/classes/class.ilObjectAddNewItemGUI.php"; 208 $gui = new ilObjectAddNewItemGUI($parent_ref_id); 209 $gui->setDisabledObjectTypes(array("itgr", "sess")); 210 $gui->setAfterCreationCallback($this->object->getRefId()); 211 $gui->render(); 212 213 include_once("./Modules/ItemGroup/classes/class.ilItemGroupItemsTableGUI.php"); 214 $tab = new ilItemGroupItemsTableGUI($this, "listMaterials"); 215 $tpl->setContent($tab->getHTML()); 216 } 217 218 /** 219 * Save material assignment 220 */ 221 public function saveItemAssignment() 222 { 223 $ilCtrl = $this->ctrl; 224 225 $this->checkPermission("write"); 226 227 include_once './Modules/ItemGroup/classes/class.ilItemGroupItems.php'; 228 229 $item_group_items = new ilItemGroupItems($this->object->getRefId()); 230 $items = is_array($_POST['items']) 231 ? $_POST['items'] 232 : array(); 233 $items = ilUtil::stripSlashesArray($items); 234 $item_group_items->setItems($items); 235 $item_group_items->update(); 236 237 ilUtil::sendSuccess($this->lng->txt('msg_obj_modified'), true); 238 $ilCtrl->redirect($this, "listMaterials"); 239 } 240 241 242 /** 243 * Get standard template 244 */ 245 public function getTemplate() 246 { 247 $this->tpl->loadStandardTemplate(); 248 } 249 250 251 /** 252 * Set tabs 253 */ 254 public function setTabs() 255 { 256 $ilAccess = $this->access; 257 $ilTabs = $this->tabs; 258 $ilCtrl = $this->ctrl; 259 $ilHelp = $this->help; 260 $lng = $this->lng; 261 $tree = $this->tree; 262 263 $ilHelp->setScreenIdComponent("itgr"); 264 265 $parent_ref_id = $tree->getParentId($this->object->getRefId()); 266 $parent_obj_id = ilObject::_lookupObjId($parent_ref_id); 267 $parent_type = ilObject::_lookupType($parent_obj_id); 268 269 include_once("./Services/Link/classes/class.ilLink.php"); 270 $ilTabs->setBackTarget( 271 $lng->txt('obj_' . $parent_type), 272 ilLink::_getLink($parent_ref_id), 273 "_top" 274 ); 275 276 if ($ilAccess->checkAccess("write", "", $this->object->getRefId())) { 277 $ilTabs->addTab( 278 'materials', 279 $lng->txt('itgr_materials'), 280 $this->ctrl->getLinkTarget($this, 'listMaterials') 281 ); 282 283 $ilTabs->addTab( 284 'settings', 285 $lng->txt('settings'), 286 $this->ctrl->getLinkTarget($this, 'edit') 287 ); 288 } 289 290 if ($ilAccess->checkAccess("edit_permission", "", $this->object->getRefId())) { 291 $ilTabs->addTab( 292 "perm_settings", 293 $lng->txt('perm_settings'), 294 $this->ctrl->getLinkTargetByClass(array(get_class($this),'ilpermissiongui'), "perm") 295 ); 296 } 297 } 298 299 300 /** 301 * Goto item group 302 */ 303 public static function _goto($a_target) 304 { 305 global $DIC; 306 307 $ilAccess = $DIC->access(); 308 $ilErr = $DIC["ilErr"]; 309 $lng = $DIC->language(); 310 $tree = $DIC->repositoryTree(); 311 312 $targets = explode('_', $a_target); 313 $ref_id = $targets[0]; 314 $par_id = $tree->getParentId($ref_id); 315 316 if ($ilAccess->checkAccess("read", "", $par_id)) { 317 include_once("./Services/Link/classes/class.ilLink.php"); 318 ilUtil::redirect(ilLink::_getLink($par_id)); 319 exit; 320 } elseif ($ilAccess->checkAccess("read", "", ROOT_FOLDER_ID)) { 321 ilUtil::sendFailure(sprintf( 322 $lng->txt("msg_no_perm_read_item"), 323 ilObject::_lookupTitle(ilObject::_lookupObjId($a_target)) 324 ), true); 325 ilObjectGUI::_gotoRepositoryRoot(); 326 } 327 328 $ilErr->raiseError($lng->txt("msg_no_perm_read"), $ilErr->FATAL); 329 } 330 331 /** 332 * Goto item group 333 */ 334 public function gotoParent() 335 { 336 $ilAccess = $this->access; 337 $ilErr = $this->error; 338 $lng = $this->lng; 339 $tree = $this->tree; 340 341 $ref_id = $this->object->getRefId(); 342 $par_id = $tree->getParentId($ref_id); 343 344 if ($ilAccess->checkAccess("read", "", $par_id)) { 345 include_once("./Services/Link/classes/class.ilLink.php"); 346 ilUtil::redirect(ilLink::_getLink($par_id)); 347 exit; 348 } 349 } 350 351 /** 352 * Custom callback after object is created (in parent containert 353 * 354 * @param ilObject $a_obj 355 */ 356 public function afterSaveCallback(ilObject $a_obj) 357 { 358 // add new object to materials 359 include_once './Modules/ItemGroup/classes/class.ilItemGroupItems.php'; 360 $items = new ilItemGroupItems($this->object->getRefId()); 361 $items->addItem($a_obj->getRefId()); 362 $items->update(); 363 } 364 365 /** 366 * Get edit form values (custom part) 367 * 368 * @param array $a_values form values 369 */ 370 public function getEditFormCustomValues(array &$a_values) 371 { 372 $a_values["show_title"] = !$this->object->getHideTitle(); 373 $a_values["behaviour"] = $this->object->getBehaviour(); 374 } 375 376 /** 377 * Update (custom part) 378 * 379 * @param ilPropertyFormGUI $a_form form 380 */ 381 public function updateCustom(ilPropertyFormGUI $a_form) 382 { 383 $this->object->setHideTitle(!$a_form->getInput("show_title")); 384 include_once("./Modules/ItemGroup/classes/class.ilItemGroupBehaviour.php"); 385 $behaviour = ($a_form->getInput("show_title")) 386 ? $a_form->getInput("behaviour") 387 : ilItemGroupBehaviour::ALWAYS_OPEN; 388 $this->object->setBehaviour($behaviour); 389 } 390 391 /** 392 * Init object creation form 393 * 394 * @param string $a_new_type 395 * @return ilPropertyFormGUI 396 */ 397 protected function initCreateForm($a_new_type) 398 { 399 $form = parent::initCreateForm($a_new_type); 400 $ta = $form->getItemByPostVar("desc"); 401 $ta->setInfo($this->lng->txt("itgr_desc_info")); 402 return $form; 403 } 404} 405