ILIAS  release_8 Revision v8.24
ilMailAutoCompleteUserProvider Class Reference

Class ilMailAutoCompleteUserProvider. More...

+ Inheritance diagram for ilMailAutoCompleteUserProvider:
+ Collaboration diagram for ilMailAutoCompleteUserProvider:

Public Member Functions

 current ()
 
 key ()
 
 rewind ()
 
- Public Member Functions inherited from ilMailAutoCompleteRecipientProvider
 __construct (string $quoted_term, string $term)
 
 valid ()
 
 next ()
 
 __destruct ()
 

Protected Member Functions

 getSelectPart ()
 
 getFromPart ()
 
 getWherePart (string $search_query)
 
 getOrderByPart ()
 
 getQueryConditionByFieldAndValue (string $field, $a_str)
 
 getFields ()
 

Additional Inherited Members

- Protected Attributes inherited from ilMailAutoCompleteRecipientProvider
ilDBInterface $db
 
ilDBStatement $res = null
 
array $data = null
 
string $quoted_term
 
string $term = ''
 
int $user_id = 0
 

Detailed Description

Member Function Documentation

◆ current()

ilMailAutoCompleteUserProvider::current ( )
Returns
array{login: string, firstname: string, lastname:string}

Definition at line 29 of file class.ilMailAutoCompleteUserProvider.php.

29 : array
30 {
31 return [
32 'login' => $this->data['login'],
33 'firstname' => $this->data['firstname'],
34 'lastname' => $this->data['lastname'],
35 ];
36 }

◆ getFields()

ilMailAutoCompleteUserProvider::getFields ( )
protected
Returns
string[]

Definition at line 179 of file class.ilMailAutoCompleteUserProvider.php.

179 : array
180 {
181 $available_fields = [];
182 foreach (['firstname', 'lastname'] as $field) {
184 $available_fields[] = $field;
185 }
186 }
187 return $available_fields;
188 }

References ilUserSearchOptions\_isEnabled().

Referenced by getWherePart().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFromPart()

ilMailAutoCompleteUserProvider::getFromPart ( )
protected

Reimplemented in ilMailAutoCompleteBuddyRecipientsProvider.

Definition at line 92 of file class.ilMailAutoCompleteUserProvider.php.

92 : string
93 {
94 $joins = [];
95
96 $joins[] = '
97 LEFT JOIN usr_pref profpref
98 ON profpref.usr_id = usr_data.usr_id
99 AND profpref.keyword = ' . $this->db->quote('public_profile', 'text');
100
101 $joins[] = '
102 LEFT JOIN usr_pref pubemail
103 ON pubemail.usr_id = usr_data.usr_id
104 AND pubemail.keyword = ' . $this->db->quote('public_email', 'text');
105
106 return 'usr_data ' . implode(' ', $joins);
107 }

Referenced by rewind().

+ Here is the caller graph for this function:

◆ getOrderByPart()

ilMailAutoCompleteUserProvider::getOrderByPart ( )
protected

Definition at line 166 of file class.ilMailAutoCompleteUserProvider.php.

166 : string
167 {
168 return 'login ASC';
169 }

Referenced by rewind().

+ Here is the caller graph for this function:

◆ getQueryConditionByFieldAndValue()

ilMailAutoCompleteUserProvider::getQueryConditionByFieldAndValue ( string  $field,
  $a_str 
)
protected

Definition at line 171 of file class.ilMailAutoCompleteUserProvider.php.

171 : string
172 {
173 return $this->db->like($field, 'text', $a_str . '%');
174 }

Referenced by getWherePart().

+ Here is the caller graph for this function:

◆ getSelectPart()

ilMailAutoCompleteUserProvider::getSelectPart ( )
protected

Definition at line 63 of file class.ilMailAutoCompleteUserProvider.php.

63 : string
64 {
65 $fields = [
66 'login',
67 sprintf(
68 '(CASE WHEN (firstname IS NOT NULL AND (profpref.value = %s OR profpref.value = %s)) THEN firstname ELSE \'\' END) firstname',
69 $this->db->quote('y', 'text'),
70 $this->db->quote('g', 'text')
71 ),
72 sprintf(
73 '(CASE WHEN (lastname IS NOT NULL AND (profpref.value = %s OR profpref.value = %s)) THEN lastname ELSE \'\' END) lastname',
74 $this->db->quote('y', 'text'),
75 $this->db->quote('g', 'text')
76 ),
77 sprintf(
78 "(CASE WHEN (email IS NOT NULL AND (profpref.value = %s OR profpref.value = %s) " .
79 "AND pubemail.value = %s) THEN email ELSE '' END) email",
80 $this->db->quote('y', 'text'),
81 $this->db->quote('g', 'text'),
82 $this->db->quote('y', 'text')
83 ),
84 ];
85
86 $fields[] = 'profpref.value profile_value';
87 $fields[] = 'pubemail.value email_value';
88
89 return implode(', ', $fields);
90 }

