ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjRoleFolder.php
Go to the documentation of this file.
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 
25 require_once "./classes/class.ilObject.php";
26 
36 {
43  function ilObjRoleFolder($a_id = 0,$a_call_by_reference = true)
44  {
45  $this->type = "rolf";
46  $this->ilObject($a_id,$a_call_by_reference);
47  }
48 
49  function read($a_force_db = false)
50  {
51  parent::read();
52 
53  if ($this->getId() != ROLE_FOLDER_ID)
54  {
55  $this->setDescription($this->lng->txt("obj_".$this->getType()."_local_desc").$this->getTitle().$this->getDescription());
56  $this->setTitle($this->lng->txt("obj_".$this->getType()."_local"));
57 
58  }
59  }
60 
61 
68  function delete()
69  {
70  // always call parent delete function first!!
71  if (!parent::delete())
72  {
73  return false;
74  }
75 
76  // put here rolefolder specific stuff
77  global $rbacreview;
78 
79  $roles = $rbacreview->getRolesOfRoleFolder($this->getRefId());
80 
81  // FIRST DELETE ALL LOCAL/BASE ROLES OF FOLDER
82  foreach ($roles as $role_id)
83  {
84  $roleObj =& $this->ilias->obj_factory->getInstanceByObjId($role_id);
85  $roleObj->setParent($this->getRefId());
86  $roleObj->delete();
87  unset($roleObj);
88  }
89 
90  // always call parent delete function at the end!!
91  return true;
92  }
93 
102  function createRole($a_title,$a_desc,$a_import_id = 0)
103  {
104  global $rbacadmin, $rbacreview;
105 
106  include_once ("./Services/AccessControl/classes/class.ilObjRole.php");
107  $roleObj = new ilObjRole();
108  $roleObj->setTitle($a_title);
109  $roleObj->setDescription($a_desc);
110 //echo "aaa-1-";
111  if ($a_import_id != "")
112  {
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 
129  function purge()
130  {
131  global $rbacreview, $rbacadmin, $tree;
132 
133  $local_roles = $rbacreview->getRolesOfRoleFolder($this->getRefId());
134 
135  if (count($local_roles) == 0)
136  {
137  $rbacadmin->revokePermission($this->getRefId());
138 
139  if ($tree_id = $this->isDeleted())
140  {
141  $deleted_tree = new ilTree ($tree_id,- (int) $tree_id);
142  $deleted_tree->deleteTree($deleted_tree->getNodeData($this->getRefId()));
143  }
144  else
145  {
146  $tree->deleteTree($tree->getNodeData($this->getRefId()));
147  }
148 
149  $this->delete();
150 
151  return true;
152  }
153 
154  return false;
155  }
156 
162  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  {
169  return $row->tree;
170  }
171 
172  return false;
173  }
174 } // END class.ilObjRoleFolder
175 ?>