49         $this->db = $DIC->database();
    50         $this->tree = $DIC->repositoryTree();
    51         $this->roles = array();
    52         $this->staff = array();
    53         $this->ilUser = $DIC->user();
    58         if (static::$instance === null) {
    59             static::$instance = 
new self();
    62         return static::$instance;
    67         if (!isset($this->positionRepo)) {
    69             $this->positionRepo = 
$dic[
"repo.Positions"];
    77         if (!isset($this->assignmentRepo)) {
    79             $this->assignmentRepo = 
$dic[
"repo.UserAssignments"];
    99         return $this->
getAssignmentRepo()->getUsersByOrgUnitsAndPosition($orgu_ids, $position_id);
   112         if ($recursive === 
false) {
   136         if ($recursive === 
false) {
   157         $all_refs = $ref_ids;
   160             if (isset($this->staff[$title][
$ref_id])) {
   161                 unset($ref_ids[
$id]);
   163                 $this->staff[$title][
$ref_id] = array();
   164                 $ref_ids[
$id] = $this->roles[$title][
$ref_id];
   169         if (count($ref_ids)) {
   170             $q = 
"SELECT usr_id, rol_id FROM rbac_ua WHERE " . $this->db->in(
"rol_id", $ref_ids, 
false, 
"integer");
   171             $set = $this->db->query(
$q);
   172             while (
$res = $this->db->fetchAssoc($set)) {
   173                 $orgu_ref = $this->role_to_orgu[$title][
$res[
"rol_id"]];
   174                 $this->staff[$title][$orgu_ref][] = $res[
"usr_id"];
   180         foreach ($all_refs as $ref) {
   181             $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, 
true) === 
false && in_array($child, $closed, 
true) === 
false) {
   219         $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   220                 INNER JOIN rbac_operations ON rbac_operations.operation = " . $this->db->quote($operation, 
"text") . 
"   221                 INNER JOIN rbac_ua ON rbac_ua.usr_id = " . $this->db->quote($this->ilUser->getId(), 
"integer") . 
"   222                 INNER JOIN rbac_pa ON rbac_pa.rol_id = rbac_ua.rol_id AND rbac_pa.ops_id LIKE CONCAT('%', rbac_operations.ops_id, '%')   223                 INNER JOIN object_reference ON object_reference.ref_id = rbac_pa.ref_id   224                 WHERE object_data.obj_id = object_reference.obj_id AND object_data.type = 'orgu'";
   226         $set = $this->db->query(
$q);
   228         while (
$res = $this->db->fetchAssoc($set)) {
   230             $perm_check = unserialize(
$res[
'ops_id'], [
'allowed_classes' => 
true]);
   231             if (in_array(
$res[
"op_id"], $perm_check, 
true) === 
false) {
   235             $orgus[] = 
$res[
"ref_id"];
   248         $q = 
"SELECT object_data.obj_id, object_data.title, object_data.type, rbac_pa.ops_id FROM object_data   249                 INNER JOIN rbac_ua ON rbac_ua.usr_id = " . $this->db->quote($this->ilUser->getId(), 
"integer") . 
"   250                 INNER JOIN rbac_pa ON rbac_pa.rol_id = rbac_ua.rol_id AND rbac_pa.ops_id LIKE CONCAT('%', " . $this->db->quote(
   254                 INNER JOIN rbac_fa ON rbac_fa.rol_id = rbac_ua.rol_id   255                 INNER JOIN tree ON tree.child = rbac_fa.parent   256                 INNER JOIN object_reference ON object_reference.ref_id = tree.parent   257                 WHERE object_data.obj_id = object_reference.obj_id AND object_data.type = 'orgu'";
   259         $set = $this->db->query(
$q);
   261         while (
$res = $this->db->fetchAssoc($set)) {
   263             $perm_check = unserialize(
$res[
'ops_id'], [
'allowed_classes' => 
true]);
   264             if (in_array(
$res[
"ops_id"], $perm_check, 
true) === 
false) {
   268             $orgus[] = 
$res[
"obj_id"];
   277         return $this->tree_childs[
$ref_id];
   282         if (!array_key_exists($ref_id, $this->tree_childs)) {
   284             foreach ($this->tree->getChilds($ref_id) as $child) {
   285                 if ($child[
"type"] == 
"orgu") {
   286                     $children[] = $child[
"child"];
   289             $this->tree_childs[
$ref_id] = $children;
   297         while ($current_level < $level) {
   298             $new_level = array();
   299             foreach ($levels[$current_level] as $orgu_ref) {
   300                 $new_level = array_merge($this->
getChildren($orgu_ref), $new_level);
   302             $new_level = array_unique($new_level);
   303             $levels[$current_level + 1] = $new_level;
   307         return $levels[$level];
   326             ->getOrgUnitsByUserAndPosition($user_id, $superior_position, $recursive);
   343         $q = 
"SELECT orgu.obj_id, refr.ref_id FROM object_data orgu   344                 INNER JOIN object_reference refr ON refr.obj_id = orgu.obj_id   345                                 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)   346                                 INNER JOIN rbac_ua rbac ON rbac.usr_id = " . $this->db->quote($user_id, 
"integer") . 
" AND roles.obj_id = rbac.rol_id   347                                 WHERE orgu.type = 'orgu'";
   348         $set = $this->db->query(
$q);
   349         $orgu_ref_ids = array();
   350         while (
$res = $this->db->fetchAssoc($set)) {
   351             $orgu_ref_ids[] = 
$res[
'ref_id'];
   353         $superiors = array();
   354         foreach ($orgu_ref_ids as $orgu_ref_id) {
   355             $superiors = array_merge($superiors, $this->
getSuperiors($orgu_ref_id, $recursive));
   368         $q = 
"SELECT object_reference.ref_id FROM rbac_ua   369                                 JOIN rbac_fa ON rbac_fa.rol_id = rbac_ua.rol_id   370                                 JOIN object_reference ON rbac_fa.parent = object_reference.ref_id   371                                 JOIN object_data ON object_data.obj_id = object_reference.obj_id   372                         WHERE rbac_ua.usr_id = " . $this->db->quote($user_id, 
'integer') . 
" AND object_data.type = 'orgu';";
   374         $set = $this->db->query(
$q);
   375         $orgu_ref_ids = array();
   376         while (
$res = $this->db->fetchAssoc($set)) {
   377             $orgu_ref_ids[] = 
$res[
'ref_id'];
   379         $orgus_on_level_x = array();
   380         foreach ($orgu_ref_ids as $orgu_ref_id) {
   388         return array_unique($orgus_on_level_x);
   413         if (self::$temporary_table_name == $temporary_table_name) {
   416         if (self::$temporary_table_name === null) {
   419         } elseif ($temporary_table_name != self::$temporary_table_name) {
   420             throw new ilException(
'there is already a temporary table for org-unit assignement: ' . self::$temporary_table_name);
   423         $q = 
"CREATE TEMPORARY TABLE IF NOT EXISTS " . $temporary_table_name . 
" AS (   424                                 SELECT DISTINCT object_reference.ref_id AS ref_id, il_orgu_ua.user_id AS user_id, orgu_path_storage.path AS path   426                     JOIN object_reference ON object_reference.ref_id = il_orgu_ua.orgu_id   427                                         JOIN object_data ON object_data.obj_id = object_reference.obj_id   428                                         JOIN orgu_path_storage ON orgu_path_storage.ref_id = object_reference.ref_id   429                                 WHERE object_data.type = 'orgu' AND object_reference.deleted IS NULL   431         $this->db->manipulate(
$q);
   438         if (self::$temporary_table_name === null
   439             || $temporary_table_name !== self::$temporary_table_name
   444         $this->db->manipulate(
$q);
   446         self::$temporary_table_name = null;
   454         foreach ($org_refs as $org_unit) {
   467         return $this->roles[
"employee"];
   477         return $this->roles[
"superior"];
   482         if ($this->roles[$role] == null) {
   494         $this->roles[$role] = array();
   495         $q = 
"SELECT obj_id, title FROM object_data WHERE type = 'role' AND title LIKE 'il_orgu_" . $role . 
"%'";
   496         $set = $this->db->query(
$q);
   497         while (
$res = $this->db->fetchAssoc($set)) {
   499             $this->roles[$role][$orgu_ref] = 
$res[
"obj_id"];
   500             $this->role_to_orgu[$role][
$res[
"obj_id"]] = $orgu_ref;
   506         $array = explode(
"_", $role_title);
   508         return $array[count($array) - 1];
   529         $line = array($orgu_ref);
   530         $current_ref = $orgu_ref;
   532             $current_ref = $this->
getParent($current_ref);
   534                 $line[] = $current_ref;
   538             if (count($line) > 100) {
   539                 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");
   542         $line = array_reverse($line);
   543         if (count($line) > $level) {
   544             return $line[$level];
   546             throw new Exception(
"you want to fetch level " . $level . 
" but the line to the length of the line is only " . count($line)
   547                 . 
". The line of the given org unit is: " . print_r($line, 
true));
   553         if (array_key_exists($orgu_ref, $this->parent) === 
false) {
   554             $this->parent[$orgu_ref] = $this->tree->getParentId($orgu_ref);
   557         return $this->parent[$orgu_ref];
 getSuperiorsOfUser(int $user_id, bool $recursive=true)
 
buildTempTableWithUsrAssignements(string $temporary_table_name='orgu_usr_assignements')
Creates a temporary table with all orgu/user assignements. 
 
const CORE_POSITION_EMPLOYEE
 
static ilObjOrgUnitTree $instance
 
static string $temporary_table_name_getOrgUnitOfUser
 
loadArrayOfStaff(string $title, array $ref_ids)
 
ilOrgUnitUserAssignmentDBRepository $assignmentRepo
 
getEmployees(int $ref_id, bool $recursive=false)
 
getLevelXOfTreenode(int $orgu_ref, int $level)
Specify eg. 
 
getAllOrgunitsOnLevelX(int $level)
 
ilOrgUnitPositionDBRepository $positionRepo
 
static _lookupObjId(int $ref_id)
 
dropTempTable(string $temporary_table_name)
 
getOrgUnitOfUser(int $user_id)
 
getLevelXOfUser(int $user_id, int $level)
for additional info see the other getLevelX method. 
 
static _lookupTitle(int $obj_id)
 
getEmployeesUnderUser(int $user_id, bool $recursive=true)
 
getRefIdFromRoleTitle(string $role_title)
 
getAssignements(int $ref_id, ilOrgUnitPosition $ilOrgUnitPosition)
 
getAllChildren(int $ref_id)
 
getSuperiors(int $ref_id, bool $recursive=false)
 
loadChildren(int $ref_id)
 
getOrgusWhereUserHasPermissionForOperationId(string $operation_id)
If you want to have all orgunits where the current user has the write permission: use this with the p...
 
getTitles(array $org_refs)
 
getAssignedUsers(array $orgu_ids, int $position_id)
 
loadRolesQuery(string $role)
 
static string $temporary_table_name
 
const CORE_POSITION_SUPERIOR
 
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins 
 
getOrgusWhereUserHasPermissionForOperation($operation)
If you want to have all orgunits where the current user has the write permission: use this with the p...