ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 var $db = null;
47
48 public function ilUserSearchOptions()
49 {
50 }
51
57 public static function getSelectableColumnInfo($a_admin = false)
58 {
59 $col_info = array();
60 foreach(self::_getSearchableFieldsInfo($a_admin) as $field)
61 {
62 if(is_numeric($field['db']))
63 {
64 $field['db'] = 'udf_'.$field['db'];
65 }
66
67 $col_info[$field['db']] = array(
68 'txt' => $field['lang']
69 );
70
71 if($field['db'] == 'login' or $field['db'] == 'firstname' or $field['db'] == 'lastname')
72 {
73 $col_info[$field['db']]['default'] = true;
74 }
75 }
76 return $col_info;
77 }
78
79 public static function _getSearchableFieldsInfo($a_admin = false)
80 {
81 global $lng;
82
83 // begin-patch lok
84 $lng->loadLanguageModule('user');
85 // end-patch lok
86
87 $counter = 1;
88 foreach(ilUserSearchOptions::_getPossibleFields($a_admin) as $field)
89 {
90 // TODO: check enabled
91 // DONE
92 if($a_admin == false and !ilUserSearchOptions::_isEnabled($field))
93 {
94 continue;
95 }
96 $fields[$counter]['values'] = array();
97 $fields[$counter]['type'] = FIELD_TYPE_TEXT;
98 $fields[$counter]['lang'] = $lng->txt($field);
99 $fields[$counter]['db'] = $field;
100
104 $fields[$counter]['autoComplete'] = false;
105 switch($field)
106 {
107 case 'login':
108 case 'firstname':
109 case 'lastname':
110 case 'email':
111 $fields[$counter]['autoComplete'] = true;
112 break;
113
114 case 'title':
115 $fields[$counter]['lang'] = $lng->txt('person_title');
116 break;
117
118 // SELECTS
119
120 case 'gender':
121 $fields[$counter]['type'] = FIELD_TYPE_SELECT;
122 $fields[$counter]['values'] = array(0 => $lng->txt('please_choose'),
123 'f' => $lng->txt('gender_f'),
124 'm' => $lng->txt('gender_m'));
125 break;
126
127 case 'sel_country':
128 $fields[$counter]['type'] = FIELD_TYPE_SELECT;
129 $fields[$counter]['values'] = array(0 => $lng->txt('please_choose'));
130
131 // #7843 -- see ilCountrySelectInputGUI
132 $lng->loadLanguageModule('meta');
133 include_once('./Services/Utilities/classes/class.ilCountry.php');
134 foreach (ilCountry::getCountryCodes() as $c)
135 {
136 $fields[$counter]['values'][$c] = $lng->txt('meta_c_'.$c);
137 }
138 asort($fields[$counter]['values']);
139 break;
140
141 // begin-patch lok
142 case 'interests_general':
143 case 'interests_help_offered':
144 case 'interests_help_looking':
145 $fields[$counter]['type'] = FIELD_TYPE_MULTI;
146 break;
147 // end-patch lok
148
149
150
151
152 /*
153 case 'active':
154 $fields[$counter]['type'] = FIELD_TYPE_SELECT;
155 $fields[$counter]['values'] = array(-1 => $lng->txt('please_choose'),
156 '1' => $lng->txt('active'),
157 '0' => $lng->txt('inactive'));
158
159 break;
160 */
161 }
162
163 ++$counter;
164 }
165 $fields = ilUserSearchOptions::__appendUserDefinedFields($fields,$counter);
166
167 return $fields ? $fields : array();
168 }
169
170 public static function _getPossibleFields($a_admin = false)
171 {
172 return array('gender',
173 'lastname',
174 'firstname',
175 'login',
176 'title',
177 'institution',
178 'department',
179 'street',
180 'zipcode',
181 'city',
182 'country',
183 'sel_country',
184 'email',
185 'hobby',
186 // begin-patch lok
187 'matriculation',
188 'interests_general',
189 'interests_help_offered',
190 'interests_help_looking'
191 );
192 // end-patch lok
193
194 }
195
196 public static function _isSearchable($a_key)
197 {
198 return in_array($a_key,ilUserSearchOptions::_getPossibleFields());
199 }
200
201 public static function _isEnabled($a_key)
202 {
203 global $ilias;
204
205 // login is always enabled
206 if($a_key == 'login')
207 {
208 return true;
209 }
210
211 return (bool) $ilias->getSetting('search_enabled_'.$a_key);
212 }
213
214 public static function _saveStatus($a_key,$a_enabled)
215 {
216 global $ilias;
217
218 $ilias->setSetting('search_enabled_'.$a_key,(int) $a_enabled);
219 return true;
220 }
221
222 public static function __appendUserDefinedFields($fields,$counter)
223 {
224 include_once './Services/User/classes/class.ilUserDefinedFields.php';
225
226 $user_defined_fields = ilUserDefinedFields::_getInstance();
227
228 foreach($user_defined_fields->getSearchableDefinitions() as $definition)
229 {
230 $fields[$counter]['values'] = ilUserSearchOptions::__prepareValues($definition['field_values']);
231 $fields[$counter]['lang'] = $definition['field_name'];
232 $fields[$counter]['db'] = $definition['field_id'];
233
234 switch($definition['field_type'])
235 {
236 case UDF_TYPE_TEXT:
237 $fields[$counter]['type'] = FIELD_TYPE_UDF_TEXT;
238 break;
239
240 case UDF_TYPE_SELECT:
241 $fields[$counter]['type'] = FIELD_TYPE_UDF_SELECT;
242 break;
243 }
244 ++$counter;
245 }
246 return $fields ? $fields : array();
247 }
248
249 public static function __prepareValues($a_values)
250 {
251 global $lng;
252
253 $new_values = array(0 => $lng->txt('please_choose'));
254 foreach($a_values as $value)
255 {
256 $new_values[$value] = $value;
257 }
258 return $new_values ? $new_values : array();
259 }
260}
261?>
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 _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.
global $lng
Definition: privfeed.php:40