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