ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilObjOrgUnitTree Class Reference

Class ilObjOrgUnitTree Implements a singleton pattern for caching. More...

+ Collaboration diagram for ilObjOrgUnitTree:

Public Member Functions

 getEmployees ($ref_id, $recursive=false)
 getSuperiors ($ref_id, $recursive=false)
 getAllChildren ($ref_id)
 getOrgusWhereUserHasPermissionForOperation ($operation)
 If you want to have all orgunits where the current user has the write permission: use this with the parameter "write".
 getOrgusWhereUserHasPermissionForOperationId ($operation_id)
 If you want to have all orgunits where the current user has the write permission: use this with the parameter 3 (3 is the "write" permission as in rbac_operations).
 getAllOrgunitsOnLevelX ($level)
 getEmployeesUnderUser ($user_id, $recursive=true)
 getSuperiorsOfUser ($user_id, $recursive=true)
 getLevelXOfUser ($user_id, $level)
 for additional info see the other getLevelX method.
 getOrgUnitOfUser ($user_id, $ref_id=0)
 getOrgUnitOfUser
 getTitles ($org_refs)
 getEmployeeRoles ()
 getSuperiorRoles ()
 flushCache ()
 getLevelXOfTreenode ($orgu_ref, $level)
 Specify eg.
 getParent ($orgu_ref)

Static Public Member Functions

static _getInstance ()
 singleton access.

Private Member Functions

 __construct ()
 making the construct private
 loadStaff ($title, $ref_id)
 loadStaffRecursive ($title, $ref_id)
 loadArrayOfStaff ($title, $ref_ids)
 getChildren ($ref_id)
 loadChildren ($ref_id)
 loadRoles ($role)
 loadRolesQuery ($role)
 getRefIdFromRoleTitle ($role_title)

Private Attributes

 $roles
 $role_to_orgu
 $staff
 $tree_childs
 $ctrl
 $parent
 $db

Static Private Attributes

static $instance

Detailed Description

Class ilObjOrgUnitTree Implements a singleton pattern for caching.

Author
: Oskar Truffer ot@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch
: Martin Studer ms@st.nosp@m.uder.nosp@m.-raim.nosp@m.ann..nosp@m.ch

Definition at line 12 of file class.ilObjOrgUnitTree.php.

Constructor & Destructor Documentation

ilObjOrgUnitTree::__construct ( )
private

making the construct private

Definition at line 38 of file class.ilObjOrgUnitTree.php.

References $ilCtrl, and $ilDB.

{
global $ilCtrl, $ilDB, $tree;
$this->ctrl = $ilCtrl;
$this->db = $ilDB;
$this->tree = $tree;
$this->roles = array();
$this->staff = array();
}

Member Function Documentation

static ilObjOrgUnitTree::_getInstance ( )
static

singleton access.

Definition at line 48 of file class.ilObjOrgUnitTree.php.

References $instance.

Referenced by ilObjOrgUnitAccess\_checkAccessToUserLearningProgress(), ilOrgUnitStaffTableGUI\fillRow(), ilOrgUnitStaffTableGUI\parseData(), and ilOrgUnitStaffTableGUI\setRowForUser().

{
if(self::$instance == null)
self::$instance = new ilObjOrgUnitTree();
}

+ Here is the caller graph for this function:

ilObjOrgUnitTree::flushCache ( )

Definition at line 365 of file class.ilObjOrgUnitTree.php.

{
$this->roles = null;
}
ilObjOrgUnitTree::getAllChildren (   $ref_id)

Definition at line 116 of file class.ilObjOrgUnitTree.php.

References $ref_id, and getChildren().

Referenced by getOrgUnitOfUser(), and loadStaffRecursive().

