ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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) 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) 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) 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 $outer_conditions[] = 'usr_data.active != ' . $this->db->quote(0, 'integer');
140
141 $field_conditions = array();
142 foreach ($this->getFields() as $field) {
143 $field_condition = $this->getQueryConditionByFieldAndValue($field, $search_query);
144
145 if ('email' == $field) {
146 // If privacy should be respected, the profile setting of every user concerning the email address has to be
147 // respected (in every user context, no matter if the user is 'logged in' or 'anonymous').
148 $email_query = array();
149 $email_query[] = $field_condition;
150 $email_query[] = 'pubemail.value = ' . $this->db->quote('y', 'text');
151 $field_conditions[] = '(' . implode(' AND ', $email_query) . ')';
152 } else {
153 $field_conditions[] = $field_condition;
154 }
155 }
156
157 // If the current user context ist 'logged in' and privacy should be respected, all fields >>>except the login<<<
158 // should only be searchable if the users' profile is published (y oder g)
159 // In 'anonymous' context we do not need this additional conditions,
160 // because we checked the privacy setting in the condition above: profile = 'g'
161 if ($field_conditions) {
162 $fields = '(' . implode(' OR ', $field_conditions) . ')';
163
164 $field_conditions = ['(' . implode(' AND ', array(
165 $fields,
166 $this->db->in('profpref.value', array('y', 'g'), false, 'text')
167 )) . ')'];
168 }
169
170 // The login field must be searchable regardless (for 'logged in' users) of any privacy settings.
171 // We handled the general condition for 'anonymous' context above: profile = 'g'
172 $field_conditions[] = $this->getQueryConditionByFieldAndValue('login', $search_query);
173
174 include_once 'Services/User/classes/class.ilUserAccountSettings.php';
175 if (ilUserAccountSettings::getInstance()->isUserAccessRestricted()) {
176 include_once './Services/User/classes/class.ilUserFilter.php';
177 $outer_conditions[] = $this->db->in('time_limit_owner', ilUserFilter::getInstance()->getFolderIds(), false, 'integer');
178 }
179
180 if ($field_conditions) {
181 $outer_conditions[] = '(' . implode(' OR ', $field_conditions) . ')';
182 }
183
184 return implode(' AND ', $outer_conditions);
185 }
186
190 protected function getOrderByPart()
191 {
192 return 'login ASC';
193 }
194
200 protected function getQueryConditionByFieldAndValue($field, $a_str)
201 {
202 return $this->db->like($field, 'text', $a_str . '%');
203 }
204
209 protected function getFields()
210 {
211 $available_fields = array();
212 foreach (array('firstname', 'lastname') as $field) {
213 include_once 'Services/Search/classes/class.ilUserSearchOptions.php';
215 $available_fields[] = $field;
216 }
217 }
218 return $available_fields;
219 }
220}
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']