56 $this->roles =
array();
57 $this->staff =
array();
66 if (self::$instance === null) {
67 self::$instance =
new self();
70 return self::$instance;
96 'position_id' => $ilOrgUnitPosition->
getId(),
97 ))->getArray(
'id',
'user_id');
140 $all_refs = $ref_ids;
142 foreach ($ref_ids as
$id => $ref_id) {
143 if (isset($this->staff[
$title][$ref_id])) {
144 unset($ref_ids[
$id]);
147 $ref_ids[
$id] = $this->roles[
$title][$ref_id];
152 if (count($ref_ids)) {
153 $q =
"SELECT usr_id, rol_id FROM rbac_ua WHERE " 154 . $this->db->in(
"rol_id", $ref_ids,
false,
"integer");
155 $set = $this->db->query($q);
156 while (
$res = $this->db->fetchAssoc($set)) {
157 $orgu_ref = $this->role_to_orgu[
$title][
$res[
"rol_id"]];
158 $this->staff[
$title][$orgu_ref][] = $res[
"usr_id"];
163 $all_users =
array();
164 foreach ($all_refs as $ref) {
165 $all_users = array_merge($all_users, $this->staff[
$title][$ref]);
179 $open =
array( $ref_id );
181 while (count($open)) {
182 $ref = array_pop($open);
185 if (!in_array($child, $open) && !in_array($child, $closed)) {
216 $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 217 INNER JOIN rbac_operations ON rbac_operations.operation = " 218 . $this->db->quote($operation,
"text") .
" 219 INNER JOIN rbac_ua ON rbac_ua.usr_id = " . $this->db->quote(
$ilUser->getId(),
"integer") .
" 220 INNER JOIN rbac_pa ON rbac_pa.rol_id = rbac_ua.rol_id AND rbac_pa.ops_id LIKE CONCAT('%', rbac_operations.ops_id, '%') 221 INNER JOIN object_reference ON object_reference.ref_id = rbac_pa.ref_id 222 WHERE object_data.obj_id = object_reference.obj_id AND object_data.type = 'orgu'";
224 $set = $this->db->query($q);
226 while (
$res = $this->db->fetchAssoc($set)) {
228 $perm_check = unserialize(
$res[
'ops_id']);
229 if (!in_array(
$res[
"op_id"], $perm_check)) {
233 $orgus[] =
$res[
"ref_id"];
252 $q =
"SELECT object_data.obj_id, object_data.title, object_data.type, rbac_pa.ops_id FROM object_data 253 INNER JOIN rbac_ua ON rbac_ua.usr_id = " . $this->db->quote(
$ilUser->getId(),
"integer") .
" 254 INNER JOIN rbac_pa ON rbac_pa.rol_id = rbac_ua.rol_id AND rbac_pa.ops_id LIKE CONCAT('%', " 255 . $this->db->quote($operation_id,
"integer") .
", '%') 256 INNER JOIN rbac_fa ON rbac_fa.rol_id = rbac_ua.rol_id 257 INNER JOIN tree ON tree.child = rbac_fa.parent 258 INNER JOIN object_reference ON object_reference.ref_id = tree.parent 259 WHERE object_data.obj_id = object_reference.obj_id AND object_data.type = 'orgu'";
261 $set = $this->db->query($q);
263 while (
$res = $this->db->fetchAssoc($set)) {
265 $perm_check = unserialize(
$res[
'ops_id']);
266 if (!in_array(
$res[
"ops_id"], $perm_check)) {
270 $orgus[] =
$res[
"obj_id"];
286 return $this->tree_childs[$ref_id];
295 if (!$this->tree_childs[$ref_id]) {
297 foreach ($this->tree->getChilds($ref_id) as $child) {
298 if ($child[
"type"] ==
"orgu") {
299 $children[] = $child[
"child"];
302 $this->tree_childs[$ref_id] = $children;
316 while ($current_level < $level) {
317 $new_level =
array();
318 foreach ($levels[$current_level] as $orgu_ref) {
319 $new_level = array_merge($this->
getChildren($orgu_ref), $new_level);
321 $new_level = array_unique($new_level);
322 $levels[$current_level + 1] = $new_level;
326 return $levels[$level];
341 $q =
"SELECT orgu.obj_id, refr.ref_id FROM object_data orgu 342 INNER JOIN object_reference refr ON refr.obj_id = orgu.obj_id 343 INNER JOIN object_data roles ON roles.title LIKE CONCAT('il_orgu_superior_',refr.ref_id) 344 INNER JOIN rbac_ua rbac ON rbac.usr_id = " . $this->db->quote($user_id,
"integer") .
" AND roles.obj_id = rbac.rol_id 345 WHERE orgu.type = 'orgu'";
346 $set = $this->db->query($q);
347 $orgu_ref_ids =
array();
348 while (
$res = $this->db->fetchAssoc($set)) {
349 $orgu_ref_ids[] =
$res[
'ref_id'];
351 $employees =
array();
352 foreach ($orgu_ref_ids as $orgu_ref_id) {
353 $employees = array_merge($employees, $this->
getEmployees($orgu_ref_id, $recursive));
371 $q =
"SELECT orgu.obj_id, refr.ref_id FROM object_data orgu 372 INNER JOIN object_reference refr ON refr.obj_id = orgu.obj_id 373 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) 374 INNER JOIN rbac_ua rbac ON rbac.usr_id = " . $this->db->quote($user_id,
"integer") .
" AND roles.obj_id = rbac.rol_id 375 WHERE orgu.type = 'orgu'";
376 $set = $this->db->query($q);
377 $orgu_ref_ids =
array();
378 while (
$res = $this->db->fetchAssoc($set)) {
379 $orgu_ref_ids[] =
$res[
'ref_id'];
381 $superiors =
array();
382 foreach ($orgu_ref_ids as $orgu_ref_id) {
383 $superiors = array_merge($superiors, $this->
getSuperiors($orgu_ref_id, $recursive));
400 $q =
"SELECT object_reference.ref_id FROM rbac_ua 401 JOIN rbac_fa ON rbac_fa.rol_id = rbac_ua.rol_id 402 JOIN object_reference ON rbac_fa.parent = object_reference.ref_id 403 JOIN object_data ON object_data.obj_id = object_reference.obj_id 404 WHERE rbac_ua.usr_id = " . $this->db->quote($user_id,
'integer')
405 .
" AND object_data.type = 'orgu';";
407 $set = $this->db->query($q);
408 $orgu_ref_ids =
array();
409 while (
$res = $this->db->fetchAssoc($set)) {
410 $orgu_ref_ids[] =
$res[
'ref_id'];
412 $orgus_on_level_x =
array();
413 foreach ($orgu_ref_ids as $orgu_ref_id) {
421 return array_unique($orgus_on_level_x);
435 $q =
"SELECT object_reference.ref_id FROM rbac_ua 436 JOIN rbac_fa ON rbac_fa.rol_id = rbac_ua.rol_id 437 JOIN object_reference ON rbac_fa.parent = object_reference.ref_id 438 JOIN object_data ON object_data.obj_id = object_reference.obj_id 439 WHERE rbac_ua.usr_id = " . $this->db->quote($user_id,
'integer')
440 .
" AND object_data.type = 'orgu'";
442 $set = $this->db->query($q);
443 $orgu_ref_ids =
array();
444 while (
$res = $this->db->fetchAssoc($set)) {
445 $orgu_ref_ids[] =
$res[
'ref_id'];
447 $orgu_ref_ids = array_unique($orgu_ref_ids);
450 foreach ($orgu_ref_ids as $k => $refId) {
451 if (!in_array($refId, $childernOrgIds)) {
452 unset($orgu_ref_ids[$k]);
457 return $orgu_ref_ids;
482 if (self::$temporary_table_name === null) {
486 throw new ilException(
'there is already a temporary table for org-unit assignement: ' 487 . self::$temporary_table_name);
491 SELECT DISTINCT object_reference.ref_id AS ref_id, il_orgu_ua.user_id AS user_id, orgu_path_storage.path AS path 493 JOIN object_reference ON object_reference.ref_id = il_orgu_ua.orgu_id 494 JOIN object_data ON object_data.obj_id = object_reference.obj_id 495 JOIN orgu_path_storage ON orgu_path_storage.ref_id = object_reference.ref_id 496 WHERE object_data.type = 'orgu' AND object_reference.deleted IS NULL 498 $this->db->manipulate($q);
511 if (self::$temporary_table_name === null
516 $this->db->manipulate($q);
518 self::$temporary_table_name = null;
532 foreach ($org_refs as $org_unit) {
547 return $this->roles[
"employee"];
558 return $this->roles[
"superior"];
567 if ($this->roles[$role] == null) {
584 $this->roles[$role] =
array();
585 $q =
"SELECT obj_id, title FROM object_data WHERE type = 'role' AND title LIKE 'il_orgu_" 587 $set = $this->db->query($q);
588 while (
$res = $this->db->fetchAssoc($set)) {
590 $this->roles[$role][$orgu_ref] =
$res[
"obj_id"];
591 $this->role_to_orgu[$role][
$res[
"obj_id"]] = $orgu_ref;
603 $array = explode(
"_", $role_title);
605 return $array[count($array) - 1];
631 $line =
array( $orgu_ref );
632 $current_ref = $orgu_ref;
634 $current_ref = $this->
getParent($current_ref);
636 $line[] = $current_ref;
640 if (count($line) > 100) {
641 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");
644 $line = array_reverse($line);
645 if (count($line) > $level) {
646 return $line[$level];
648 throw new Exception(
"you want to fetch level " . $level
649 .
" but the line to the length of the line is only " . count($line)
650 .
". The line of the given org unit is: " . print_r($line,
true));
662 if (!$this->parent[$orgu_ref]) {
663 $this->parent[$orgu_ref] = $this->tree->getParentId($orgu_ref);
666 return $this->parent[$orgu_ref];
getRefIdFromRoleTitle($role_title)
if(!array_key_exists('StateId', $_REQUEST)) $id
static _lookupTitle($a_id)
lookup object title
static where($where, $operator=null)
getAssignements($ref_id, ilOrgUnitPosition $ilOrgUnitPosition)
getSuperiorsOfUser($user_id, $recursive=true)
static $temporary_table_name
getOrgusWhereUserHasPermissionForOperationId($operation_id)
If you want to have all orgunits where the current user has the write permission: use this with the p...
getEmployees($ref_id, $recursive=false)
foreach($_POST as $key=> $value) $res
loadArrayOfStaff($title, $ref_ids)
static _lookupObjId($a_id)
getEmployeesUnderUser($user_id, $recursive=true)
getSuperiors($ref_id, $recursive=false)
loadStaffRecursive($title, $ref_id)
Class ilObjOrgUnitTree Implements a singleton pattern for caching.
Create styles array
The data for the language used.
loadStaff($title, $ref_id)
getLevelXOfTreenode($orgu_ref, $level)
Specify eg.
dropTempTable($temporary_table_name)
getAllOrgunitsOnLevelX($level)
buildTempTableWithUsrAssignements($temporary_table_name='orgu_usr_assignements')
Creates a temporary table with all orgu/user assignements.
getLevelXOfUser($user_id, $level)
for additional info see the other getLevelX method.
getOrgusWhereUserHasPermissionForOperation($operation)
If you want to have all orgunits where the current user has the write permission: use this with the p...
getOrgUnitOfUser($user_id, $ref_id=0)
getOrgUnitOfUser