ILIAS  release_8 Revision v8.24
class.ilUserSearchOptions.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
30{
31 public const FIELD_TYPE_UDF_UNDEFINED = 0;
32 public const FIELD_TYPE_UDF_SELECT = 1;
33 public const FIELD_TYPE_UDF_TEXT = 2;
34 public const FIELD_TYPE_SELECT = 3;
35 public const FIELD_TYPE_TEXT = 4;
36 // begin-patch lok
37 public const FIELD_TYPE_MULTI = 5;
38 // end-patch lok
39 public const FIELD_TYPE_UDF_WYSIWYG = 6;
40
41
47 public static function getSelectableColumnInfo(bool $a_admin = false): array
48 {
49 $col_info = array();
50 foreach (self::_getSearchableFieldsInfo($a_admin) as $field) {
51 if (is_numeric($field['db'])) {
52 $field['db'] = 'udf_' . $field['db'];
53 }
54
55 $col_info[$field['db']] = array(
56 'txt' => $field['lang']
57 );
58
59 if ($field['db'] == 'login' or $field['db'] == 'firstname' or $field['db'] == 'lastname') {
60 $col_info[$field['db']]['default'] = true;
61 }
62 }
63 return $col_info;
64 }
65
66 public static function _getSearchableFieldsInfo(bool $a_admin = false): array
67 {
68 global $DIC;
69
70 $lng = $DIC->language();
71
72 // begin-patch lok
73 $lng->loadLanguageModule('user');
74 // end-patch lok
75
76 $counter = 1;
77 $fields = [];
78 foreach (ilUserSearchOptions::_getPossibleFields($a_admin) as $field) {
79 // TODO: check enabled
80 // DONE
81 if ($a_admin == false and !ilUserSearchOptions::_isEnabled($field)) {
82 continue;
83 }
84 $fields[$counter]['values'] = array();
85 $fields[$counter]['type'] = self::FIELD_TYPE_TEXT;
86 $fields[$counter]['lang'] = $lng->txt($field);
87 $fields[$counter]['db'] = $field;
88
92 $fields[$counter]['autoComplete'] = false;
93 switch ($field) {
94 case 'login':
95 case 'firstname':
96 case 'lastname':
97 case 'email':
98 case 'second_email':
99 $fields[$counter]['autoComplete'] = true;
100 break;
101
102 case 'title':
103 $fields[$counter]['lang'] = $lng->txt('person_title');
104 break;
105
106 // SELECTS
107
108 case 'gender':
109 $fields[$counter]['type'] = self::FIELD_TYPE_SELECT;
110 $fields[$counter]['values'] = array(
111 0 => $lng->txt('please_choose'),
112 'n' => $lng->txt('gender_n'),
113 'f' => $lng->txt('gender_f'),
114 'm' => $lng->txt('gender_m'),
115 );
116 break;
117
118 case 'sel_country':
119 $fields[$counter]['type'] = self::FIELD_TYPE_SELECT;
120 $fields[$counter]['values'] = array(0 => $lng->txt('please_choose'));
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 break;
129
130 case 'org_units':
131 $fields[$counter]['type'] = self::FIELD_TYPE_SELECT;
133 $options[0] = $lng->txt('select_one');
134 foreach ($paths as $org_ref_id => $path) {
135 $options[$org_ref_id] = $path;
136 }
137
138 $fields[$counter]['values'] = $options;
139 break;
140
141
142 // begin-patch lok
143 case 'interests_general':
144 case 'interests_help_offered':
145 case 'interests_help_looking':
146 $fields[$counter]['type'] = self::FIELD_TYPE_MULTI;
147 break;
148 }
149
150 ++$counter;
151 }
152 $fields = ilUserSearchOptions::__appendUserDefinedFields($fields, $counter);
153
154 return $fields ?: array();
155 }
156
157 public static function _getPossibleFields(bool $a_admin = false): array
158 {
159 return array('gender',
160 'lastname',
161 'firstname',
162 'login',
163 'title',
164 'institution',
165 'department',
166 'street',
167 'zipcode',
168 'city',
169 'country',
170 'sel_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
193 $settings = $DIC->settings();
194
195 // login is always enabled
196 if ($a_key == 'login') {
197 return true;
198 }
199 return (bool) $settings->get('search_enabled_' . $a_key);
200 }
201
202 public static function _saveStatus(string $a_key, bool $a_enabled): bool
203 {
204 global $DIC;
205
206 $ilias = $DIC['ilias'];
207
208 $ilias->setSetting('search_enabled_' . $a_key, (string) $a_enabled);
209 return true;
210 }
211
212 public static function __appendUserDefinedFields(array $fields, int $counter): array
213 {
214 $user_defined_fields = ilUserDefinedFields::_getInstance();
215 foreach ($user_defined_fields->getSearchableDefinitions() as $definition) {
216 $fields[$counter]['values'] = ilUserSearchOptions::__prepareValues($definition['field_values']);
217 $fields[$counter]['lang'] = $definition['field_name'];
218 $fields[$counter]['db'] = $definition['field_id'];
219
220 switch ($definition['field_type']) {
221 case UDF_TYPE_TEXT:
222 $fields[$counter]['type'] = self::FIELD_TYPE_UDF_TEXT;
223 break;
224
225 case UDF_TYPE_SELECT:
226 $fields[$counter]['type'] = self::FIELD_TYPE_UDF_SELECT;
227 break;
228
229 case UDF_TYPE_WYSIWYG:
230 $fields[$counter]['type'] = self::FIELD_TYPE_UDF_WYSIWYG;
231 break;
232
233 default:
234 // do not throw: udf plugin support
235 $fields[$counter]['type'] = $definition['field_type'];
236 break;
237 }
238 ++$counter;
239 }
240 return $fields;
241 }
242
243 public static function __prepareValues(array $a_values): array
244 {
245 global $DIC;
246
247 $lng = $DIC->language();
248
249 $new_values = array(0 => $lng->txt('please_choose'));
250 foreach ($a_values as $value) {
251 $new_values[$value] = $value;
252 }
253 return $new_values;
254 }
255}
const UDF_TYPE_SELECT
const UDF_TYPE_WYSIWYG
const UDF_TYPE_TEXT
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getCountryCodes()
Get country codes (DIN EN 3166-1)
static getTextRepresentationOfOrgUnits(bool $sort_by_title=true)
Get ref id path array.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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: cli.php:38
global $DIC
Definition: feed.php:28
$path
Definition: ltiservices.php:32
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
$lng