ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilRoleMailboxSearch.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2018 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
13 protected $parserFactory;
14
16 protected $db;
17
23 public function __construct(
25 \ilDBInterface $db = null
26 ) {
27 global $DIC;
28
29 $this->parserFactory = $parserFactory;
30
31 if (null === $db) {
32 $db = $DIC->database();
33 }
34 $this->db = $db;
35 }
36
80 public function searchRoleIdsByAddressString(string $a_address_list) : array
81 {
82 $parser = $this->parserFactory->getParser($a_address_list);
83 $parsedList = $parser->parse();
84
85 $role_ids = array();
86 foreach ($parsedList as $address) {
87 $local_part = $address->getMailbox();
88 if (strpos($local_part, '#') !== 0 && !($local_part[0] == '"' && $local_part[1] == "#")) {
89 // A local-part which doesn't start with a '#' doesn't denote a role.
90 // Therefore we can skip it.
91 continue;
92 }
93
94 $local_part = substr($local_part, 1);
95
96 /* If role contains spaces, eg. 'foo role', double quotes are added which have to be removed here.*/
97 if ($local_part[0] == '#' && $local_part[strlen($local_part) - 1] == '"') {
98 $local_part = substr($local_part, 1);
99 $local_part = substr($local_part, 0, strlen($local_part) - 1);
100 }
101
102 if (substr($local_part, 0, 8) == 'il_role_') {
103 $role_id = substr($local_part, 8);
104 $query = "SELECT t.tree " .
105 "FROM rbac_fa fa " .
106 "JOIN tree t ON t.child = fa.parent " .
107 "WHERE fa.rol_id = " . $this->db->quote($role_id, 'integer') . " " .
108 "AND fa.assign = 'y' " .
109 "AND t.tree = 1";
110 $res = $this->db->query($query);
111 if ($this->db->numRows($res) > 0) {
112 $role_ids[] = $role_id;
113 }
114 continue;
115 }
116
117 $domain = $address->getHost();
118 if (strpos($domain, '[') == 0 && strrpos($domain, ']')) {
119 $domain = substr($domain, 1, strlen($domain) - 2);
120 }
121 if (strlen($local_part) == 0) {
122 $local_part = $domain;
123 $address->setHost(\ilMail::ILIAS_HOST);
125 }
126
127 if (strtolower($address->getHost()) == \ilMail::ILIAS_HOST) {
128 // Search for roles = local-part in the whole repository
129 $query = "SELECT dat.obj_id " .
130 "FROM object_data dat " .
131 "JOIN rbac_fa fa ON fa.rol_id = dat.obj_id " .
132 "JOIN tree t ON t.child = fa.parent " .
133 "WHERE dat.title =" . $this->db->quote($local_part, 'text') . " " .
134 "AND dat.type = 'role' " .
135 "AND fa.assign = 'y' " .
136 "AND t.tree = 1";
137 } else {
138 // Search for roles like local-part in objects = host
139 $query = "SELECT rdat.obj_id " .
140 "FROM object_data odat " .
141 "JOIN object_reference oref ON oref.obj_id = odat.obj_id " .
142 "JOIN tree otree ON otree.child = oref.ref_id " .
143 "JOIN rbac_fa rfa ON rfa.parent = otree.child " .
144 "JOIN object_data rdat ON rdat.obj_id = rfa.rol_id " .
145 "WHERE odat.title = " . $this->db->quote($domain, 'text') . " " .
146 "AND otree.tree = 1 " .
147 "AND rfa.assign = 'y' " .
148 "AND rdat.title LIKE " .
149 $this->db->quote('%' . preg_replace('/([_%])/', '\\\\$1', $local_part) . '%', 'text');
150 }
151 $res = $this->db->query($query);
152
153 $count = 0;
154 while ($row = $this->db->fetchAssoc($res)) {
155 $role_ids[] = $row['obj_id'];
156
157 $count++;
158 }
159
160 // Nothing found?
161 // In this case, we search for roles = host.
162 if ($count == 0 && strtolower($address->getHost()) == \ilMail::ILIAS_HOST) {
163 $q = "SELECT dat.obj_id " .
164 "FROM object_data dat " .
165 "JOIN object_reference ref ON ref.obj_id = dat.obj_id " .
166 "JOIN tree t ON t.child = ref.ref_id " .
167 "WHERE dat.title = " . $this->db->quote($domain, 'text') . " " .
168 "AND dat.type = 'role' " .
169 "AND t.tree = 1 ";
170 $res = $this->db->query($q);
171
172 while ($row = $this->db->fetchAssoc($res)) {
173 $role_ids[] = $row['obj_id'];
174 }
175 }
176 }
177
178 return $role_ids;
179 }
180}
$parser
Definition: BPMN2Parser.php:23
if(!array_key_exists('domain', $_REQUEST)) $domain
Definition: resume.php:8
An exception for terminatinating execution or to throw for unit testing.
Class ilMailRfc822AddressParserFactory.
const ILIAS_HOST
Class ilRoleMailboxSearch.
searchRoleIdsByAddressString(string $a_address_list)
Finds all role ids that match the specified user friendly role mailbox address list.
__construct(\ilMailRfc822AddressParserFactory $parserFactory, \ilDBInterface $db=null)
ilRoleMailboxSearch constructor.
Interface ilDBInterface.
$row
$query
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res