{
$open = array($ref_id);
$closed = array();
while(count($open)){
$ref = array_pop($open);
$closed[] = $ref;
foreach($this->getChildren($ref) as $child)
if(!in_array($child, $open) && ! in_array($child, $closed))
$open[] = $child;
}
return $closed;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilObjOrgUnitTree::getAllOrgunitsOnLevelX (   $level)

Definition at line 213 of file class.ilObjOrgUnitTree.php.

References getChildren(), and ilObjOrgUnit\getRootOrgRefId().

{
$levels = array(0 => array(ilObjOrgUnit::getRootOrgRefId()));
$current_level = 0;
while($current_level < $level){
$new_level = array();
foreach($levels[$current_level] as $orgu_ref)
$new_level = array_merge($this->getChildren($orgu_ref), $new_level);
$new_level = array_unique($new_level);
$levels[$current_level+1] = $new_level;
$current_level++;
}
return $levels[$level];
}

+ Here is the call graph for this function:

ilObjOrgUnitTree::getChildren (   $ref_id)
private
Parameters
$ref_id
Returns
int[]

Definition at line 197 of file class.ilObjOrgUnitTree.php.

References $ref_id, and loadChildren().

Referenced by getAllChildren(), and getAllOrgunitsOnLevelX().

{
return $this->tree_childs[$ref_id];
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilObjOrgUnitTree::getEmployeeRoles ( )
Returns
int[] returns an array of role_ids. orgu_ref => role_id

Definition at line 349 of file class.ilObjOrgUnitTree.php.

References loadRoles().

{
$this->loadRoles("employee");
return $this->roles["employee"];
}

+ Here is the call graph for this function:

ilObjOrgUnitTree::getEmployees (   $ref_id,
  $recursive = false 
)
Parameters
$ref_idint the reference id of the organisational unit.
$recursivebool if true you get the ids of the subsequent orgunits employees too
Returns
int[] array of user ids.

Definition at line 59 of file class.ilObjOrgUnitTree.php.

References $ref_id, loadStaff(), and loadStaffRecursive().

Referenced by getEmployeesUnderUser().

{
return array_unique(($recursive?$this->loadStaffRecursive("employee",$ref_id):$this->loadStaff("employee", $ref_id)));
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilObjOrgUnitTree::getEmployeesUnderUser (   $user_id,
  $recursive = true 
)
Parameters
$user_idint
$recursivebool if this is true subsequent orgunits of this users superior role get searched as well.
Returns
int[] returns an array of user_ids of the users which have an employee role in an orgunit of which this user's id has a superior role.

Definition at line 232 of file class.ilObjOrgUnitTree.php.

References $res, and getEmployees().

{
//querry for all orgu where user_id is superior.
$q = "SELECT orgu.obj_id, refr.ref_id FROM object_data orgu
INNER JOIN object_reference refr ON refr.obj_id = orgu.obj_id
INNER JOIN object_data roles ON roles.title LIKE CONCAT('il_orgu_superior_',refr.ref_id)
INNER JOIN rbac_ua rbac ON rbac.usr_id = ".$this->db->quote($user_id, "integer")." AND roles.obj_id = rbac.rol_id
WHERE orgu.type = 'orgu'";
$set = $this->db->query($q);
$orgu_ref_ids = array();
while($res = $this->db->fetchAssoc($set)){
$orgu_ref_ids[] = $res['ref_id'];
}
$employees = array();
foreach($orgu_ref_ids as $orgu_ref_id){
$employees = array_merge($employees, $this->getEmployees($orgu_ref_id, $recursive));
}
return $employees;
}

+ Here is the call graph for this function:

ilObjOrgUnitTree::getLevelXOfTreenode (   $orgu_ref,
  $level 
)

Specify eg.

level 1 and it will return on which orgunit on the first level after the root node the specified orgu_ref is a subunit of. eg: 0

  • - 1 2
    3 4 5
  • 6

(6, 1) = 1; (4, 1) = 2; (6, 2) = 3;

Parameters
$orgu_ref
$level
Exceptions
Exceptionin case there's a thread of an infinite loop or if you try to fetch the third level but there are only two (e.g. you want to fetch lvl 1 but give the root node as reference).
Returns
int|bool ref_id of the orgu or false if not found.

Definition at line 402 of file class.ilObjOrgUnitTree.php.

References getParent(), and ilObjOrgUnit\getRootOrgRefId().

Referenced by getLevelXOfUser().

{
$line = array($orgu_ref);
$current_ref = $orgu_ref;
while($current_ref != ilObjOrgUnit::getRootOrgRefId()){
$current_ref = $this->getParent($current_ref);
if($current_ref)
$line[] = $current_ref;
else
break;
if(count($line) > 100)
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");
}
$line = array_reverse($line);
if(count($line) > $level)
return $line[$level];
else
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));
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilObjOrgUnitTree::getLevelXOfUser (   $user_id,
  $level 
)

for additional info see the other getLevelX method.

Parameters
$user_id
$level
Returns
int[]

Definition at line 284 of file class.ilObjOrgUnitTree.php.

References $res, and getLevelXOfTreenode().

{
$q = "SELECT orgu.obj_id, refr.ref_id FROM object_data orgu
INNER JOIN object_reference refr ON refr.obj_id = orgu.obj_id
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)
INNER JOIN rbac_ua rbac ON rbac.usr_id = " . $this->db->quote($user_id, "integer") . " AND roles.obj_id = rbac.rol_id
WHERE orgu.type = 'orgu' AND refr.deleted IS NULL";
$set = $this->db->query($q);
$orgu_ref_ids = array();
while ($res = $this->db->fetchAssoc($set)) {
$orgu_ref_ids[] = $res['ref_id'];
}
$orgus_on_level_x = array();
foreach($orgu_ref_ids as $orgu_ref_id){
try{
$orgus_on_level_x[] = $this->getLevelXOfTreenode($orgu_ref_id, $level);
}catch(Exception $e){
// this means the user is assigned to a orgu above the given level. just dont add it to the list.
}
}
return array_unique($orgus_on_level_x);
}

+ Here is the call graph for this function:

ilObjOrgUnitTree::getOrgUnitOfUser (   $user_id,
  $ref_id = 0 
)

getOrgUnitOfUser

Parameters
$user_id
int$ref_idif given, only OrgUnits under this ID are returned (including $ref_id)
Returns
int[]

Definition at line 315 of file class.ilObjOrgUnitTree.php.

References $ref_id, $res, and getAllChildren().

{
$q = "SELECT orgu.obj_id, refr.ref_id FROM object_data orgu
INNER JOIN object_reference refr ON refr.obj_id = orgu.obj_id
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)
INNER JOIN rbac_ua rbac ON rbac.usr_id = ".$this->db->quote($user_id, "integer")." AND roles.obj_id = rbac.rol_id
WHERE orgu.type = 'orgu' AND refr.deleted IS NULL";
$set = $this->db->query($q);
$orgu_ref_ids = array();
while($res = $this->db->fetchAssoc($set)){
$orgu_ref_ids[] = $res['ref_id'];
}
$orgu_ref_ids = array_unique($orgu_ref_ids);
if ($ref_id) {
$childernOrgIds = $this->getAllChildren($ref_id);
foreach ($orgu_ref_ids as $k => $refId) {
if (!in_array($refId, $childernOrgIds)) {
unset($orgu_ref_ids[$k]);
}
}
}
return $orgu_ref_ids;
}

