ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilUserSearchOptions.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
33define('FIELD_TYPE_UDF_SELECT', 1);
34define('FIELD_TYPE_UDF_TEXT', 2);
35define('FIELD_TYPE_SELECT', 3);
36define('FIELD_TYPE_TEXT', 4);
37// begin-patch lok
38define('FIELD_TYPE_MULTI', 5);
39// end-patch lok
40
41
42
43
45{
46 public $db = null;
47
53 public static function getSelectableColumnInfo($a_admin = false)
54 {
55 $col_info = array();
56 foreach (self::_getSearchableFieldsInfo($a_admin) as $field) {
57 if (is_numeric($field['db'])) {
58 $field['db'] = 'udf_' . $field['db'];
59 }
60
61 $col_info[$field['db']] = array(
62 'txt' => $field['lang']
63 );
64
65 if ($field['db'] == 'login' or $field['db'] == 'firstname' or $field['db'] == 'lastname') {
66 $col_info[$field['db']]['default'] = true;
67 }
68 }
69 return $col_info;
70 }
71
72 public static function _getSearchableFieldsInfo($a_admin = false)
73 {
74 global $lng;
75
76 // begin-patch lok
77 $lng->loadLanguageModule('user');
78 // end-patch lok
79
80 $counter = 1;
81 foreach (ilUserSearchOptions::_getPossibleFields($a_admin) as $field) {
82 // TODO: check enabled
83 // DONE
84 if ($a_admin == false and !ilUserSearchOptions::_isEnabled($field)) {
85 continue;
86 }
87 $fields[$counter]['values'] = array();
88 $fields[$counter]['type'] = FIELD_TYPE_TEXT;
89 $fields[$counter]['lang'] = $lng->txt($field);
90 $fields[$counter]['db'] = $field;
91
95 $fields[$counter]['autoComplete'] = false;
96 switch ($field) {
97 case 'login':
98 case 'firstname':
99 case 'lastname':
100 case 'email':
101 case 'second_email':
102 $fields[$counter]['autoComplete'] = true;
103 break;
104
105 case 'title':
106 $fields[$counter]['lang'] = $lng->txt('person_title');
107 break;
108
109 // SELECTS
110
111 case 'gender':
112 $fields[$counter]['type'] = FIELD_TYPE_SELECT;
113 $fields[$counter]['values'] = array(
114 0 => $lng->txt('please_choose'),
115 'n' => $lng->txt('gender_n'),
116 'f' => $lng->txt('gender_f'),
117 'm' => $lng->txt('gender_m'),
118 );
119 break;
120
121 case 'sel_country':
122 $fields[$counter]['type'] = FIELD_TYPE_SELECT;
123 $fields[$counter]['values'] = array(0 => $lng->txt('please_choose'));
124
125 // #7843 -- see ilCountrySelectInputGUI
126 $lng->loadLanguageModule('meta');
127 include_once('./Services/Utilities/classes/class.ilCountry.php');
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'] = FIELD_TYPE_SELECT;
136
137 include_once './Modules/OrgUnit/classes/PathStorage/class.ilOrgUnitPathStorage.php';
139
140 $options[0] = $lng->txt('select_one');
141 foreach ($paths as $org_ref_id => $path) {
142 $options[$org_ref_id] = $path;
143 }
144
145 $fields[$counter]['values'] = $options;
146 break;
147
148
149 // begin-patch lok
150 case 'interests_general':
151 case 'interests_help_offered':
152 case 'interests_help_looking':
153 $fields[$counter]['type'] = FIELD_TYPE_MULTI;
154 break;
155 // end-patch lok
156
157
158
159
160 /*
161 case 'active':
162 $fields[$counter]['type'] = FIELD_TYPE_SELECT;
163 $fields[$counter]['values'] = array(-1 => $lng->txt('please_choose'),
164 '1' => $lng->txt('active'),
165 '0' => $lng->txt('inactive'));
166
167 break;
168 */
169 }
170
171 ++$counter;
172 }
174
175 return $fields ? $fields : array();
176 }
177
178 public static function _getPossibleFields($a_admin = false)
179 {
180 return array('gender',
181 'lastname',
182 'firstname',
183 'login',
184 'title',
185 'institution',
186 'department',
187 'street',
188 'zipcode',
189 'city',
190 'country',
191 'sel_country',
192 'email',
193 'second_email',
194 'hobby',
195 'org_units',
196 // begin-patch lok
197 'matriculation',
198 'interests_general',
199 'interests_help_offered',
200 'interests_help_looking'
201 );
202 // end-patch lok
203 }
204
205 public static function _isSearchable($a_key)
206 {
207 return in_array($a_key, ilUserSearchOptions::_getPossibleFields());
208 }
209
210 public static function _isEnabled($a_key)
211 {
212 global $ilias;
213
214 // login is always enabled
215 if ($a_key == 'login') {
216 return true;
217 }
218
219 return (bool) $ilias->getSetting('search_enabled_' . $a_key);
220 }
221
222 public static function _saveStatus($a_key, $a_enabled)
223 {
224 global $ilias;
225
226 $ilias->setSetting('search_enabled_' . $a_key, (int) $a_enabled);
227 return true;
228 }
229
230 public static function __appendUserDefinedFields($fields, $counter)
231 {
232 include_once './Services/User/classes/class.ilUserDefinedFields.php';
233
234 $user_defined_fields = ilUserDefinedFields::_getInstance();
235
236 foreach ($user_defined_fields->getSearchableDefinitions() as $definition) {
237 $fields[$counter]['values'] = ilUserSearchOptions::__prepareValues($definition['field_values']);
238 $fields[$counter]['lang'] = $definition['field_name'];
239 $fields[$counter]['db'] = $definition['field_id'];
240
241 switch ($definition['field_type']) {
242 case UDF_TYPE_TEXT:
243 $fields[$counter]['type'] = FIELD_TYPE_UDF_TEXT;
244 break;
245
246 case UDF_TYPE_SELECT:
247 $fields[$counter]['type'] = FIELD_TYPE_UDF_SELECT;
248 break;
249 }
250 ++$counter;
251 }
252 return $fields ? $fields : array();
253 }
254
255 public static function __prepareValues($a_values)
256 {
257 global $lng;
258
259 $new_values = array(0 => $lng->txt('please_choose'));
260 foreach ($a_values as $value) {
261 $new_values[$value] = $value;
262 }
263 return $new_values ? $new_values : array();
264 }
265}
if(!isset( $_REQUEST[ 'ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options
Definition: as_login.php:20
An exception for terminatinating execution or to throw for unit testing.
const UDF_TYPE_SELECT
const UDF_TYPE_TEXT
const FIELD_TYPE_TEXT
const FIELD_TYPE_MULTI
const FIELD_TYPE_SELECT
const FIELD_TYPE_UDF_SELECT
Class ilUserSearchOptions.
const FIELD_TYPE_UDF_TEXT
static getCountryCodes()
Get country codes (DIN EN 3166-1)
static getTextRepresentationOfOrgUnits($sort_by_title=true)
Get ref id path array.
static _getInstance()
Get instance.
static _getSearchableFieldsInfo($a_admin=false)
static __appendUserDefinedFields($fields, $counter)
static _getPossibleFields($a_admin=false)
static _saveStatus($a_key, $a_enabled)
static getSelectableColumnInfo($a_admin=false)
Get info of searchable fields for selectable columns in table gui.
$counter
global $lng
Definition: privfeed.php:17