3 require_once(
"./Modules/OrgUnit/classes/class.ilObjOrgUnit.php");
55 $this->roles =
array();
56 $this->staff =
array();
64 if (self::$instance === null) {
65 self::$instance =
new self();
68 return self::$instance;
114 $all_refs = $ref_ids;
116 foreach ($ref_ids as $id =>
$ref_id) {
118 unset($ref_ids[$id]);
126 if (count($ref_ids)) {
127 $q =
"SELECT usr_id, rol_id FROM rbac_ua WHERE " . $this->db->in(
"rol_id", $ref_ids,
false,
"integer");
128 $set = $this->db->query($q);
129 while (
$res = $this->db->fetchAssoc($set)) {
130 $orgu_ref = $this->role_to_orgu[
$title][
$res[
"rol_id"]];
131 $this->staff[
$title][$orgu_ref][] = $res[
"usr_id"];
136 $all_users =
array();
137 foreach ($all_refs as $ref) {
138 $all_users = array_merge($all_users, $this->staff[
$title][$ref]);
152 while (count($open)) {
153 $ref = array_pop($open);
156 if (!in_array($child, $open) && !in_array($child, $closed)) {
184 $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 185 INNER JOIN rbac_operations ON rbac_operations.operation = " . $this->db->quote($operation,
"text") .
" 186 INNER JOIN rbac_ua ON rbac_ua.usr_id = " . $this->db->quote(
$ilUser->getId(),
"integer") .
" 187 INNER JOIN rbac_pa ON rbac_pa.rol_id = rbac_ua.rol_id AND rbac_pa.ops_id LIKE CONCAT('%', rbac_operations.ops_id, '%') 188 INNER JOIN object_reference ON object_reference.ref_id = rbac_pa.ref_id 189 WHERE object_data.obj_id = object_reference.obj_id AND object_data.type = 'orgu'";
191 $set = $this->db->query($q);
193 while (
$res = $this->db->fetchAssoc($set)) {
195 $perm_check = unserialize(
$res[
'ops_id']);
196 if (!in_array(
$res[
"op_id"], $perm_check)) {
200 $orgus[] =
$res[
"ref_id"];
217 $q =
"SELECT object_data.obj_id, object_data.title, object_data.type, rbac_pa.ops_id FROM object_data 218 INNER JOIN rbac_ua ON rbac_ua.usr_id = " . $this->db->quote(
$ilUser->getId(),
"integer") .
" 219 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") .
", '%') 220 INNER JOIN rbac_fa ON rbac_fa.rol_id = rbac_ua.rol_id 221 INNER JOIN tree ON tree.child = rbac_fa.parent 222 INNER JOIN object_reference ON object_reference.ref_id = tree.parent 223 WHERE object_data.obj_id = object_reference.obj_id AND object_data.type = 'orgu'";
225 $set = $this->db->query($q);
227 while (
$res = $this->db->fetchAssoc($set)) {
229 $perm_check = unserialize(
$res[
'ops_id']);
230 if (!in_array(
$res[
"ops_id"], $perm_check)) {
234 $orgus[] =
$res[
"obj_id"];
248 return $this->tree_childs[
$ref_id];
256 if (!$this->tree_childs[
$ref_id]) {
258 foreach ($this->tree->getChilds($ref_id) as $child) {
259 if ($child[
"type"] ==
"orgu") {
260 $children[] = $child[
"child"];
263 $this->tree_childs[
$ref_id] = $children;
275 while ($current_level < $level) {
276 $new_level =
array();
277 foreach ($levels[$current_level] as $orgu_ref) {
278 $new_level = array_merge($this->
getChildren($orgu_ref), $new_level);
280 $new_level = array_unique($new_level);
281 $levels[$current_level + 1] = $new_level;
285 return $levels[$level];
296 $q =
"SELECT orgu.obj_id, refr.ref_id FROM object_data orgu 297 INNER JOIN object_reference refr ON refr.obj_id = orgu.obj_id 298 INNER JOIN object_data roles ON roles.title LIKE CONCAT('il_orgu_superior_',refr.ref_id) 299 INNER JOIN rbac_ua rbac ON rbac.usr_id = " . $this->db->quote($user_id,
"integer") .
" AND roles.obj_id = rbac.rol_id 300 WHERE orgu.type = 'orgu'";
301 $set = $this->db->query($q);
302 $orgu_ref_ids =
array();
303 while (
$res = $this->db->fetchAssoc($set)) {
304 $orgu_ref_ids[] =
$res[
'ref_id'];
306 $employees =
array();
307 foreach ($orgu_ref_ids as $orgu_ref_id) {
308 $employees = array_merge($employees, $this->
getEmployees($orgu_ref_id, $recursive));
322 $q =
"SELECT orgu.obj_id, refr.ref_id FROM object_data orgu 323 INNER JOIN object_reference refr ON refr.obj_id = orgu.obj_id 324 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) 325 INNER JOIN rbac_ua rbac ON rbac.usr_id = " . $this->db->quote($user_id,
"integer") .
" AND roles.obj_id = rbac.rol_id 326 WHERE orgu.type = 'orgu'";
327 $set = $this->db->query($q);
328 $orgu_ref_ids =
array();
329 while (
$res = $this->db->fetchAssoc($set)) {
330 $orgu_ref_ids[] =
$res[
'ref_id'];
332 $superiors =
array();
333 foreach ($orgu_ref_ids as $orgu_ref_id) {
334 $superiors = array_merge($superiors, $this->
getSuperiors($orgu_ref_id, $recursive));
350 $q =
"SELECT object_reference.ref_id FROM rbac_ua 351 JOIN rbac_fa ON rbac_fa.rol_id = rbac_ua.rol_id 352 JOIN object_reference ON rbac_fa.parent = object_reference.ref_id 353 JOIN object_data ON object_data.obj_id = object_reference.obj_id 354 WHERE rbac_ua.usr_id = " . $this->db->quote($user_id,
'integer') .
" AND object_data.type = 'orgu';";
356 $set = $this->db->query($q);
357 $orgu_ref_ids =
array();
358 while (
$res = $this->db->fetchAssoc($set)) {
359 $orgu_ref_ids[] =
$res[
'ref_id'];
361 $orgus_on_level_x =
array();
362 foreach ($orgu_ref_ids as $orgu_ref_id) {
370 return array_unique($orgus_on_level_x);
382 $q =
"SELECT object_reference.ref_id FROM rbac_ua 383 JOIN rbac_fa ON rbac_fa.rol_id = rbac_ua.rol_id 384 JOIN object_reference ON rbac_fa.parent = object_reference.ref_id 385 JOIN object_data ON object_data.obj_id = object_reference.obj_id 386 WHERE rbac_ua.usr_id = " . $this->db->quote($user_id,
'integer') .
" AND object_data.type = 'orgu'";
388 $set = $this->db->query($q);
389 $orgu_ref_ids =
array();
390 while (
$res = $this->db->fetchAssoc($set)) {
391 $orgu_ref_ids[] =
$res[
'ref_id'];
393 $orgu_ref_ids = array_unique($orgu_ref_ids);
396 foreach ($orgu_ref_ids as $k => $refId) {
397 if (!in_array($refId, $childernOrgIds)) {
398 unset($orgu_ref_ids[$k]);
403 return $orgu_ref_ids;
426 if (self::$temporary_table_name === null) {
430 throw new ilException(
'there is already a temporary table for org-unit assignement: ' . self::$temporary_table_name);
434 SELECT DISTINCT object_reference.ref_id AS ref_id, rbac_ua.usr_id AS user_id, orgu_path_storage.path AS path 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 JOIN orgu_path_storage ON orgu_path_storage.ref_id = object_reference.ref_id 440 WHERE object_data.type = 'orgu' AND object_reference.deleted IS NULL 442 $this->db->manipulate($q);
456 $this->db->manipulate($q);
458 self::$temporary_table_name = null;
470 foreach ($org_refs as $org_unit) {
484 return $this->roles[
"employee"];
494 return $this->roles[
"superior"];
502 if ($this->roles[$role] == null) {
517 $this->roles[$role] =
array();
518 $q =
"SELECT obj_id, title FROM object_data WHERE type = 'role' AND title LIKE 'il_orgu_" . $role .
"%'";
519 $set = $this->db->query($q);
520 while (
$res = $this->db->fetchAssoc($set)) {
522 $this->roles[$role][$orgu_ref] =
$res[
"obj_id"];
523 $this->role_to_orgu[$role][
$res[
"obj_id"]] = $orgu_ref;
533 $array = explode(
"_", $role_title);
535 return $array[count($array) - 1];
558 $line =
array( $orgu_ref );
559 $current_ref = $orgu_ref;
561 $current_ref = $this->
getParent($current_ref);
563 $line[] = $current_ref;
567 if (count($line) > 100) {
568 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");
571 $line = array_reverse($line);
572 if (count($line) > $level) {
573 return $line[$level];
575 throw new Exception(
"you want to fetch level " . $level .
" but the line to the length of the line is only " . count($line)
576 .
". The line of the given org unit is: " . print_r($line,
true));
586 if (!$this->
parent[$orgu_ref]) {
587 $this->
parent[$orgu_ref] = $this->tree->getParentId($orgu_ref);
590 return $this->
parent[$orgu_ref];
getRefIdFromRoleTitle($role_title)
Base class for ILIAS Exception handling.
static _lookupTitle($a_id)
lookup object title
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)
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