Referenced by rewind().

+ Here is the caller graph for this function:

◆ getWherePart()

ilMailAutoCompleteUserProvider::getWherePart ( string  $search_query)
protected

Definition at line 109 of file class.ilMailAutoCompleteUserProvider.php.

109 : string
110 {
111 $outer_conditions = [];
112 $outer_conditions[] = 'usr_data.usr_id != ' . $this->db->quote(ANONYMOUS_USER_ID, 'integer');
113 $outer_conditions[] = 'usr_data.active != ' . $this->db->quote(0, 'integer');
114
115 $field_conditions = [];
116 foreach ($this->getFields() as $field) {
117 $field_condition = $this->getQueryConditionByFieldAndValue($field, $search_query);
118
119 if ('email' === $field) {
120 // If privacy should be respected,
121 // the profile setting of every user concerning the email address has to be
122 // respected (in every user context, no matter if the user is 'logged in' or 'anonymous').
123 $email_query = [];
124 $email_query[] = $field_condition;
125 $email_query[] = 'pubemail.value = ' . $this->db->quote('y', 'text');
126 $field_conditions[] = '(' . implode(' AND ', $email_query) . ')';
127 } else {
128 $field_conditions[] = $field_condition;
129 }
130 }
131
132 // If the current user context ist 'logged in' and privacy should be respected,
133 // all fields >>>except the login<<<
134 // should only be searchable if the users' profile is published (y oder g)
135 // In 'anonymous' context we do not need this additional conditions,
136 // because we checked the privacy setting in the condition above: profile = 'g'
137 if ($field_conditions) {
138 $fields = '(' . implode(' OR ', $field_conditions) . ')';
139
140 $field_conditions = ['(' . implode(' AND ', [
141 $fields,
142 $this->db->in('profpref.value', ['y', 'g'], false, 'text'),
143 ]) . ')'];
144 }
145
146 // The login field must be searchable regardless (for 'logged in' users) of any privacy settings.
147 // We handled the general condition for 'anonymous' context above: profile = 'g'
148 $field_conditions[] = $this->getQueryConditionByFieldAndValue('login', $search_query);
149
150 if (ilUserAccountSettings::getInstance()->isUserAccessRestricted()) {
151 $outer_conditions[] = $this->db->in(
152 'time_limit_owner',
153 ilUserFilter::getInstance()->getFolderIds(),
154 false,
155 'integer'
156 );
157 }
158
159 if ($field_conditions) {
160 $outer_conditions[] = '(' . implode(' OR ', $field_conditions) . ')';
161 }
162
163 return implode(' AND ', $outer_conditions);
164 }
const ANONYMOUS_USER_ID
Definition: constants.php:27

References ANONYMOUS_USER_ID, getFields(), ilUserAccountSettings\getInstance(), ilUserFilter\getInstance(), and getQueryConditionByFieldAndValue().

Referenced by rewind().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ key()

ilMailAutoCompleteUserProvider::key ( )

Definition at line 38 of file class.ilMailAutoCompleteUserProvider.php.

38 : string
39 {
40 return $this->data['login'];
41 }

◆ rewind()

ilMailAutoCompleteUserProvider::rewind ( )

Definition at line 43 of file class.ilMailAutoCompleteUserProvider.php.

43 : void
44 {
45 if ($this->res) {
46 $this->db->free($this->res);
47 $this->res = null;
48 }
49
50 $select_part = $this->getSelectPart();
51 $where_part = $this->getWherePart($this->quoted_term);
52 $order_by_part = $this->getOrderByPart();
53 $query = implode(" ", [
54 'SELECT ' . $select_part,
55 'FROM ' . $this->getFromPart(),
56 $where_part ? 'WHERE ' . $where_part : '',
57 $order_by_part ? 'ORDER BY ' . $order_by_part : '',
58 ]);
59
60 $this->res = $this->db->query($query);
61 }
$query

References $query, getFromPart(), getOrderByPart(), getSelectPart(), and getWherePart().

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: