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