ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjOrgUnit.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 require_once "./Services/Container/classes/class.ilContainer.php";
4 require_once("./Modules/OrgUnit/classes/class.ilOrgUnitImporter.php");
14 class ilObjOrgUnit extends ilContainer {
15 
16  protected static $root_ref_id;
17  protected static $root_id;
18 
19  protected $employee_role;
20  protected $superior_role;
21 
22  public function __construct($a_id = 0,$a_call_by_reference = true){
23  $this->type = "orgu";
24  $this->ilContainer($a_id,$a_call_by_reference);
25  }
26 
27  public static function getRootOrgRefId(){
29  return self::$root_ref_id;
30  }
31 
32  public static function getRootOrgId(){
34  return self::$root_id;
35  }
36 
37  private static function loadRootOrgRefIdAndId(){
38  if(self::$root_ref_id === Null || self::$root_id === null){
39  global $ilDB;
40  $q = "SELECT o.obj_id, r.ref_id FROM object_data o
41  INNER JOIN object_reference r ON r.obj_id = o.obj_id
42  WHERE title = ".$ilDB->quote('__OrgUnitAdministration', 'text')."";
43  $set = $ilDB->query($q);
44  $res = $ilDB->fetchAssoc($set);
45  self::$root_id = $res["obj_id"];
46  self::$root_ref_id= $res["ref_id"];
47  }
48  }
49 
50  private function loadRoles(){
51  global $ilLog;
52  if(!$this->employee_role || !$this->superior_role){
53  $this->doLoadRoles();
54  }
55 
56  if(!$this->employee_role || !$this->superior_role){
57  $this->initDefaultRoles();
58  $this->doLoadRoles();
59  if(!$this->employee_role || !$this->superior_role)
60  throw new Exception("The standard roles the orgu object with id: ".$this->getId()." aren't initialized or have been deleted, newly creating them didn't work!");
61  else
62  $ilLog->write("[".__FILE__.":".__LINE__."] The standard roles for the orgu obj with id: ".$this->getId()." were newly created as they couldnt be found.");
63  }
64  }
65 
66  private function doLoadRoles(){
67  global $ilDB;
68  if(!$this->employee_role || !$this->superior_role){
69  $q = "SELECT obj_id, title FROM object_data WHERE title LIKE 'il_orgu_employee_".$ilDB->quote($this->getRefId(),"integer")."' OR title LIKE 'il_orgu_superior_".$ilDB->quote($this->getRefId(),"integer")."'";
70  $set = $ilDB->query($q);
71  while($res = $ilDB->fetchAssoc($set)){
72  if($res["title"] == "il_orgu_employee_".$this->getRefId())
73  $this->employee_role = $res["obj_id"];
74  elseif($res["title"] == "il_orgu_superior_".$this->getRefId())
75  $this->superior_role = $res["obj_id"];
76  }
77 
78  if(!$this->employee_role || !$this->superior_role)
79  throw new Exception("The standard roles the orgu object with id: ".$this->getId()." aren't initialized or have been deleted!");
80  }
81  }
82 
83  public function assignUsersToEmployeeRole($user_ids){
84  global $rbacadmin, $ilAppEventHandler;
85  foreach($user_ids as $user_id)
86  {
87  $rbacadmin->assignUser($this->getEmployeeRole(), $user_id);
88 
89  $ilAppEventHandler->raise('Modules/OrgUnit',
90  'assignUsersToEmployeeRole',
91  array('object' => $this,
92  'obj_id' => $this->getId(),
93  'ref_id' => $this->getRefId(),
94  'role_id' => $this->getEmployeeRole(),
95  'user_id' => $user_id));
96  }
97  }
98 
99  public function assignUsersToSuperiorRole($user_ids){
100  global $rbacadmin, $ilAppEventHandler;
101  foreach($user_ids as $user_id)
102  {
103  $rbacadmin->assignUser($this->getSuperiorRole(), $user_id);
104 
105  $ilAppEventHandler->raise('Modules/OrgUnit',
106  'assignUsersToSuperiorRole',
107  array('object' => $this,
108  'obj_id' => $this->getId(),
109  'ref_id' => $this->getRefId(),
110  'role_id' => $this->getSuperiorRole(),
111  'user_id' => $user_id));
112  }
113 
114  }
115 
116  public function deassignUserFromEmployeeRole($user_id){
117  global $rbacadmin, $ilAppEventHandler;
118  $rbacadmin->deassignUser($this->getEmployeeRole(), $user_id);
119 
120  $ilAppEventHandler->raise('Modules/OrgUnit',
121  'deassignUserFromEmployeeRole',
122  array('object' => $this,
123  'obj_id' => $this->getId(),
124  'ref_id' => $this->getRefId(),
125  'role_id' => $this->getEmployeeRole(),
126  'user_id' => $user_id));
127  }
128 
129  public function deassignUserFromSuperiorRole($user_id){
130  global $rbacadmin, $ilAppEventHandler;
131  $rbacadmin->deassignUser($this->getSuperiorRole(), $user_id);
132 
133 
134  $ilAppEventHandler->raise('Modules/OrgUnit',
135  'deassignUserFromSuperiorRole',
136  array('object' => $this,
137  'obj_id' => $this->getId(),
138  'ref_id' => $this->getRefId(),
139  'role_id' => $this->getSuperiorRole(),
140  'user_id' => $user_id));
141  }
142 
147  {
148  $this->employee_role = $employee_role;
149  }
150 
151  public static function _exists($a_id, $a_reference = false){
152  return parent::_exists($a_id, $a_reference, "orgu");
153  }
154 
158  public function getEmployeeRole()
159  {
160  $this->loadRoles();
161  return $this->employee_role;
162  }
163 
168  {
169  $this->superior_role = $superior_role;
170  }
171 
175  public function getSuperiorRole()
176  {
177  $this->loadRoles();
178  return $this->superior_role;
179  }
180 
181  public function initDefaultRoles(){
182  global $rbacadmin,$rbacreview, $ilAppEventHandler;
183 
184  $rolf_obj = $this->createRoleFolder();
185 
186  // CREATE Employee ROLE
187  $role_obj = $rolf_obj->createRole("il_orgu_employee_".$this->getRefId(),"Emplyee of org unit obj_no.".$this->getId());
188 // = $
189 // EMPLOYEE DOES NOT YET NEED A ROLE TEMPLATE.
190 // // SET PERMISSION TEMPLATE OF NEW LOCAL ADMIN ROLE
191 // $query = "SELECT obj_id FROM object_data ".
192 // " WHERE type='rolt' AND title='il_orgu_employee'";
193 //
194 // $res = $this->ilias->db->getRow($query, DB_FETCHMODE_OBJECT);
195 // $rbacadmin->copyRoleTemplatePermissions($res->obj_id,ROLE_FOLDER_ID,$rolf_obj->getRefId(),$role_obj->getId());
196 //
197 // // SET OBJECT PERMISSIONS OF COURSE OBJECT
198 // $ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"orgu",$rolf_obj->getRefId());
199 // $rbacadmin->grantPermission($role_obj->getId(),$ops,$this->getRefId());
200 
201  // CREATE Superior ROLE
202  $role_obj = $rolf_obj->createRole("il_orgu_superior_".$this->getRefId(),"Superior of org unit obj_no.".$this->getId());
203 
204  // SET PERMISSION TEMPLATE OF NEW LOCAL ADMIN ROLE
205  $query = "SELECT obj_id FROM object_data ".
206  " WHERE type='rolt' AND title='il_orgu_superior'";
207 
208  $res = $this->ilias->db->getRow($query, DB_FETCHMODE_OBJECT);
209  $rbacadmin->copyRoleTemplatePermissions($res->obj_id,ROLE_FOLDER_ID,$rolf_obj->getRefId(),$role_obj->getId());
210 
211  // SET OBJECT PERMISSIONS OF COURSE OBJECT
212  $ops = $rbacreview->getOperationsOfRole($role_obj->getId(),"orgu",$rolf_obj->getRefId());
213  $rbacadmin->grantPermission($role_obj->getId(),$ops,$this->getRefId());
214 
215 
216  $ilAppEventHandler->raise('Modules/OrgUnit',
217  'initDefaultRoles',
218  array('object' => $this,
219  'obj_id' => $this->getId(),
220  'ref_id' => $this->getRefId(),
221  'role_superior_id' => $role_obj->getId(),
222  'role_employee_id' => $role_obj->getId()));
223 
224  }
225 
226  public function getTitle(){
227  if(parent::getTitle() != "__OrgUnitAdministration")
228  return parent::getTitle();
229  else
230  return $this->lng->txt("objs_orgu");
231  }
232 
236  public function getTranslations(){
237  global $lng, $ilDB;
238 
239  $translations = array();
240 
241  $q = "SELECT * FROM object_translation WHERE obj_id = ".
242  $ilDB->quote($this->getId(),'integer')." ORDER BY lang_default DESC";
243  $r = $this->ilias->db->query($q);
244 
245  $num = 0;
246 
247  while ($row = $r->fetchRow(DB_FETCHMODE_OBJECT))
248  {
249  $data["Fobject"][$num]= array("title" => $row->title,
250  "desc" => $row->description,
251  "lang" => $row->lang_code
252  );
253  $num++;
254  }
255 
256  $translations = $data;
257 
258  if(!count($translations["Fobject"])){
259  $this->addTranslation($this->getTitle(), "", $lng->getDefaultLanguage(), true);
260  $translations["Fobject"][] = array("title" => $this->getTitle(),
261  "desc" => "",
262  "lang" => $lng->getDefaultLanguage());
263  }
264  return $translations;
265  }
266 
267 
274  function delete()
275  {
276  global $ilDB,$ilAppEventHandler;
277 
278  // always call parent delete function first!!
279  if (!parent::delete())
280  {
281  return false;
282  }
283 
284  // put here category specific stuff
285  include_once('./Services/User/classes/class.ilObjUserFolder.php');
287 
288  $query = "DELETE FROM object_translation WHERE obj_id = ".$ilDB->quote($this->getId(),'integer');
289  $res = $ilDB->manipulate($query);
290 
291  $ilAppEventHandler->raise('Modules/OrgUnit',
292  'delete',
293  array('object' => $this,
294  'obj_id' => $this->getId()));
295 
296  return true;
297  }
298 
299 
300  // remove all Translations of current OrgUnit
302  {
303  global $ilDB;
304 
305  $query = "DELETE FROM object_translation WHERE obj_id= ".
306  $ilDB->quote($this->getId(),'integer');
307  $res = $ilDB->manipulate($query);
308  }
309 
310  // remove translations of current OrgUnit
311  function deleteTranslation($a_lang)
312  {
313  global $ilDB;
314 
315  $query = "DELETE FROM object_translation WHERE obj_id= ".
316  $ilDB->quote($this->getId(),'integer')." AND lang_code = ".
317  $ilDB->quote($a_lang, 'text');
318  $res = $ilDB->manipulate($query);
319  }
320 
321  // add a new translation to current OrgUnit
322  function addTranslation($a_title,$a_desc,$a_lang,$a_lang_default)
323  {
324  global $ilDB;
325 
326  if (empty($a_title))
327  {
328  $a_title = "NO TITLE";
329  }
330 
331  $query = "INSERT INTO object_translation ".
332  "(obj_id,title,description,lang_code,lang_default) ".
333  "VALUES ".
334  "(".$ilDB->quote($this->getId(),'integer').",".
335  $ilDB->quote($a_title,'text').",".$ilDB->quote($a_desc,'text').",".
336  $ilDB->quote($a_lang,'text').",".$ilDB->quote($a_lang_default,'integer').")";
337  $res = $ilDB->manipulate($query);
338 
339  return true;
340  }
341 
342  // update a translation to current OrgUnit
343  function updateTranslation($a_title,$a_desc,$a_lang,$a_lang_default)
344  {
345  global $ilDB, $ilLog;
346 
347  if (empty($a_title))
348  {
349  $a_title = "NO TITLE";
350  }
351 
352  $query = "UPDATE object_translation SET ";
353 
354 
355  $query .= " title = ". $ilDB->quote($a_title,'text');
356 
357 
358  if($a_desc != "") {
359  $query .= ", description = ".$ilDB->quote($a_desc,'text')." ";
360  }
361 
362  if($a_lang_default) {
363  $query .= ", lang_default = ".$ilDB->quote($a_lang_default,'integer')." ";
364  }
365 
366  $query .= " WHERE obj_id = ".$ilDB->quote($this->getId(),'integer')." AND lang_code = ".$ilDB->quote($a_lang,'text');
367  $res = $ilDB->manipulate($query);
368 
369  return true;
370  }
371 
372 
373 }
374 ?>