ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilRoleAutoComplete.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
26{
30 public static function getList(string $a_str): string
31 {
32 global $DIC;
33
34 $ilDB = $DIC->database();
35 $ilDB->setLimit(20, 0);
36 $query = "SELECT o1.title role,o2.title container FROM object_data o1 " .
37 "JOIN rbac_fa fa ON o1.obj_id = rol_id " .
38// "JOIN tree t1 ON fa.parent = t1.child " .
39// "JOIN object_reference obr ON ref_id = t1.parent " .
40 "JOIN object_reference obr ON ref_id = fa.parent AND obr.deleted IS NULL " .
41 "JOIN object_data o2 ON obr.obj_id = o2.obj_id " .
42 "INNER JOIN tree t ON t.child = obr.ref_id AND t.tree = 1 " .
43 "WHERE o1.type = 'role' " .
44 "AND assign = 'y' " .
45 "AND (" . $ilDB->like('o1.title', 'text', '%' . $a_str . '%') . "OR " .
46 $ilDB->like('o2.title', 'text', '%' . $a_str . '%') . " )" .
47 "AND fa.parent != 8 " .
48 "ORDER BY role,container";
49
50 $res = $ilDB->query($query);
51 $counter = 0;
52 $result = [];
53 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
54 $result[$counter] = new stdClass();
55 $result[$counter]->value = $row->role;
56 $result[$counter]->label = $row->role . " (" . $row->container . ")";
57 ++$counter;
58 }
59
60 if ($counter == 0) {
61 return self::getListByObject($a_str);
62 }
63
64 return json_encode($result, JSON_THROW_ON_ERROR);
65 }
66
70 public static function getListByObject(string $a_str): string
71 {
72 global $DIC;
73
74 $rbacreview = $DIC->rbac()->review();
75 $ilDB = $DIC->database();
76
77 $result = [];
78
79 if (strpos($a_str, '@') !== 0) {
80 return json_encode($result, JSON_THROW_ON_ERROR);
81 }
82
83 $a_str = substr($a_str, 1);
84
85 $ilDB->setLimit(100, 0);
86 $query = "SELECT ref_id, title FROM object_data ode " .
87 "JOIN object_reference ore ON ode.obj_id = ore.obj_id " .
88 "WHERE " . $ilDB->like('title', 'text', $a_str . '%') . ' ' .
89 'ORDER BY title';
90 $res = $ilDB->query($query);
91 $counter = 0;
92 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
93 foreach ($rbacreview->getRolesOfRoleFolder($row->ref_id, false) as $rol_id) {
94 $role = ilObject::_lookupTitle($rol_id);
95
96 $result[$counter] = new stdClass();
97 $result[$counter]->value = $role;
98 $result[$counter]->label = $role . " (" . $row->title . ")";
99 ++$counter;
100 }
101 }
102 return json_encode($result, JSON_THROW_ON_ERROR);
103 }
104}
static _lookupTitle(int $obj_id)
Auto completion class for user lists.
static getListByObject(string $a_str)
Get list of roles assigned to an object.
static getList(string $a_str)
Get completion list.
$res
Definition: ltiservices.php:69
global $DIC
Definition: shib_login.php:26
$counter