56 $this->roles = array();
57 $this->staff = array();
66 if (self::$instance === null) {
67 self::$instance =
new self();
70 return self::$instance;
90 $arr_usr_ids = $arr_usr_ids
109 'orgu_id' => $ref_id,
110 'position_id' => $ilOrgUnitPosition->
getId(),
111 ))->getArray(
'id',
'user_id');
125 switch ($recursive) {
131 $arr_usr_ids = $arr_usr_ids
150 $all_refs = $ref_ids;
152 foreach ($ref_ids as
$id => $ref_id) {
153 if (isset($this->staff[
$title][$ref_id])) {
154 unset($ref_ids[
$id]);
156 $this->staff[
$title][$ref_id] = array();
157 $ref_ids[
$id] = $this->roles[
$title][$ref_id];
162 if (count($ref_ids)) {
163 $q =
"SELECT usr_id, rol_id FROM rbac_ua WHERE " . $this->db->in(
"rol_id", $ref_ids,
false,
"integer");
164 $set = $this->db->query($q);
165 while (
$res = $this->db->fetchAssoc($set)) {
166 $orgu_ref = $this->role_to_orgu[
$title][
$res[
"rol_id"]];
167 $this->staff[
$title][$orgu_ref][] = $res[
"usr_id"];
172 $all_users = array();
173 foreach ($all_refs as $ref) {
174 $all_users = array_merge($all_users, $this->staff[
$title][$ref]);
188 $open = array( $ref_id );
190 while (count($open)) {
191 $ref = array_pop($open);
194 if (!in_array($child, $open) && !in_array($child, $closed)) {
225 $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 226 INNER JOIN rbac_operations ON rbac_operations.operation = " . $this->db->quote($operation,
"text") .
" 227 INNER JOIN rbac_ua ON rbac_ua.usr_id = " . $this->db->quote(
$ilUser->getId(),
"integer") .
" 228 INNER JOIN rbac_pa ON rbac_pa.rol_id = rbac_ua.rol_id AND rbac_pa.ops_id LIKE CONCAT('%', rbac_operations.ops_id, '%') 229 INNER JOIN object_reference ON object_reference.ref_id = rbac_pa.ref_id 230 WHERE object_data.obj_id = object_reference.obj_id AND object_data.type = 'orgu'";
232 $set = $this->db->query($q);
234 while (
$res = $this->db->fetchAssoc($set)) {
236 $perm_check = unserialize(
$res[
'ops_id']);
237 if (!in_array(
$res[
"op_id"], $perm_check)) {
241 $orgus[] =
$res[
"ref_id"];
260 $q =
"SELECT object_data.obj_id, object_data.title, object_data.type, rbac_pa.ops_id FROM object_data 261 INNER JOIN rbac_ua ON rbac_ua.usr_id = " . $this->db->quote(
$ilUser->getId(),
"integer") .
" 262 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") .
", '%') 263 INNER JOIN rbac_fa ON rbac_fa.rol_id = rbac_ua.rol_id 264 INNER JOIN tree ON tree.child = rbac_fa.parent 265 INNER JOIN object_reference ON object_reference.ref_id = tree.parent 266 WHERE object_data.obj_id = object_reference.obj_id AND object_data.type = 'orgu'";
268 $set = $this->db->query($q);
270 while (
$res = $this->db->fetchAssoc($set)) {
272 $perm_check = unserialize(
$res[
'ops_id']);
273 if (!in_array(
$res[
"ops_id"], $perm_check)) {
277 $orgus[] =
$res[
"obj_id"];
293 return $this->tree_childs[$ref_id];
302 if (!$this->tree_childs[$ref_id]) {
304 foreach ($this->tree->getChilds($ref_id) as $child) {
305 if ($child[
"type"] ==
"orgu") {
306 $children[] = $child[
"child"];
309 $this->tree_childs[$ref_id] = $children;
323 while ($current_level < $level) {
324 $new_level = array();
325 foreach ($levels[$current_level] as $orgu_ref) {
326 $new_level = array_merge($this->
getChildren($orgu_ref), $new_level);
328 $new_level = array_unique($new_level);
329 $levels[$current_level + 1] = $new_level;
333 return $levels[$level];
348 $q =
"SELECT orgu.obj_id, refr.ref_id FROM object_data orgu 349 INNER JOIN object_reference refr ON refr.obj_id = orgu.obj_id 350 INNER JOIN object_data roles ON roles.title LIKE CONCAT('il_orgu_superior_',refr.ref_id) 351 INNER JOIN rbac_ua rbac ON rbac.usr_id = " . $this->db->quote($user_id,
"integer") .
" AND roles.obj_id = rbac.rol_id 352 WHERE orgu.type = 'orgu'";
353 $set = $this->db->query($q);
354 $orgu_ref_ids = array();
355 while (
$res = $this->db->fetchAssoc($set)) {
356 $orgu_ref_ids[] =
$res[
'ref_id'];
358 $employees = array();
359 foreach ($orgu_ref_ids as $orgu_ref_id) {
360 $employees = array_merge($employees, $this->
getEmployees($orgu_ref_id, $recursive));
378 $q =
"SELECT orgu.obj_id, refr.ref_id FROM object_data orgu 379 INNER JOIN object_reference refr ON refr.obj_id = orgu.obj_id 380 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) 381 INNER JOIN rbac_ua rbac ON rbac.usr_id = " . $this->db->quote($user_id,
"integer") .
" AND roles.obj_id = rbac.rol_id 382 WHERE orgu.type = 'orgu'";
383 $set = $this->db->query($q);
384 $orgu_ref_ids = array();
385 while (
$res = $this->db->fetchAssoc($set)) {
386 $orgu_ref_ids[] =
$res[
'ref_id'];
388 $superiors = array();
389 foreach ($orgu_ref_ids as $orgu_ref_id) {
390 $superiors = array_merge($superiors, $this->
getSuperiors($orgu_ref_id, $recursive));
407 $q =
"SELECT object_reference.ref_id FROM rbac_ua 408 JOIN rbac_fa ON rbac_fa.rol_id = rbac_ua.rol_id 409 JOIN object_reference ON rbac_fa.parent = object_reference.ref_id 410 JOIN object_data ON object_data.obj_id = object_reference.obj_id 411 WHERE rbac_ua.usr_id = " . $this->db->quote($user_id,
'integer') .
" AND object_data.type = 'orgu';";
413 $set = $this->db->query($q);
414 $orgu_ref_ids = array();
415 while (
$res = $this->db->fetchAssoc($set)) {
416 $orgu_ref_ids[] =
$res[
'ref_id'];
418 $orgus_on_level_x = array();
419 foreach ($orgu_ref_ids as $orgu_ref_id) {
427 return array_unique($orgus_on_level_x);
441 $q =
"SELECT object_reference.ref_id FROM rbac_ua 442 JOIN rbac_fa ON rbac_fa.rol_id = rbac_ua.rol_id 443 JOIN object_reference ON rbac_fa.parent = object_reference.ref_id 444 JOIN object_data ON object_data.obj_id = object_reference.obj_id 445 WHERE rbac_ua.usr_id = " . $this->db->quote($user_id,
'integer') .
" AND object_data.type = 'orgu'";
447 $set = $this->db->query($q);
448 $orgu_ref_ids = array();
449 while (
$res = $this->db->fetchAssoc($set)) {
450 $orgu_ref_ids[] =
$res[
'ref_id'];
452 $orgu_ref_ids = array_unique($orgu_ref_ids);
455 foreach ($orgu_ref_ids as $k => $refId) {
456 if (!in_array($refId, $childernOrgIds)) {
457 unset($orgu_ref_ids[$k]);
462 return $orgu_ref_ids;
487 if (self::$temporary_table_name === null) {
491 throw new ilException(
'there is already a temporary table for org-unit assignement: ' . self::$temporary_table_name);
495 SELECT DISTINCT object_reference.ref_id AS ref_id, il_orgu_ua.user_id AS user_id, orgu_path_storage.path AS path 497 JOIN object_reference ON object_reference.ref_id = il_orgu_ua.orgu_id 498 JOIN object_data ON object_data.obj_id = object_reference.obj_id 499 JOIN orgu_path_storage ON orgu_path_storage.ref_id = object_reference.ref_id 500 WHERE object_data.type = 'orgu' AND object_reference.deleted IS NULL 502 $this->db->manipulate($q);
515 if (self::$temporary_table_name === null
520 $this->db->manipulate($q);
522 self::$temporary_table_name = null;
536 foreach ($org_refs as $org_unit) {
551 return $this->roles[
"employee"];
562 return $this->roles[
"superior"];
571 if ($this->roles[$role] == null) {
588 $this->roles[$role] = array();
589 $q =
"SELECT obj_id, title FROM object_data WHERE type = 'role' AND title LIKE 'il_orgu_" . $role .
"%'";
590 $set = $this->db->query($q);
591 while (
$res = $this->db->fetchAssoc($set)) {
593 $this->roles[$role][$orgu_ref] =
$res[
"obj_id"];
594 $this->role_to_orgu[$role][
$res[
"obj_id"]] = $orgu_ref;
606 $array = explode(
"_", $role_title);
608 return $array[count($array) - 1];
634 $line = array( $orgu_ref );
635 $current_ref = $orgu_ref;
637 $current_ref = $this->
getParent($current_ref);
639 $line[] = $current_ref;
643 if (count($line) > 100) {
644 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");
647 $line = array_reverse($line);
648 if (count($line) > $level) {
649 return $line[$level];
651 throw new Exception(
"you want to fetch level " . $level .
" but the line to the length of the line is only " . count($line)
652 .
". The line of the given org unit is: " . print_r($line,
true));
664 if (!$this->
parent[$orgu_ref]) {
665 $this->
parent[$orgu_ref] = $this->tree->getParentId($orgu_ref);
668 return $this->
parent[$orgu_ref];
getRefIdFromRoleTitle($role_title)
const CORE_POSITION_EMPLOYEE
if(!array_key_exists('StateId', $_REQUEST)) $id
static getCorePosition($core_identifier)
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)
Class ilObjOrgUnitTree Implements a singleton pattern for caching.
getLevelXOfTreenode($orgu_ref, $level)
Specify eg.
const CORE_POSITION_SUPERIOR
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