19 declare(strict_types=1);
34 protected int $roleId,
35 protected bool $localize =
true,
43 $db = $DIC->database();
48 $lng = $DIC->language();
52 if (null === $parserFactory) {
119 $query =
'SELECT rdat.title role_title, odat.title object_title, ' .
120 ' oref.ref_id object_ref ' .
121 'FROM object_data rdat ' .
122 'INNER JOIN role_data roledat ON roledat.role_id = rdat.obj_id ' .
123 'INNER JOIN rbac_fa fa ON fa.rol_id = rdat.obj_id AND fa.assign = ' . $this->db->quote(
'y',
ilDBConstants::T_TEXT) .
' ' .
124 'INNER JOIN tree rtree ON rtree.child = fa.parent ' .
125 'INNER JOIN object_reference oref ON oref.ref_id = rtree.child ' .
126 'INNER JOIN object_data odat ON odat.obj_id = oref.obj_id ' .
128 $res = $this->db->query($query);
129 if (($row = $this->db->fetchObject(
$res)) === null) {
133 $object_title = $row->object_title;
134 $object_ref = (
int) $row->object_ref;
135 $role_title = $row->role_title;
140 $domain = $object_title;
141 $local_part = $role_title;
144 $q =
'SELECT COUNT(DISTINCT dat.obj_id) AS count ' .
145 'FROM object_data dat ' .
146 'INNER JOIN object_reference ref ON ref.obj_id = dat.obj_id AND ref.deleted IS NULL ' .
147 'INNER JOIN tree ON tree.child = ref.ref_id AND tree.tree = ' . $this->db->quote(1,
ilDBConstants::T_INTEGER) .
' ' .
149 $res = $this->db->query(
$q);
150 $row = $this->db->fetchObject(
$res);
153 if ($row->count !== 1) {
161 if ($domain !== null && preg_match(
'/[\[\]\\]|[\x00-\x1f]|[\x28-\x29]|[;]/', (
string) $domain)) {
167 if ($domain !== null &&
168 (preg_match(
'/[()<>@,;:\\".\[\]]/', (
string) $domain) ||
169 preg_match(
'/[^\x21-\x8f]/', (
string) $domain))
171 $domain =
'[' . $domain .
']';
177 if ($domain !== null && str_starts_with($role_title,
'il_')) {
178 $unambiguous_role_title = $role_title;
180 $pos = strpos($role_title,
'_', 3) + 1;
181 $local_part = substr(
184 strrpos($role_title,
'_') - $pos
187 $unambiguous_role_title =
'il_role_' . $this->roleId;
194 if ($domain === null) {
196 $q =
'SELECT COUNT(DISTINCT rdat.role_id) AS count ' .
197 'FROM object_data dat ' .
198 'INNER JOIN role_data rdat ON rdat.role_id = dat.obj_id ' .
199 'INNER JOIN rbac_fa fa ON fa.rol_id = rdat.role_id ' .
200 'INNER JOIN tree t ON t.child = fa.parent ' .
201 'INNER JOIN object_reference oref ON oref.ref_id = t.child ' .
204 $q =
'SELECT COUNT(rd.obj_id) AS count ' .
205 'FROM object_data rd ' .
206 'INNER JOIN rbac_fa fa ON fa.rol_id = rd.obj_id AND fa.assign = ' . $this->db->quote(
'y',
ilDBConstants::T_TEXT) .
' ' .
207 'INNER JOIN tree t ON t.child = fa.parent AND t.child = ' . $this->db->quote($object_ref,
ilDBConstants::T_INTEGER) .
' ' .
208 'WHERE rd.title LIKE ' . $this->db->quote(
209 '%' . preg_replace(
'/([_%])/',
'\\\\$1', $local_part) .
'%',
214 $res = $this->db->query(
$q);
215 $row = $this->db->fetchObject(
$res);
219 if ($row->count !== 1) {
220 $local_part = $unambiguous_role_title;
227 if (preg_match(
'/[\\"\x00-\x1f]/', (
string) $local_part)) {
228 $local_part = $unambiguous_role_title;
229 } elseif (!preg_match(
'/^[\\x00-\\x7E]+$/i', (
string) $local_part)) {
231 $local_part = $unambiguous_role_title;
236 $local_part =
'#' . $local_part;
239 if (preg_match(
'/[()<>@,;:.\[\]\x20]/', $local_part)) {
240 $local_part =
'"' . $local_part .
'"';
243 $mailbox = ($domain === null) ?
245 $local_part .
'@' . $domain;
247 if ($this->localize) {
248 if (str_starts_with($role_title,
'il_')) {
249 $phrase = $this->
lng->txt(substr($role_title, 0, strrpos($role_title,
'_')));
251 $phrase = $role_title;
258 $phrase = preg_replace(
'/\s\s+/',
' ', $phrase);
259 $phrase = preg_replace(
'/[()<>@,;:\\".\[\]]/',
'', $phrase);
261 $mailbox = $phrase .
' <' . $mailbox .
'>';
266 $parser = $this->parserFactory->getParser($mailbox);
271 $res = $this->db->query(
274 INNER JOIN role_data rd ON rd.role_id = od.obj_id 278 FROM object_data maybe_same_role_od 279 INNER JOIN role_data maybe_same_role_rd ON maybe_same_role_rd.role_id = maybe_same_role_od.obj_id 280 WHERE maybe_same_role_od.title = od.title 281 AND maybe_same_role_od.obj_id != od.obj_id 284 if (($row = $this->db->fetchObject(
$res)) !== null) {
285 return '#' . $row->title;
288 return '#il_role_' . $this->roleId;
value()
Returns the mailbox address of a role.
Class ilRoleMailboxAddress.
Class ilMailRfc822AddressParserFactory.
__construct(protected int $roleId, protected bool $localize=true, ilMailRfc822AddressParserFactory $parserFactory=null, ilDBInterface $db=null, ilLanguage $lng=null)
ilMailRfc822AddressParserFactory $parserFactory