ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilMailAutoCompleteUserProvider.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once 'Services/User/classes/class.ilUserAutoComplete.php';
5require_once 'Services/Mail/classes/class.ilMailAutoCompleteRecipientProvider.php';
6
11{
16 public function __construct($quoted_term, $term)
17 {
18 parent::__construct($quoted_term, $term);
19 }
20
25 public function valid()
26 {
27 $this->data = $this->db->fetchAssoc($this->res);
28
29 return is_array($this->data);
30 }
31
36 public function current()
37 {
38 return array(
39 'login' => $this->data['login'],
40 'firstname' => $this->data['firstname'],
41 'lastname' => $this->data['lastname']
42 );
43 }
44
49 public function key()
50 {
51 return $this->data['login'];
52 }
53
57 public function rewind()
58 {
59 if($this->res)
60 {
61 $this->db->free($this->res);
62 $this->res = null;
63 }
64 $select_part = $this->getSelectPart();
65 $where_part = $this->getWherePart($this->quoted_term);
66 $order_by_part = $this->getOrderByPart();
67 $query = implode(" ", array(
68 'SELECT ' . $select_part,
69 'FROM ' . $this->getFromPart(),
70 $where_part ? 'WHERE ' . $where_part : '',
71 $order_by_part ? 'ORDER BY ' . $order_by_part : ''
72 ));
73
74 $this->res = $this->db->query($query);
75 }
76
80 protected function getSelectPart()
81 {
82 $fields = array(
83 'login',
84 sprintf(
85 "(CASE WHEN (profpref.value = %s OR profpref.value = %s OR profpref.value IS NULL) THEN firstname ELSE '' END) firstname",
86 $this->db->quote('y', 'text'), $this->db->quote('g', 'text')
87 ),
88 sprintf(
89 "(CASE WHEN (profpref.value = %s OR profpref.value = %s OR profpref.value IS NULL) THEN lastname ELSE '' END) lastname",
90 $this->db->quote('y', 'text'), $this->db->quote('g', 'text')
91 ),
92 sprintf(
93 "(CASE WHEN ((profpref.value = %s OR profpref.value = %s OR profpref.value IS NULL) AND pubemail.value = %s) THEN email ELSE '' END) email",
94 $this->db->quote('y', 'text'), $this->db->quote('g', 'text'), $this->db->quote('y', 'text')
95 ),
96 );
97
98 $fields[] = 'profpref.value profile_value';
99 $fields[] = 'pubemail.value email_value';
100
101 return implode(', ', $fields);
102 }
103
107 protected function getFromPart()
108 {
112 global $ilDB;
113
114 $joins = array();
115
116 $joins[] = '
117 LEFT JOIN usr_pref profpref
118 ON profpref.usr_id = usr_data.usr_id
119 AND profpref.keyword = ' . $ilDB->quote('public_profile', 'text');
120
121 $joins[] = '
122 LEFT JOIN usr_pref pubemail
123 ON pubemail.usr_id = usr_data.usr_id
124 AND pubemail.keyword = ' . $ilDB->quote('public_email', 'text');
125
126 if($joins)
127 {
128 return 'usr_data ' . implode(' ', $joins);
129 }
130 else
131 {
132 return 'usr_data ';
133 }
134 }
135
140 protected function getWherePart($search_query)
141 {
145 global $ilDB;
146
147 $outer_conditions = array();
148 $outer_conditions[] = 'usr_data.usr_id != ' . $ilDB->quote(ANONYMOUS_USER_ID, 'integer');
149
150 $field_conditions = array();
151 foreach($this->getFields() as $field)
152 {
153 $field_condition = $this->getQueryConditionByFieldAndValue($field, $search_query);
154
155 if('email' == $field)
156 {
157 // If privacy should be respected, the profile setting of every user concerning the email address has to be
158 // respected (in every user context, no matter if the user is 'logged in' or 'anonymous').
159 $email_query = array();
160 $email_query[] = $field_condition;
161 $email_query[] = 'pubemail.value = ' . $ilDB->quote('y', 'text');
162 $field_conditions[] = '(' . implode(' AND ', $email_query) . ')';
163 }
164 else
165 {
166 $field_conditions[] = $field_condition;
167 }
168 }
169
170 // If the current user context ist 'logged in' and privacy should be respected, all fields >>>except the login<<<
171 // should only be searchable if the users' profile is published (y oder g)
172 // In 'anonymous' context we do not need this additional conditions,
173 // because we checked the privacy setting in the condition above: profile = 'g'
174 if ($field_conditions) {
175 $fields = '(' . implode(' OR ', $field_conditions) . ')';
176
177 $field_conditions = ['(' . implode(' AND ', array(
178 $fields,
179 $ilDB->in('profpref.value', array('y', 'g'), false, 'text')
180 )) . ')'];
181 }
182
183 // The login field must be searchable regardless (for 'logged in' users) of any privacy settings.
184 // We handled the general condition for 'anonymous' context above: profile = 'g'
185 $field_conditions[] = $this->getQueryConditionByFieldAndValue('login', $search_query);
186
187 include_once 'Services/User/classes/class.ilUserAccountSettings.php';
188 if(ilUserAccountSettings::getInstance()->isUserAccessRestricted())
189 {
190 include_once './Services/User/classes/class.ilUserFilter.php';
191 $outer_conditions[] = $ilDB->in('time_limit_owner', ilUserFilter::getInstance()->getFolderIds(), false, 'integer');
192 }
193
194 if($field_conditions)
195 {
196 $outer_conditions[] = '(' . implode(' OR ', $field_conditions) . ')';
197 }
198
199 return implode(' AND ', $outer_conditions);
200 }
201
205 protected function getOrderByPart()
206 {
207 return 'login ASC';
208 }
209
215 protected function getQueryConditionByFieldAndValue($field, $a_str)
216 {
220 global $ilDB;
221
222 return $ilDB->like($field, 'text', $a_str . '%');
223 }
224
229 protected function getFields()
230 {
231 $available_fields = array();
232 foreach(array('firstname', 'lastname') as $field)
233 {
234 include_once 'Services/Search/classes/class.ilUserSearchOptions.php';
236 {
237 $available_fields[] = $field;
238 }
239 }
240 return $available_fields;
241 }
242}
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
Class ilMailAutoCompleteUserProvider.
rewind()
"Rewind "implementation of iterator interface
key()
"Key" implementation of iterator interface
current()
"Current" implementation of iterator interface
valid()
"Valid" implementation of iterator interface
static getInstance()
Singelton get instance.
static getInstance()
Singelton get instance.
global $ilDB