ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 $this->db->free($this->res);
61 $this->res = null;
62 }
63 $select_part = $this->getSelectPart();
64 $where_part = $this->getWherePart($this->quoted_term);
65 $order_by_part = $this->getOrderByPart();
66 $query = implode(" ", array(
67 'SELECT ' . $select_part,
68 'FROM ' . $this->getFromPart(),
69 $where_part ? 'WHERE ' . $where_part : '',
70 $order_by_part ? 'ORDER BY ' . $order_by_part : ''
71 ));
72
73 $this->res = $this->db->query($query);
74 }
75
79 protected function getSelectPart()
80 {
81 $fields = array(
82 'login',
83 sprintf(
84 "(CASE WHEN (profpref.value = %s OR profpref.value = %s OR profpref.value IS NULL) THEN firstname ELSE '' END) firstname",
85 $this->db->quote('y', 'text'),
86 $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'),
91 $this->db->quote('g', 'text')
92 ),
93 sprintf(
94 "(CASE WHEN ((profpref.value = %s OR profpref.value = %s OR profpref.value IS NULL) AND pubemail.value = %s) THEN email ELSE '' END) email",
95 $this->db->quote('y', 'text'),
96 $this->db->quote('g', 'text'),
97 $this->db->quote('y', 'text')
98 ),
99 );
100
101 $fields[] = 'profpref.value profile_value';
102 $fields[] = 'pubemail.value email_value';
103
104 return implode(', ', $fields);
105 }
106
110 protected function getFromPart()
111 {
112 $joins = array();
113
114 $joins[] = '
115 LEFT JOIN usr_pref profpref
116 ON profpref.usr_id = usr_data.usr_id
117 AND profpref.keyword = ' . $this->db->quote('public_profile', 'text');
118
119 $joins[] = '
120 LEFT JOIN usr_pref pubemail
121 ON pubemail.usr_id = usr_data.usr_id
122 AND pubemail.keyword = ' . $this->db->quote('public_email', 'text');
123
124 if ($joins) {
125 return 'usr_data ' . implode(' ', $joins);
126 } else {
127 return 'usr_data ';
128 }
129 }
130
135 protected function getWherePart($search_query)
136 {
137 $outer_conditions = array();
138 $outer_conditions[] = 'usr_data.usr_id != ' . $this->db->quote(ANONYMOUS_USER_ID, 'integer');
139
140 $field_conditions = array();
141 foreach ($this->getFields() as $field) {
142 $field_condition = $this->getQueryConditionByFieldAndValue($field, $search_query);
143
144 if ('email' == $field) {
145 // If privacy should be respected, the profile setting of every user concerning the email address has to be
146 // respected (in every user context, no matter if the user is 'logged in' or 'anonymous').
147 $email_query = array();
148 $email_query[] = $field_condition;
149 $email_query[] = 'pubemail.value = ' . $this->db->quote('y', 'text');
150 $field_conditions[] = '(' . implode(' AND ', $email_query) . ')';
151 } else {
152 $field_conditions[] = $field_condition;
153 }
154 }
155
156 // If the current user context ist 'logged in' and privacy should be respected, all fields >>>except the login<<<
157 // should only be searchable if the users' profile is published (y oder g)
158 // In 'anonymous' context we do not need this additional conditions,
159 // because we checked the privacy setting in the condition above: profile = 'g'
160 if ($field_conditions) {
161 $fields = '(' . implode(' OR ', $field_conditions) . ')';
162
163 $field_conditions = ['(' . implode(' AND ', array(
164 $fields,
165 $this->db->in('profpref.value', array('y', 'g'), false, 'text')
166 )) . ')'];
167 }
168
169 // The login field must be searchable regardless (for 'logged in' users) of any privacy settings.
170 // We handled the general condition for 'anonymous' context above: profile = 'g'
171 $field_conditions[] = $this->getQueryConditionByFieldAndValue('login', $search_query);
172
173 include_once 'Services/User/classes/class.ilUserAccountSettings.php';
174 if (ilUserAccountSettings::getInstance()->isUserAccessRestricted()) {
175 include_once './Services/User/classes/class.ilUserFilter.php';
176 $outer_conditions[] = $this->db->in('time_limit_owner', ilUserFilter::getInstance()->getFolderIds(), false, 'integer');
177 }
178
179 if ($field_conditions) {
180 $outer_conditions[] = '(' . implode(' OR ', $field_conditions) . ')';
181 }
182
183 return implode(' AND ', $outer_conditions);
184 }
185
189 protected function getOrderByPart()
190 {
191 return 'login ASC';
192 }
193
199 protected function getQueryConditionByFieldAndValue($field, $a_str)
200 {
201 return $this->db->like($field, 'text', $a_str . '%');
202 }
203
208 protected function getFields()
209 {
210 $available_fields = array();
211 foreach (array('firstname', 'lastname') as $field) {
212 include_once 'Services/Search/classes/class.ilUserSearchOptions.php';
214 $available_fields[] = $field;
215 }
216 }
217 return $available_fields;
218 }
219}
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.
$query
$this data['403_header']