+ Here is the call graph for this function:

ilObjOrgUnitTree::getOrgusWhereUserHasPermissionForOperation (   $operation)

If you want to have all orgunits where the current user has the write permission: use this with the parameter "write".

Parameters
$operationstring
Returns
int[] ids of the org units.

Definition at line 134 of file class.ilObjOrgUnitTree.php.

References $ilUser, and $res.

{
global $ilUser;
/*$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
INNER JOIN rbac_operations ON rbac_operations.operation = ".$this->db->quote($operation, "text")."
INNER JOIN rbac_ua ON rbac_ua.usr_id = ".$this->db->quote($ilUser->getId(), "integer")."
INNER JOIN rbac_pa ON rbac_pa.rol_id = rbac_ua.rol_id AND rbac_pa.ops_id LIKE CONCAT('%', rbac_operations.ops_id, '%')
INNER JOIN rbac_fa ON rbac_fa.rol_id = rbac_ua.rol_id
INNER JOIN tree ON tree.child = rbac_fa.parent
INNER JOIN object_reference ON object_reference.ref_id = tree.parent
WHERE object_data.obj_id = object_reference.obj_id AND object_data.type = 'orgu'";*/
$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
INNER JOIN rbac_operations ON rbac_operations.operation = ".$this->db->quote($operation, "text")."
INNER JOIN rbac_ua ON rbac_ua.usr_id = ".$this->db->quote($ilUser->getId(), "integer")."
INNER JOIN rbac_pa ON rbac_pa.rol_id = rbac_ua.rol_id AND rbac_pa.ops_id LIKE CONCAT('%', rbac_operations.ops_id, '%')
INNER JOIN object_reference ON object_reference.ref_id = rbac_pa.ref_id
WHERE object_data.obj_id = object_reference.obj_id AND object_data.type = 'orgu'";
$set = $this->db->query($q);
$orgus = array();
while($res = $this->db->fetchAssoc($set)){
//this is needed as the table rbac_operations is not in the first normal form, thus this needs some additional checkings.
$perm_check = unserialize($res['ops_id']);
if(!in_array($res["op_id"], $perm_check))
continue;
$orgus[] = $res["ref_id"];
}
return $orgus;
}
ilObjOrgUnitTree::getOrgusWhereUserHasPermissionForOperationId (   $operation_id)

If you want to have all orgunits where the current user has the write permission: use this with the parameter 3 (3 is the "write" permission as in rbac_operations).

Parameters
$operation_id
Returns
int[] ids of the org units.

