ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilUserSearchOptions.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
34{
35 public const FIELD_TYPE_UDF_UNDEFINED = 0;
36 public const FIELD_TYPE_UDF_SELECT = 1;
37 public const FIELD_TYPE_UDF_TEXT = 2;
38 public const FIELD_TYPE_SELECT = 3;
39 public const FIELD_TYPE_TEXT = 4;
40 // begin-patch lok
41 public const FIELD_TYPE_MULTI = 5;
42 // end-patch lok
43 public const FIELD_TYPE_UDF_WYSIWYG = 6;
44
45
51 public static function getSelectableColumnInfo(bool $a_admin = false): array
52 {
53 $col_info = array();
54 foreach (self::_getSearchableFieldsInfo($a_admin) as $field) {
55 if (is_numeric($field['db'])) {
56 $field['db'] = 'udf_' . $field['db'];
57 }
58
59 $col_info[$field['db']] = array(
60 'txt' => $field['lang']
61 );
62
63 if ($field['db'] == 'login' or $field['db'] == 'firstname' or $field['db'] == 'lastname') {
64 $col_info[$field['db']]['default'] = true;
65 }
66 }
67 return $col_info;
68 }
69
70 public static function _getSearchableFieldsInfo(bool $a_admin = false): array
71 {
72 global $DIC;
73
74 $lng = $DIC->language();
75
76 // begin-patch lok
77 $lng->loadLanguageModule('user');
78 // end-patch lok
79
80 $counter = 1;
81 $fields = [];
82 foreach (ilUserSearchOptions::_getPossibleFields($a_admin) as $field) {
83 // TODO: check enabled
84 // DONE
85 if ($a_admin == false and !ilUserSearchOptions::_isEnabled($field)) {
86 continue;
87 }
88 $fields[$counter]['values'] = array();
89 $fields[$counter]['type'] = self::FIELD_TYPE_TEXT;
90 $fields[$counter]['lang'] = $lng->txt($field);
91 $fields[$counter]['db'] = $field;
92
96 $fields[$counter]['autoComplete'] = false;
97 switch ($field) {
98 case 'login':
99 case 'firstname':
100 case 'lastname':
101 case 'email':
102 case 'second_email':
103 $fields[$counter]['autoComplete'] = true;
104 break;
105
106 case 'title':
107 $fields[$counter]['lang'] = $lng->txt('person_title');
108 break;
109
110 // SELECTS
111
112 case 'gender':
113 $fields[$counter]['type'] = self::FIELD_TYPE_SELECT;
114 $fields[$counter]['values'] = array(
115 0 => $lng->txt('please_choose'),
116 'n' => $lng->txt('gender_n'),
117 'f' => $lng->txt('gender_f'),
118 'm' => $lng->txt('gender_m'),
119 );
120 break;
121
122 case 'sel_country':
123 $fields[$counter]['type'] = self::FIELD_TYPE_SELECT;
124 $fields[$counter]['values'] = array(0 => $lng->txt('please_choose'));
125
126 // #7843 -- see ilCountrySelectInputGUI
127 $lng->loadLanguageModule('meta');
128 foreach (ilCountry::getCountryCodes() as $c) {
129 $fields[$counter]['values'][$c] = $lng->txt('meta_c_' . $c);
130 }
131 asort($fields[$counter]['values']);
132 break;
133
134 case 'org_units':
135 $fields[$counter]['type'] = self::FIELD_TYPE_SELECT;
137 $options[0] = $lng->txt('select_one');
138 foreach ($paths as $org_ref_id => $path) {
139 $options[$org_ref_id] = $path;
140 }
141
142 $fields[$counter]['values'] = $options;
143 break;
144
145
146 // begin-patch lok
147 case 'interests_general':
148 case 'interests_help_offered':
149 case 'interests_help_looking':
150 $fields[$counter]['type'] = self::FIELD_TYPE_MULTI;
151 break;
152 }
153
154 ++$counter;
155 }
157
158 return $fields ?: array();
159 }
160
161 public static function _getPossibleFields(bool $a_admin = false): array
162 {
163 return array('gender',
164 'lastname',
165 'firstname',
166 'login',
167 'title',
168 'institution',
169 'department',
170 'street',
171 'zipcode',
172 'city',
173 'country',
174 'sel_country',
175 'email',
176 'second_email',
177 'hobby',
178 'org_units',
179 // begin-patch lok
180 'matriculation',
181 'interests_general',
182 'interests_help_offered',
183 'interests_help_looking'
184 );
185 // end-patch lok
186 }
187
188 public static function _isSearchable(string $a_key): bool
189 {
190 return in_array($a_key, ilUserSearchOptions::_getPossibleFields());
191 }
192
193 public static function _isEnabled($a_key): bool
194 {
195 global $DIC;
196
197 $settings = $DIC->settings();
198
199 // login is always enabled
200 if ($a_key == 'login') {
201 return true;
202 }
203 return (bool) $settings->get('search_enabled_' . $a_key);
204 }
205
206 public static function _saveStatus(string $a_key, bool $a_enabled): bool
207 {
208 global $DIC;
209
210 $ilias = $DIC['ilias'];
211
212 $ilias->setSetting('search_enabled_' . $a_key, (string) $a_enabled);
213 return true;
214 }
215
216 public static function __appendUserDefinedFields(array $fields, int $counter): array
217 {
218 global $DIC;
219 $lng = $DIC->language();
220 foreach ($DIC['user']->getProfile()->getVisibleUserDefinedFields(Context::Search) as $field) {
221 $input = $field->getLegacyInput($lng, Context::Search);
222 if ($input instanceof ilSelectInputGUI) {
223 $fields[$counter]['values'] = ilUserSearchOptions::__prepareValues($input->getOptions());
224 $fields[$counter]['type'] = self::FIELD_TYPE_UDF_SELECT;
225 }
226 $fields[$counter]['lang'] = $field->getLabel($lng);
227 $fields[$counter]['db'] = $field->getIdentifier();
228
229 switch (get_class($input)) {
230 case ilTextInputGUI::class:
231 $fields[$counter]['type'] = self::FIELD_TYPE_UDF_TEXT;
232 break;
233
234 case ilTextAreaInputGUI::class:
235 $fields[$counter]['type'] = self::FIELD_TYPE_UDF_WYSIWYG;
236 break;
237
238 default:
239 // do not throw: udf plugin support
240 $fields[$counter]['type'] = get_class($input);
241 break;
242 }
243 ++$counter;
244 }
245 return $fields;
246 }
247
248 public static function __prepareValues(array $a_values): array
249 {
250 global $DIC;
251
252 $lng = $DIC->language();
253
254 $new_values = array(0 => $lng->txt('please_choose'));
255 foreach ($a_values as $value) {
256 $new_values[$value] = $value;
257 }
258 return $new_values;
259 }
260}
static getCountryCodes()
Get country codes (DIN EN 3166-1)
static getTextRepresentationOfOrgUnits(bool $sort_by_title=true)
Get ref id path array.
This class represents a selection list property in a property form.
Class ilUserSearchOptions.
static __appendUserDefinedFields(array $fields, int $counter)
static _getSearchableFieldsInfo(bool $a_admin=false)
static _saveStatus(string $a_key, bool $a_enabled)
static _isSearchable(string $a_key)
static __prepareValues(array $a_values)
static _getPossibleFields(bool $a_admin=false)
static getSelectableColumnInfo(bool $a_admin=false)
Get info of searchable fields for selectable columns in table gui.
$c
Definition: deliver.php:25
$path
Definition: ltiservices.php:30
global $lng
Definition: privfeed.php:31
global $DIC
Definition: shib_login.php:26
$counter