ILIAS  release_8 Revision v8.24
class.ilRoleMailboxSearch.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
28{
30 protected ilDBInterface $db;
31
32 public function __construct(
34 ilDBInterface $db = null
35 ) {
36 global $DIC;
37
38 $this->parserFactory = $parserFactory;
39
40 if (null === $db) {
41 $db = $DIC->database();
42 }
43 $this->db = $db;
44 }
45
88 public function searchRoleIdsByAddressString(string $a_address_list): array
89 {
90 $parser = $this->parserFactory->getParser($a_address_list);
91 $parsedList = $parser->parse();
92
93 $role_ids = [];
94 foreach ($parsedList as $address) {
95 $local_part = $address->getMailbox();
96 if (strpos($local_part, '#') !== 0 && !($local_part[0] === '"' && $local_part[1] === "#")) {
97 // A local-part which doesn't start with a '#' doesn't denote a role.
98 // Therefore we can skip it.
99 continue;
100 }
101
102 $local_part = substr($local_part, 1);
103
104 /* If role contains spaces, eg. 'foo role', double quotes are added which have to be removed here.*/
105 if ($local_part[0] === '#' && $local_part[strlen($local_part) - 1] === '"') {
106 $local_part = substr($local_part, 1);
107 $local_part = substr($local_part, 0, -1);
108 }
109
110 if (strpos($local_part, 'il_role_') === 0) {
111 $role_id = substr($local_part, 8);
112 $query = "SELECT t.tree " .
113 "FROM rbac_fa fa " .
114 "JOIN tree t ON t.child = fa.parent " .
115 "WHERE fa.rol_id = " . $this->db->quote($role_id, 'integer') . " " .
116 "AND fa.assign = 'y' " .
117 "AND t.tree = 1";
118 $res = $this->db->query($query);
119 if ($this->db->numRows($res) > 0) {
120 $role_ids[] = (int) $role_id;
121 }
122 continue;
123 }
124
125 $domain = $address->getHost();
126 if (strpos($domain, '[') === 0 && strrpos($domain, ']')) {
127 $domain = substr($domain, 1, -1);
128 }
129 if ($local_part === '') {
130 $local_part = $domain;
131 $address->setHost(ilMail::ILIAS_HOST);
132 $domain = ilMail::ILIAS_HOST;
133 }
134
135 if (strtolower($address->getHost()) === ilMail::ILIAS_HOST) {
136 // Search for roles = local-part in the whole repository
137 $query = "SELECT dat.obj_id " .
138 "FROM object_data dat " .
139 "JOIN rbac_fa fa ON fa.rol_id = dat.obj_id " .
140 "JOIN tree t ON t.child = fa.parent " .
141 "WHERE dat.title =" . $this->db->quote($local_part, 'text') . " " .
142 "AND dat.type = 'role' " .
143 "AND fa.assign = 'y' " .
144 "AND t.tree = 1";
145 } else {
146 // Search for roles like local-part in objects = host
147 $query = "SELECT rdat.obj_id " .
148 "FROM object_data odat " .
149 "JOIN object_reference oref ON oref.obj_id = odat.obj_id " .
150 "JOIN tree otree ON otree.child = oref.ref_id " .
151 "JOIN rbac_fa rfa ON rfa.parent = otree.child " .
152 "JOIN object_data rdat ON rdat.obj_id = rfa.rol_id " .
153 "WHERE odat.title = " . $this->db->quote($domain, 'text') . " " .
154 "AND otree.tree = 1 " .
155 "AND rfa.assign = 'y' " .
156 "AND rdat.title LIKE " .
157 $this->db->quote(
158 '%' . preg_replace('/([_%])/', '\\\\$1', $local_part) . '%',
159 'text'
160 );
161 }
162 $res = $this->db->query($query);
163
164 $count = 0;
165 while ($row = $this->db->fetchAssoc($res)) {
166 $role_ids[] = (int) $row['obj_id'];
167
168 $count++;
169 }
170
171 // Nothing found?
172 // In this case, we search for roles = host.
173 if ($count === 0 && strtolower($address->getHost()) === ilMail::ILIAS_HOST) {
174 $q = "SELECT dat.obj_id " .
175 "FROM object_data dat " .
176 "JOIN object_reference ref ON ref.obj_id = dat.obj_id " .
177 "JOIN tree t ON t.child = ref.ref_id " .
178 "WHERE dat.title = " . $this->db->quote($domain, 'text') . " " .
179 "AND dat.type = 'role' " .
180 "AND t.tree = 1 ";
181 $res = $this->db->query($q);
182
183 while ($row = $this->db->fetchAssoc($res)) {
184 $role_ids[] = (int) $row['obj_id'];
185 }
186 }
187 }
188
189 return $role_ids;
190 }
191}
const ILIAS_HOST
Class ilRoleMailboxSearch.
__construct(ilMailRfc822AddressParserFactory $parserFactory, ilDBInterface $db=null)
searchRoleIdsByAddressString(string $a_address_list)
Finds all role ids that match the specified user friendly role mailbox address list.
ilMailRfc822AddressParserFactory $parserFactory
global $DIC
Definition: feed.php:28
Interface ilDBInterface.
$res
Definition: ltiservices.php:69
$query