ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilRoleMailboxSearch Class Reference
+ Collaboration diagram for ilRoleMailboxSearch:

Public Member Functions

 __construct (protected ilMailRfc822AddressParserFactory $parser_factory, ?ilDBInterface $db=null)
 
 searchRoleIdsByAddressString (string $a_address_list)
 Finds all role ids that match the specified user friendly role mailbox address list. More...
 

Protected Attributes

ilDBInterface $db
 

Detailed Description

Definition at line 21 of file class.ilRoleMailboxSearch.php.

Constructor & Destructor Documentation

◆ __construct()

ilRoleMailboxSearch::__construct ( protected ilMailRfc822AddressParserFactory  $parser_factory,
?ilDBInterface  $db = null 
)

Definition at line 25 of file class.ilRoleMailboxSearch.php.

28 {
29 global $DIC;
30
31 $this->db = $db ?? $DIC->database();
32 }
global $DIC
Definition: shib_login.php:26

References $db, and $DIC.

Member Function Documentation

◆ searchRoleIdsByAddressString()

ilRoleMailboxSearch::searchRoleIdsByAddressString ( string  $a_address_list)

Finds all role ids that match the specified user friendly role mailbox address list.

The role mailbox name address list is an e-mail address list according to IETF RFC 822:

address list = role mailbox, {"," role mailbox } ; role mailbox = "#", local part, ["@" domain] ;

Examples: The following role mailbox names are all resolved to the role il_crs_member_123:

#Course.A #member@Course.A #il_crs_member_123@Course.A #il_crs_member_123 #il_crs_member_123@ilias

Examples: The following role mailbox names are all resolved to the role il_crs_member_345:

#member@[English Course] #il_crs_member_345@[English Course] #il_crs_member_345 #il_crs_member_345@ilias

If only the local part is specified, or if domain is equal to "ilias", ILIAS compares the title of role objects with local part. Only roles that are not in a trash folder are considered for the comparison.

If a domain is specified, and if the domain is not equal to "ilias", ILIAS compares the title of objects with the domain. Only objects that are not in a trash folder are considered for the comparison. Then ILIAS searches for local roles which contain the local part in their title. This allows for abbreviated role names, e.g. instead of having to specify #il_grp_member_345@MyGroup, it is sufficient to specify #member@MyGroup.

The address list may contain addresses thate are not role mailboxes. These addresses are ignored.

If a role mailbox address is ambiguous, this function returns the ID's of all role objects that are possible recipients for the role mailbox address.

If Pear Mail is not installed, then the mailbox address

Returns
list<int> Array with role ids that were found

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

76 : array
77 {
78 $parser = $this->parser_factory->getParser($a_address_list);
79 $parsed_list = $parser->parse();
80
81 $role_ids = [];
82 foreach ($parsed_list as $address) {
83 $local_part = $address->getMailbox();
84 if (!str_starts_with($local_part, '#') && !($local_part[0] === '"' && $local_part[1] === '#')) {
85 // A local-part which doesn't start with a '#' doesn't denote a role.
86 // Therefore we can skip it.
87 continue;
88 }
89
90 $local_part = substr($local_part, 1);
91
92 /* If role contains spaces, eg. 'foo role', double quotes are added which have to be removed here.*/
93 if ($local_part[0] === '#' && $local_part[strlen($local_part) - 1] === '"') {
94 $local_part = substr($local_part, 1);
95 $local_part = substr($local_part, 0, -1);
96 }
97
98 if (str_starts_with($local_part, 'il_role_')) {
99 $role_id = substr($local_part, 8);
100 $query = 'SELECT t.tree ' .
101 'FROM rbac_fa fa ' .
102 'JOIN tree t ON t.child = fa.parent ' .
103 'WHERE fa.rol_id = ' . $this->db->quote($role_id, 'integer') . ' ' .
104 "AND fa.assign = 'y' " .
105 'AND t.tree = 1';
106 $res = $this->db->query($query);
107 if ($this->db->numRows($res) > 0) {
108 $role_ids[] = (int) $role_id;
109 }
110 continue;
111 }
112
113 $domain = $address->getHost();
114 if (str_starts_with($domain, '[') && strrpos($domain, ']')) {
115 $domain = substr($domain, 1, -1);
116 }
117 if ($local_part === '') {
118 $local_part = $domain;
119 $address->setHost(ilMail::ILIAS_HOST);
120 $domain = ilMail::ILIAS_HOST;
121 }
122
123 if (strtolower($address->getHost()) === ilMail::ILIAS_HOST) {
124 // Search for roles = local-part in the whole repository
125 $query = 'SELECT dat.obj_id ' .
126 'FROM object_data dat ' .
127 'JOIN rbac_fa fa ON fa.rol_id = dat.obj_id ' .
128 'JOIN tree t ON t.child = fa.parent ' .
129 'WHERE dat.title =' . $this->db->quote($local_part, 'text') . ' ' .
130 "AND dat.type = 'role' " .
131 "AND fa.assign = 'y' " .
132 'AND t.tree = 1';
133 } else {
134 // Search for roles like local-part in objects = host
135 $query = 'SELECT rdat.obj_id ' .
136 'FROM object_data odat ' .
137 'JOIN object_reference oref ON oref.obj_id = odat.obj_id ' .
138 'JOIN tree otree ON otree.child = oref.ref_id ' .
139 'JOIN rbac_fa rfa ON rfa.parent = otree.child ' .
140 'JOIN object_data rdat ON rdat.obj_id = rfa.rol_id ' .
141 'WHERE odat.title = ' . $this->db->quote($domain, 'text') . ' ' .
142 'AND otree.tree = 1 ' .
143 "AND rfa.assign = 'y' " .
144 'AND rdat.title LIKE ' .
145 $this->db->quote(
146 '%' . preg_replace('/([_%])/', '\\\\$1', $local_part) . '%',
147 'text'
148 );
149 }
150 $res = $this->db->query($query);
151
152 $count = 0;
153 while ($row = $this->db->fetchAssoc($res)) {
154 $role_ids[] = (int) $row['obj_id'];
155
156 $count++;
157 }
158
159 // Nothing found?
160 // In this case, we search for roles = host.
161 if ($count === 0 && strtolower($address->getHost()) === ilMail::ILIAS_HOST) {
162 $q = 'SELECT dat.obj_id ' .
163 'FROM object_data dat ' .
164 'JOIN object_reference ref ON ref.obj_id = dat.obj_id ' .
165 'JOIN tree t ON t.child = ref.ref_id ' .
166 'WHERE dat.title = ' . $this->db->quote($domain, 'text') . ' ' .
167 "AND dat.type = 'role' " .
168 'AND t.tree = 1 ';
169 $res = $this->db->query($q);
170
171 while ($row = $this->db->fetchAssoc($res)) {
172 $role_ids[] = (int) $row['obj_id'];
173 }
174 }
175 }
176
177 return $role_ids;
178 }
const string ILIAS_HOST
$res
Definition: ltiservices.php:69
$q
Definition: shib_logout.php:23

References $q, $res, ilMail\ILIAS_HOST, and ILIAS\Repository\int().

+ Here is the call graph for this function:

Field Documentation

◆ $db

ilDBInterface ilRoleMailboxSearch::$db
protected

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

Referenced by __construct().


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