3 require_once(
"./Modules/OrgUnit/classes/class.ilObjOrgUnit.php");
43 $this->roles = array();
44 $this->staff = array();
49 if(self::$instance == null)
89 foreach($ref_ids as $id =>
$ref_id){
90 if(isset($this->staff[$title][
$ref_id]))
93 $this->staff[$title][
$ref_id] = array();
94 $ref_ids[$id] = $this->roles[$title][
$ref_id];
100 $q =
"SELECT usr_id, rol_id FROM rbac_ua WHERE ".$this->db->in(
"rol_id", $ref_ids,
false,
"integer");
101 $set = $this->db->query($q);
102 while(
$res = $this->db->fetchAssoc($set)){
103 $orgu_ref = $this->role_to_orgu[$title][
$res[
"rol_id"]];
104 $this->staff[$title][$orgu_ref][] = $res[
"usr_id"];
109 $all_users = array();
110 foreach($all_refs as $ref)
111 $all_users = array_merge($all_users, $this->staff[$title][$ref]);
120 $ref = array_pop($open);
123 if(!in_array($child, $open) && ! in_array($child, $closed))
145 $q =
"SELECT object_data.obj_id, object_reference.ref_id, object_data.title, object_data.type, rbac_pa.ops_id, rbac_operations.ops_id as op_id FROM object_data
146 INNER JOIN rbac_operations ON rbac_operations.operation = ".$this->db->quote($operation,
"text").
"
147 INNER JOIN rbac_ua ON rbac_ua.usr_id = ".$this->db->quote($ilUser->getId(),
"integer").
"
148 INNER JOIN rbac_pa ON rbac_pa.rol_id = rbac_ua.rol_id AND rbac_pa.ops_id LIKE CONCAT('%', rbac_operations.ops_id, '%')
149 INNER JOIN object_reference ON object_reference.ref_id = rbac_pa.ref_id
150 WHERE object_data.obj_id = object_reference.obj_id AND object_data.type = 'orgu'";
152 $set = $this->db->query($q);
154 while(
$res = $this->db->fetchAssoc($set)){
156 $perm_check = unserialize(
$res[
'ops_id']);
157 if(!in_array(
$res[
"op_id"], $perm_check))
160 $orgus[] =
$res[
"ref_id"];
172 $q =
"SELECT object_data.obj_id, object_data.title, object_data.type, rbac_pa.ops_id FROM object_data
173 INNER JOIN rbac_ua ON rbac_ua.usr_id = ".$this->db->quote($ilUser->getId(),
"integer").
"
174 INNER JOIN rbac_pa ON rbac_pa.rol_id = rbac_ua.rol_id AND rbac_pa.ops_id LIKE CONCAT('%', ".$this->db->quote($operation_id,
"integer").
", '%')
175 INNER JOIN rbac_fa ON rbac_fa.rol_id = rbac_ua.rol_id
176 INNER JOIN tree ON tree.child = rbac_fa.parent
177 INNER JOIN object_reference ON object_reference.ref_id = tree.parent
178 WHERE object_data.obj_id = object_reference.obj_id AND object_data.type = 'orgu'";
180 $set = $this->db->query($q);
182 while(
$res = $this->db->fetchAssoc($set)){
184 $perm_check = unserialize(
$res[
'ops_id']);
185 if(!in_array(
$res[
"ops_id"], $perm_check))
188 $orgus[] =
$res[
"obj_id"];
199 return $this->tree_childs[
$ref_id];
203 if(!$this->tree_childs[
$ref_id]){
205 foreach($this->tree->getChilds($ref_id) as $child){
206 if($child[
"type"] ==
"orgu")
207 $children[] = $child[
"child"];
209 $this->tree_childs[
$ref_id] = $children;
216 while($current_level < $level){
217 $new_level = array();
218 foreach($levels[$current_level] as $orgu_ref)
219 $new_level = array_merge($this->
getChildren($orgu_ref), $new_level);
220 $new_level = array_unique($new_level);
221 $levels[$current_level+1] = $new_level;
224 return $levels[$level];
234 $q =
"SELECT orgu.obj_id, refr.ref_id FROM object_data orgu
235 INNER JOIN object_reference refr ON refr.obj_id = orgu.obj_id
236 INNER JOIN object_data roles ON roles.title LIKE CONCAT('il_orgu_superior_',refr.ref_id)
237 INNER JOIN rbac_ua rbac ON rbac.usr_id = ".$this->db->quote($user_id,
"integer").
" AND roles.obj_id = rbac.rol_id
238 WHERE orgu.type = 'orgu'";
239 $set = $this->db->query($q);
240 $orgu_ref_ids = array();
241 while(
$res = $this->db->fetchAssoc($set)){
242 $orgu_ref_ids[] =
$res[
'ref_id'];
244 $employees = array();
245 foreach($orgu_ref_ids as $orgu_ref_id){
246 $employees = array_merge($employees, $this->
getEmployees($orgu_ref_id, $recursive));
258 $q =
"SELECT orgu.obj_id, refr.ref_id FROM object_data orgu
259 INNER JOIN object_reference refr ON refr.obj_id = orgu.obj_id
260 INNER JOIN object_data roles ON roles.title LIKE CONCAT('il_orgu_employee_',refr.ref_id) OR roles.title LIKE CONCAT('il_orgu_superior_',refr.ref_id)
261 INNER JOIN rbac_ua rbac ON rbac.usr_id = ".$this->db->quote($user_id,
"integer").
" AND roles.obj_id = rbac.rol_id
262 WHERE orgu.type = 'orgu'";
263 $set = $this->db->query($q);
264 $orgu_ref_ids = array();
265 while(
$res = $this->db->fetchAssoc($set)){
266 $orgu_ref_ids[] =
$res[
'ref_id'];
268 $superiors = array();
269 foreach($orgu_ref_ids as $orgu_ref_id){
270 $superiors = array_merge($superiors, $this->
getSuperiors($orgu_ref_id, $recursive));
285 $q =
"SELECT orgu.obj_id, refr.ref_id FROM object_data orgu
286 INNER JOIN object_reference refr ON refr.obj_id = orgu.obj_id
287 INNER JOIN object_data roles ON roles.title LIKE CONCAT('il_orgu_superior_',refr.ref_id) OR roles.title LIKE CONCAT('il_orgu_employee_',refr.ref_id)
288 INNER JOIN rbac_ua rbac ON rbac.usr_id = " . $this->db->quote($user_id,
"integer") .
" AND roles.obj_id = rbac.rol_id
289 WHERE orgu.type = 'orgu' AND refr.deleted IS NULL";
290 $set = $this->db->query($q);
291 $orgu_ref_ids = array();
292 while (
$res = $this->db->fetchAssoc($set)) {
293 $orgu_ref_ids[] =
$res[
'ref_id'];
295 $orgus_on_level_x = array();
296 foreach($orgu_ref_ids as $orgu_ref_id){
304 return array_unique($orgus_on_level_x);
316 $q =
"SELECT orgu.obj_id, refr.ref_id FROM object_data orgu
317 INNER JOIN object_reference refr ON refr.obj_id = orgu.obj_id
318 INNER JOIN object_data roles ON roles.title LIKE CONCAT('il_orgu_superior_',refr.ref_id) OR roles.title LIKE CONCAT('il_orgu_employee_',refr.ref_id)
319 INNER JOIN rbac_ua rbac ON rbac.usr_id = ".$this->db->quote($user_id,
"integer").
" AND roles.obj_id = rbac.rol_id
320 WHERE orgu.type = 'orgu' AND refr.deleted IS NULL";
321 $set = $this->db->query($q);
322 $orgu_ref_ids = array();
323 while(
$res = $this->db->fetchAssoc($set)){
324 $orgu_ref_ids[] =
$res[
'ref_id'];
326 $orgu_ref_ids = array_unique($orgu_ref_ids);
329 foreach ($orgu_ref_ids as $k => $refId) {
330 if (!in_array($refId, $childernOrgIds)) {
331 unset($orgu_ref_ids[$k]);
335 return $orgu_ref_ids;
340 foreach($org_refs as $org_unit){
351 return $this->roles[
"employee"];
356 return $this->roles[
"superior"];
360 if($this->roles[$role] == null){
370 $this->roles[$role] = array();
371 $q =
"SELECT obj_id, title FROM object_data WHERE type = 'role' AND title LIKE 'il_orgu_".$role.
"%'";
372 $set = $this->db->query($q);
373 while(
$res = $this->db->fetchAssoc($set)){
375 $this->roles[$role][$orgu_ref] =
$res[
"obj_id"];
376 $this->role_to_orgu[$role][
$res[
"obj_id"]] = $orgu_ref;
381 $array = explode(
"_", $role_title);
382 return $array[count($array) - 1];
403 $line = array($orgu_ref);
404 $current_ref = $orgu_ref;
406 $current_ref = $this->
getParent($current_ref);
408 $line[] = $current_ref;
411 if(count($line) > 100)
412 throw new Exception(
"There's either a non valid call of the getLevelXOfTreenode in ilObjOrgUnitTree or your nesting of orgunits is higher than 100 units, which isn't encouraged");
414 $line = array_reverse($line);
415 if(count($line) > $level)
416 return $line[$level];
418 throw new Exception(
"you want to fetch level ".$level.
" but the line to the length of the line is only ".count($line).
". The line of the given org unit is: ".print_r($line ,
true));
422 if(!$this->parent[$orgu_ref]){
423 $this->parent[$orgu_ref] = $this->tree->getParentId($orgu_ref);
425 return $this->parent[$orgu_ref];