1<?php 2/* 3 +-----------------------------------------------------------------------------+ 4 | ILIAS open source | 5 +-----------------------------------------------------------------------------+ 6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne | 7 | | 8 | This program is free software; you can redistribute it and/or | 9 | modify it under the terms of the GNU General Public License | 10 | as published by the Free Software Foundation; either version 2 | 11 | of the License, or (at your option) any later version. | 12 | | 13 | This program is distributed in the hope that it will be useful, | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 16 | GNU General Public License for more details. | 17 | | 18 | You should have received a copy of the GNU General Public License | 19 | along with this program; if not, write to the Free Software | 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 21 +-----------------------------------------------------------------------------+ 22*/ 23 24 25require_once "./Services/Object/classes/class.ilObject.php"; 26 27/** 28* Class ilObjRoleFolder 29* 30* @author Stefan Meyer <meyer@leifos.com> 31* $Id$ 32* 33* @ingroup ServicesAccessControl 34*/ 35class ilObjRoleFolder extends ilObject 36{ 37 /** 38 * Constructor 39 * @access public 40 * @param integer reference_id or object_id 41 * @param boolean treat the id as reference_id (true) or object_id (false) 42 */ 43 public function __construct($a_id = 0, $a_call_by_reference = true) 44 { 45 $this->type = "rolf"; 46 parent::__construct($a_id, $a_call_by_reference); 47 } 48 49 public function read() 50 { 51 parent::read(); 52 53 if ($this->getId() != ROLE_FOLDER_ID) { 54 $this->setDescription($this->lng->txt("obj_" . $this->getType() . "_local_desc") . $this->getTitle() . $this->getDescription()); 55 $this->setTitle($this->lng->txt("obj_" . $this->getType() . "_local")); 56 } 57 } 58 59 60 /** 61 * delete rolefolder and all related data 62 * 63 * @access public 64 * @return boolean true if all object data were removed; false if only a references were removed 65 */ 66 public function delete() 67 { 68 // always call parent delete function first!! 69 if (!parent::delete()) { 70 return false; 71 } 72 73 // put here rolefolder specific stuff 74 global $DIC; 75 76 $rbacreview = $DIC['rbacreview']; 77 78 $roles = $rbacreview->getRolesOfRoleFolder($this->getRefId()); 79 80 // FIRST DELETE ALL LOCAL/BASE ROLES OF FOLDER 81 foreach ($roles as $role_id) { 82 $roleObj = &$this->ilias->obj_factory->getInstanceByObjId($role_id); 83 $roleObj->setParent($this->getRefId()); 84 $roleObj->delete(); 85 unset($roleObj); 86 } 87 88 // always call parent delete function at the end!! 89 return true; 90 } 91 92 /** 93 * creates a local role in current rolefolder (this object) 94 * 95 * @access public 96 * @param string title 97 * @param string description 98 * @return object role object 99 */ 100 public function createRole($a_title, $a_desc, $a_import_id = 0) 101 { 102 global $DIC; 103 104 $rbacadmin = $DIC['rbacadmin']; 105 $rbacreview = $DIC['rbacreview']; 106 107 include_once("./Services/AccessControl/classes/class.ilObjRole.php"); 108 $roleObj = new ilObjRole(); 109 $roleObj->setTitle($a_title); 110 $roleObj->setDescription($a_desc); 111 //echo "aaa-1-"; 112 if ($a_import_id != "") { 113 //echo "aaa-2-".$a_import_id."-"; 114 $roleObj->setImportId($a_import_id); 115 } 116 $roleObj->create(); 117 118 // ...and put the role into local role folder... 119 $rbacadmin->assignRoleToFolder($roleObj->getId(), $this->getRefId(), "y"); 120 121 return $roleObj; 122 } 123 124 /** 125 * checks if rolefolder contains any roles. if not the rolefolder is deleted 126 * @access public 127 * @return boolean true if rolefolder is deleted 128 */ 129 public function purge() 130 { 131 global $DIC; 132 133 $rbacreview = $DIC['rbacreview']; 134 $rbacadmin = $DIC['rbacadmin']; 135 $tree = $DIC['tree']; 136 137 $local_roles = $rbacreview->getRolesOfRoleFolder($this->getRefId()); 138 139 if (count($local_roles) == 0) { 140 $rbacadmin->revokePermission($this->getRefId()); 141 142 if ($tree_id = $this->isDeleted()) { 143 $deleted_tree = new ilTree($tree_id, -(int) $tree_id); 144 $deleted_tree->deleteTree($deleted_tree->getNodeData($this->getRefId())); 145 } else { 146 $tree->deleteTree($tree->getNodeData($this->getRefId())); 147 } 148 149 $this->delete(); 150 151 return true; 152 } 153 154 return false; 155 } 156 157 /** 158 * checks if role folder is in trash 159 * @access private 160 * @return integer return negative tree if in trash, otherwise false 161 */ 162 public function isDeleted() 163 { 164 $q = "SELECT tree FROM tree WHERE child= " . $this->ilias->db->quote($this->getRefId()) . " "; 165 $row = $this->ilias->db->getRow($q); 166 167 if ($row->tree < 0) { 168 return $row->tree; 169 } 170 171 return false; 172 } 173} // END class.ilObjRoleFolder 174