ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
ilMailAutoCompleteUserProvider Class Reference
+ Inheritance diagram for ilMailAutoCompleteUserProvider:
+ Collaboration diagram for ilMailAutoCompleteUserProvider:

Public Member Functions

 current ()
 
 key ()
 
 rewind ()
 
- Public Member Functions inherited from ilMailAutoCompleteRecipientProvider
 __construct (protected string $quoted_term, protected 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
 
int $user_id = 0
 

Detailed Description

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

Member Function Documentation

◆ current()

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

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

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

◆ getFields()

ilMailAutoCompleteUserProvider::getFields ( )
protected
Returns
string[]

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

References ilUserSearchOptions\_isEnabled().

Referenced by getWherePart().

176  : array
177  {
178  $available_fields = [];
179  foreach (['firstname', 'lastname'] as $field) {
180  if (ilUserSearchOptions::_isEnabled($field)) {
181  $available_fields[] = $field;
182  }
183  }
184  return $available_fields;
185  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFromPart()

ilMailAutoCompleteUserProvider::getFromPart ( )
protected

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

Referenced by rewind().

89  : string
90  {
91  $joins = [];
92 
93  $joins[] = '
94  LEFT JOIN usr_pref profpref
95  ON profpref.usr_id = usr_data.usr_id
96  AND profpref.keyword = ' . $this->db->quote('public_profile', 'text');
97 
98  $joins[] = '
99  LEFT JOIN usr_pref pubemail
100  ON pubemail.usr_id = usr_data.usr_id
101  AND pubemail.keyword = ' . $this->db->quote('public_email', 'text');
102 
103  return 'usr_data ' . implode(' ', $joins);
104  }
+ Here is the caller graph for this function:

◆ getOrderByPart()

ilMailAutoCompleteUserProvider::getOrderByPart ( )
protected

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

Referenced by rewind().

163  : string
164  {
165  return 'login ASC';
166  }
+ Here is the caller graph for this function:

◆ getQueryConditionByFieldAndValue()

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

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

Referenced by getWherePart().

168  : string
169  {
170  return $this->db->like($field, 'text', $a_str . '%');
171  }
+ Here is the caller graph for this function:

◆ getSelectPart()

ilMailAutoCompleteUserProvider::getSelectPart ( )
protected

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

Referenced by rewind().

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

◆ getWherePart()

ilMailAutoCompleteUserProvider::getWherePart ( string  $search_query)
protected

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

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

Referenced by rewind().

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

◆ key()

ilMailAutoCompleteUserProvider::key ( )

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

35  : string
36  {
37  return $this->data['login'];
38  }

◆ rewind()

ilMailAutoCompleteUserProvider::rewind ( )

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

References getFromPart(), getOrderByPart(), getSelectPart(), getWherePart(), and null.

40  : void
41  {
42  if ($this->res !== null) {
43  $this->db->free($this->res);
44  $this->res = null;
45  }
46 
47  $select_part = $this->getSelectPart();
48  $where_part = $this->getWherePart($this->quoted_term);
49  $order_by_part = $this->getOrderByPart();
50  $query = implode(' ', [
51  'SELECT ' . $select_part,
52  'FROM ' . $this->getFromPart(),
53  $where_part !== '' ? 'WHERE ' . $where_part : '',
54  $order_by_part !== '' ? 'ORDER BY ' . $order_by_part : '',
55  ]);
56 
57  $this->res = $this->db->query($query);
58  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
+ Here is the call graph for this function:

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