ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
39 {
40  var $db = null;
41 
42  public function ilUserSearchOptions()
43  {
44  }
45 
51  public static function getSelectableColumnInfo($a_admin = false)
52  {
53  $col_info = array();
54  foreach(self::_getSearchableFieldsInfo($a_admin) as $field)
55  {
56  if(is_numeric($field['db']))
57  {
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  {
67  $col_info[$field['db']]['default'] = true;
68  }
69  }
70  return $col_info;
71  }
72 
73  public static function _getSearchableFieldsInfo($a_admin = false)
74  {
75  global $lng;
76 
77 
78  $counter = 1;
79  foreach(ilUserSearchOptions::_getPossibleFields($a_admin) as $field)
80  {
81  // TODO: check enabled
82  // DONE
83  if($a_admin == false and !ilUserSearchOptions::_isEnabled($field))
84  {
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 
97  switch($field)
98  {
99  case 'login':
100  case 'firstname':
101  case 'lastname':
102  case 'email':
103  $fields[$counter]['autoComplete'] = true;
104  break;
105 
106  case 'title':
107  $fields[$counter]['lang'] = $lng->txt('person_title');
108  break;
109 
110  // SELECTS
111 
112  case 'gender':
113  $fields[$counter]['type'] = FIELD_TYPE_SELECT;
114  $fields[$counter]['values'] = array(0 => $lng->txt('please_choose'),
115  'f' => $lng->txt('gender_f'),
116  'm' => $lng->txt('gender_m'));
117  break;
118 
119  case 'sel_country':
120  $fields[$counter]['type'] = FIELD_TYPE_SELECT;
121  $fields[$counter]['values'] = array(0 => $lng->txt('please_choose'));
122 
123  // #7843 -- see ilCountrySelectInputGUI
124  $lng->loadLanguageModule('meta');
125  include_once('./Services/Utilities/classes/class.ilCountry.php');
126  foreach (ilCountry::getCountryCodes() as $c)
127  {
128  $fields[$counter]['values'][$c] = $lng->txt('meta_c_'.$c);
129  }
130  asort($fields[$counter]['values']);
131  break;
132 
133  /*
134  case 'active':
135  $fields[$counter]['type'] = FIELD_TYPE_SELECT;
136  $fields[$counter]['values'] = array(-1 => $lng->txt('please_choose'),
137  '1' => $lng->txt('active'),
138  '0' => $lng->txt('inactive'));
139 
140  break;
141  */
142  }
143 
144  ++$counter;
145  }
146  $fields = ilUserSearchOptions::__appendUserDefinedFields($fields,$counter);
147 
148  return $fields ? $fields : array();
149  }
150 
151  public static function _getPossibleFields($a_admin = false)
152  {
153  return array('gender',
154  'login',
155  'lastname',
156  'firstname',
157  'title',
158  'institution',
159  'department',
160  'street',
161  'zipcode',
162  'city',
163  'country',
164  'sel_country',
165  'email',
166  'hobby',
167  'matriculation');
168  }
169 
170  public static function _isSearchable($a_key)
171  {
172  return in_array($a_key,ilUserSearchOptions::_getPossibleFields());
173  }
174 
175  public static function _isEnabled($a_key)
176  {
177  global $ilias;
178 
179  // login is always enabled
180  if($a_key == 'login')
181  {
182  return true;
183  }
184 
185  return (bool) $ilias->getSetting('search_enabled_'.$a_key);
186  }
187 
188  public static function _saveStatus($a_key,$a_enabled)
189  {
190  global $ilias;
191 
192  $ilias->setSetting('search_enabled_'.$a_key,(int) $a_enabled);
193  return true;
194  }
195 
196  public static function __appendUserDefinedFields($fields,$counter)
197  {
198  include_once './Services/User/classes/class.ilUserDefinedFields.php';
199 
200  $user_defined_fields = ilUserDefinedFields::_getInstance();
201 
202  foreach($user_defined_fields->getSearchableDefinitions() as $definition)
203  {
204  $fields[$counter]['values'] = ilUserSearchOptions::__prepareValues($definition['field_values']);
205  $fields[$counter]['lang'] = $definition['field_name'];
206  $fields[$counter]['db'] = $definition['field_id'];
207 
208  switch($definition['field_type'])
209  {
210  case UDF_TYPE_TEXT:
211  $fields[$counter]['type'] = FIELD_TYPE_UDF_TEXT;
212  break;
213 
214  case UDF_TYPE_SELECT:
215  $fields[$counter]['type'] = FIELD_TYPE_UDF_SELECT;
216  break;
217  }
218  ++$counter;
219  }
220  return $fields ? $fields : array();
221  }
222 
223  public static function __prepareValues($a_values)
224  {
225  global $lng;
226 
227  $new_values = array(0 => $lng->txt('please_choose'));
228  foreach($a_values as $value)
229  {
230  $new_values[$value] = $value;
231  }
232  return $new_values ? $new_values : array();
233  }
234 }
235 ?>