Definition at line 170 of file class.ilObjOrgUnitTree.php.

References $ilUser, and $res.

{
global $ilUser;
$q = "SELECT object_data.obj_id, object_data.title, object_data.type, rbac_pa.ops_id FROM object_data
INNER JOIN rbac_ua ON rbac_ua.usr_id = ".$this->db->quote($ilUser->getId(), "integer")."
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").", '%')
INNER JOIN rbac_fa ON rbac_fa.rol_id = rbac_ua.rol_id
INNER JOIN tree ON tree.child = rbac_fa.parent
INNER JOIN object_reference ON object_reference.ref_id = tree.parent
WHERE object_data.obj_id = object_reference.obj_id AND object_data.type = 'orgu'";
$set = $this->db->query($q);
$orgus = array();
while($res = $this->db->fetchAssoc($set)){
//this is needed as the table rbac_operations is not in the first normal form, thus this needs some additional checkings.
$perm_check = unserialize($res['ops_id']);
if(!in_array($res["ops_id"], $perm_check))
continue;
$orgus[] = $res["obj_id"];
}
return $orgus;
}
ilObjOrgUnitTree::getParent (   $orgu_ref)

Definition at line 421 of file class.ilObjOrgUnitTree.php.

Referenced by getLevelXOfTreenode().

{
if(!$this->parent[$orgu_ref]){
$this->parent[$orgu_ref] = $this->tree->getParentId($orgu_ref);
}
return $this->parent[$orgu_ref];
}

+ Here is the caller graph for this function:

ilObjOrgUnitTree::getRefIdFromRoleTitle (   $role_title)
private

Definition at line 380 of file class.ilObjOrgUnitTree.php.

Referenced by loadRolesQuery().

{
$array = explode("_", $role_title);
return $array[count($array) - 1];
}

+ Here is the caller graph for this function:

ilObjOrgUnitTree::getSuperiorRoles ( )

Definition at line 354 of file class.ilObjOrgUnitTree.php.

References loadRoles().

{
$this->loadRoles("superior");
return $this->roles["superior"];
}

+ Here is the call graph for this function:

ilObjOrgUnitTree::getSuperiors (   $ref_id,
  $recursive = false 
)

Definition at line 63 of file class.ilObjOrgUnitTree.php.

References $ref_id, loadStaff(), and loadStaffRecursive().

Referenced by getSuperiorsOfUser().

{
return array_unique(($recursive?$this->loadStaffRecursive("superior",$ref_id):$this->loadStaff("superior", $ref_id)));
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilObjOrgUnitTree::getSuperiorsOfUser (   $user_id,
  $recursive = true 
)
Parameters
$user_idint
$recursivebool if this is true subsequent orgunits of this users superior role get searched as well.
Returns
int[] returns an array of user_ids of the users which have an employee role in an orgunit of which this user's id has a superior role.

Definition at line 256 of file class.ilObjOrgUnitTree.php.

References $res, and getSuperiors().

{
//querry for all orgu where user_id is superior.
$q = "SELECT orgu.obj_id, refr.ref_id FROM object_data orgu
INNER JOIN object_reference refr ON refr.obj_id = orgu.obj_id
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)
INNER JOIN rbac_ua rbac ON rbac.usr_id = ".$this->db->quote($user_id, "integer")." AND roles.obj_id = rbac.rol_id
WHERE orgu.type = 'orgu'";
$set = $this->db->query($q);
$orgu_ref_ids = array();
while($res = $this->db->fetchAssoc($set)){
$orgu_ref_ids[] = $res['ref_id'];
}
$superiors = array();
foreach($orgu_ref_ids as $orgu_ref_id){
$superiors = array_merge($superiors, $this->getSuperiors($orgu_ref_id, $recursive));
}
return $superiors;
}

+ Here is the call graph for this function:

ilObjOrgUnitTree::getTitles (   $org_refs)

Definition at line 338 of file class.ilObjOrgUnitTree.php.

References ilObject\_lookupObjId(), and ilObject\_lookupTitle().

{
$names = array();
foreach($org_refs as $org_unit){
$names[$org_unit] = ilObject::_lookupTitle(ilObject::_lookupObjId($org_unit));
}
return $names;
}

+ Here is the call graph for this function:

ilObjOrgUnitTree::loadArrayOfStaff (   $title,
  $ref_ids 
)
private
Parameters
$title"employee" or "superior"
$ref_idsint[] array of orgu object ref ids.
Returns
int[] user_ids

Definition at line 85 of file class.ilObjOrgUnitTree.php.

References $ref_id, $res, and loadRoles().

Referenced by loadStaff(), and loadStaffRecursive().

{
$this->loadRoles($title);
$all_refs = $ref_ids;
//take away ref_ids that are already loaded.
foreach($ref_ids as $id => $ref_id){
if(isset($this->staff[$title][$ref_id]))
unset($ref_ids[$id]);
else{
$this->staff[$title][$ref_id] = array();
$ref_ids[$id] = $this->roles[$title][$ref_id];
}
}
//if there are still refs that need to be loaded, then do so.
if(count($ref_ids)){
$q = "SELECT usr_id, rol_id FROM rbac_ua WHERE ".$this->db->in("rol_id", $ref_ids, false, "integer");
$set = $this->db->query($q);
while($res = $this->db->fetchAssoc($set)){
$orgu_ref = $this->role_to_orgu[$title][$res["rol_id"]];
$this->staff[$title][$orgu_ref][] = $res["usr_id"];
}
}
//collect * users.
$all_users = array();
foreach($all_refs as $ref)
$all_users = array_merge($all_users, $this->staff[$title][$ref]);
return $all_users;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilObjOrgUnitTree::loadChildren (   $ref_id)
private

Definition at line 202 of file class.ilObjOrgUnitTree.php.

References $ref_id.

Referenced by getChildren().

{
if(!$this->tree_childs[$ref_id]){
$children = array();
foreach($this->tree->getChilds($ref_id) as $child){
if($child["type"] == "orgu")
$children[] = $child["child"];
}
$this->tree_childs[$ref_id] = $children;
};
}

+ Here is the caller graph for this function:

ilObjOrgUnitTree::loadRoles (   $role)
private

Definition at line 359 of file class.ilObjOrgUnitTree.php.

References loadRolesQuery().

Referenced by getEmployeeRoles(), getSuperiorRoles(), and loadArrayOfStaff().

{
if($this->roles[$role] == null){
$this->loadRolesQuery($role);
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilObjOrgUnitTree::loadRolesQuery (   $role)
private

Definition at line 369 of file class.ilObjOrgUnitTree.php.

References $res, and getRefIdFromRoleTitle().

Referenced by loadRoles().

{
$this->roles[$role] = array();
$q = "SELECT obj_id, title FROM object_data WHERE type = 'role' AND title LIKE 'il_orgu_".$role."%'";
$set = $this->db->query($q);
while($res = $this->db->fetchAssoc($set)){
$orgu_ref = $this->getRefIdFromRoleTitle($res["title"]);
$this->roles[$role][$orgu_ref] = $res["obj_id"];
$this->role_to_orgu[$role][$res["obj_id"]] = $orgu_ref;
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilObjOrgUnitTree::loadStaff (   $title,
  $ref_id 
)
private
Parameters
$titlestring "employee" or "superior"
$ref_idint ref id of org unit.
Returns
int[] array of user_obj ids

Definition at line 72 of file class.ilObjOrgUnitTree.php.

References $ref_id, and loadArrayOfStaff().

Referenced by getEmployees(), and getSuperiors().

{
return $this->loadArrayOfStaff($title, array($ref_id));
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilObjOrgUnitTree::loadStaffRecursive (   $title,
  $ref_id 
)
private

Definition at line 76 of file class.ilObjOrgUnitTree.php.

References $ref_id, getAllChildren(), and loadArrayOfStaff().

Referenced by getEmployees(), and getSuperiors().

{
return $this->loadArrayOfStaff($title, $this->getAllChildren($ref_id));
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

ilObjOrgUnitTree::$ctrl
private

Definition at line 29 of file class.ilObjOrgUnitTree.php.

ilObjOrgUnitTree::$db
private

Definition at line 35 of file class.ilObjOrgUnitTree.php.

ilObjOrgUnitTree::$instance
staticprivate

Definition at line 14 of file class.ilObjOrgUnitTree.php.

Referenced by _getInstance().

ilObjOrgUnitTree::$parent
private

Definition at line 32 of file class.ilObjOrgUnitTree.php.

ilObjOrgUnitTree::$role_to_orgu
private

Definition at line 20 of file class.ilObjOrgUnitTree.php.

ilObjOrgUnitTree::$roles
private

Definition at line 17 of file class.ilObjOrgUnitTree.php.

ilObjOrgUnitTree::$staff
private

Definition at line 23 of file class.ilObjOrgUnitTree.php.

ilObjOrgUnitTree::$tree_childs
private

Definition at line 26 of file class.ilObjOrgUnitTree.php.


The documentation for this class was generated from the following file: