ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
33 define('FIELD_TYPE_UDF_SELECT',1);
34 define('FIELD_TYPE_UDF_TEXT',2);
35 define('FIELD_TYPE_SELECT',3);
36 define('FIELD_TYPE_TEXT',4);
37 // begin-patch lok
38 define('FIELD_TYPE_MULTI',5);
39 // end-patch lok
40 
41 
42 
43 
45 {
46  var $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  {
58  if(is_numeric($field['db']))
59  {
60  $field['db'] = 'udf_'.$field['db'];
61  }
62 
63  $col_info[$field['db']] = array(
64  'txt' => $field['lang']
65  );
66 
67  if($field['db'] == 'login' or $field['db'] == 'firstname' or $field['db'] == 'lastname')
68  {
69  $col_info[$field['db']]['default'] = true;
70  }
71  }
72  return $col_info;
73  }
74 
75  public static function _getSearchableFieldsInfo($a_admin = false)
76  {
77  global $lng;
78 
79  // begin-patch lok
80  $lng->loadLanguageModule('user');
81  // end-patch lok
82 
83  $counter = 1;
84  foreach(ilUserSearchOptions::_getPossibleFields($a_admin) as $field)
85  {
86  // TODO: check enabled
87  // DONE
88  if($a_admin == false and !ilUserSearchOptions::_isEnabled($field))
89  {
90  continue;
91  }
92  $fields[$counter]['values'] = array();
93  $fields[$counter]['type'] = FIELD_TYPE_TEXT;
94  $fields[$counter]['lang'] = $lng->txt($field);
95  $fields[$counter]['db'] = $field;
96 
100  $fields[$counter]['autoComplete'] = false;
101  switch($field)
102  {
103  case 'login':
104  case 'firstname':
105  case 'lastname':
106  case 'email':
107  $fields[$counter]['autoComplete'] = true;
108  break;
109 
110  case 'title':
111  $fields[$counter]['lang'] = $lng->txt('person_title');
112  break;
113 
114  // SELECTS
115 
116  case 'gender':
117  $fields[$counter]['type'] = FIELD_TYPE_SELECT;
118  $fields[$counter]['values'] = array(0 => $lng->txt('please_choose'),
119  'f' => $lng->txt('gender_f'),
120  'm' => $lng->txt('gender_m'));
121  break;
122 
123  case 'sel_country':
124  $fields[$counter]['type'] = FIELD_TYPE_SELECT;
125  $fields[$counter]['values'] = array(0 => $lng->txt('please_choose'));
126 
127  // #7843 -- see ilCountrySelectInputGUI
128  $lng->loadLanguageModule('meta');
129  include_once('./Services/Utilities/classes/class.ilCountry.php');
130  foreach (ilCountry::getCountryCodes() as $c)
131  {
132  $fields[$counter]['values'][$c] = $lng->txt('meta_c_'.$c);
133  }
134  asort($fields[$counter]['values']);
135  break;
136 
137  case 'org_units':
138  $fields[$counter]['type'] = FIELD_TYPE_SELECT;
139 
140  include_once './Modules/OrgUnit/classes/class.ilObjOrgUnit.php';
142  include_once './Modules/OrgUnit/classes/class.ilObjOrgUnitTree.php';
144  $nodes = $tree->getAllChildren($root);
145 
146  include_once './Modules/OrgUnit/classes/PathStorage/class.ilOrgUnitPathStorage.php';
148 
149  $options[0] = $lng->txt('select_one');
150  foreach($paths as $org_ref_id => $path)
151  {
152  $options[$org_ref_id] = $path;
153  }
154 
155  $fields[$counter]['values'] = $options;
156  break;
157 
158 
159  // begin-patch lok
160  case 'interests_general':
161  case 'interests_help_offered':
162  case 'interests_help_looking':
163  $fields[$counter]['type'] = FIELD_TYPE_MULTI;
164  break;
165  // end-patch lok
166 
167 
168 
169 
170  /*
171  case 'active':
172  $fields[$counter]['type'] = FIELD_TYPE_SELECT;
173  $fields[$counter]['values'] = array(-1 => $lng->txt('please_choose'),
174  '1' => $lng->txt('active'),
175  '0' => $lng->txt('inactive'));
176 
177  break;
178  */
179  }
180 
181  ++$counter;
182  }
184 
185  return $fields ? $fields : array();
186  }
187 
188  public static function _getPossibleFields($a_admin = false)
189  {
190  return array('gender',
191  'lastname',
192  'firstname',
193  'login',
194  'title',
195  'institution',
196  'department',
197  'street',
198  'zipcode',
199  'city',
200  'country',
201  'sel_country',
202  'email',
203  'hobby',
204  'org_units',
205  // begin-patch lok
206  'matriculation',
207  'interests_general',
208  'interests_help_offered',
209  'interests_help_looking'
210  );
211  // end-patch lok
212 
213  }
214 
215  public static function _isSearchable($a_key)
216  {
217  return in_array($a_key,ilUserSearchOptions::_getPossibleFields());
218  }
219 
220  public static function _isEnabled($a_key)
221  {
222  global $ilias;
223 
224  // login is always enabled
225  if($a_key == 'login')
226  {
227  return true;
228  }
229 
230  return (bool) $ilias->getSetting('search_enabled_'.$a_key);
231  }
232 
233  public static function _saveStatus($a_key,$a_enabled)
234  {
235  global $ilias;
236 
237  $ilias->setSetting('search_enabled_'.$a_key,(int) $a_enabled);
238  return true;
239  }
240 
241  public static function __appendUserDefinedFields($fields,$counter)
242  {
243  include_once './Services/User/classes/class.ilUserDefinedFields.php';
244 
245  $user_defined_fields = ilUserDefinedFields::_getInstance();
246 
247  foreach($user_defined_fields->getSearchableDefinitions() as $definition)
248  {
249  $fields[$counter]['values'] = ilUserSearchOptions::__prepareValues($definition['field_values']);
250  $fields[$counter]['lang'] = $definition['field_name'];
251  $fields[$counter]['db'] = $definition['field_id'];
252 
253  switch($definition['field_type'])
254  {
255  case UDF_TYPE_TEXT:
256  $fields[$counter]['type'] = FIELD_TYPE_UDF_TEXT;
257  break;
258 
259  case UDF_TYPE_SELECT:
260  $fields[$counter]['type'] = FIELD_TYPE_UDF_SELECT;
261  break;
262  }
263  ++$counter;
264  }
265  return $fields ? $fields : array();
266  }
267 
268  public static function __prepareValues($a_values)
269  {
270  global $lng;
271 
272  $new_values = array(0 => $lng->txt('please_choose'));
273  foreach($a_values as $value)
274  {
275  $new_values[$value] = $value;
276  }
277  return $new_values ? $new_values : array();
278  }
279 }
280 ?>
const UDF_TYPE_SELECT
$path
Definition: aliased.php:25
static _getInstance()
Get instance.
const FIELD_TYPE_MULTI
const FIELD_TYPE_UDF_TEXT
const FIELD_TYPE_SELECT
$counter
static _saveStatus($a_key, $a_enabled)
if(!is_array($argv)) $options
static getTextRepresentationOfOrgUnits($sort_by_title=true)
Get ref id path array.
static getSelectableColumnInfo($a_admin=false)
Get info of searchable fields for selectable columns in table gui.
const UDF_TYPE_TEXT
const FIELD_TYPE_UDF_SELECT
Class ilUserSearchOptions.
Create styles array
The data for the language used.
static _getPossibleFields($a_admin=false)
static getRootOrgRefId()
global $lng
Definition: privfeed.php:17
static getCountryCodes()
Get country codes (DIN EN 3166-1)
const FIELD_TYPE_TEXT
static __appendUserDefinedFields($fields, $counter)
static _getSearchableFieldsInfo($a_admin=false)