ILIAS  Release_4_2_x_branch Revision 61807
 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  switch($field)
97  {
98  case 'login':
99  case 'firstname':
100  case 'lastname':
101  case '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(0 => $lng->txt('please_choose'),
114  'f' => $lng->txt('gender_f'),
115  'm' => $lng->txt('gender_m'));
116  break;
117 
118  case 'sel_country':
119  $fields[$counter]['type'] = FIELD_TYPE_SELECT;
120  $fields[$counter]['values'] = array(0 => $lng->txt('please_choose'));
121 
122  // #7843 -- see ilCountrySelectInputGUI
123  $lng->loadLanguageModule('meta');
124  include_once('./Services/Utilities/classes/class.ilCountry.php');
125  foreach (ilCountry::getCountryCodes() as $c)
126  {
127  $fields[$counter]['values'][$c] = $lng->txt('meta_c_'.$c);
128  }
129  asort($fields[$counter]['values']);
130  break;
131 
132  /*
133  case 'active':
134  $fields[$counter]['type'] = FIELD_TYPE_SELECT;
135  $fields[$counter]['values'] = array(-1 => $lng->txt('please_choose'),
136  '1' => $lng->txt('active'),
137  '0' => $lng->txt('inactive'));
138 
139  break;
140  */
141  }
142 
143  ++$counter;
144  }
145  $fields = ilUserSearchOptions::__appendUserDefinedFields($fields,$counter);
146 
147  return $fields ? $fields : array();
148  }
149 
150  public static function _getPossibleFields($a_admin = false)
151  {
152  return array('gender',
153  'login',
154  'lastname',
155  'firstname',
156  'title',
157  'institution',
158  'department',
159  'street',
160  'zipcode',
161  'city',
162  'country',
163  'sel_country',
164  'email',
165  'hobby',
166  'matriculation');
167  }
168 
169  public static function _isSearchable($a_key)
170  {
171  return in_array($a_key,ilUserSearchOptions::_getPossibleFields());
172  }
173 
174  public static function _isEnabled($a_key)
175  {
176  global $ilias;
177 
178  // login is always enabled
179  if($a_key == 'login')
180  {
181  return true;
182  }
183 
184  return (bool) $ilias->getSetting('search_enabled_'.$a_key);
185  }
186 
187  public static function _saveStatus($a_key,$a_enabled)
188  {
189  global $ilias;
190 
191  $ilias->setSetting('search_enabled_'.$a_key,(int) $a_enabled);
192  return true;
193  }
194 
195  public static function __appendUserDefinedFields($fields,$counter)
196  {
197  include_once './Services/User/classes/class.ilUserDefinedFields.php';
198 
199  $user_defined_fields = ilUserDefinedFields::_getInstance();
200 
201  foreach($user_defined_fields->getSearchableDefinitions() as $definition)
202  {
203  $fields[$counter]['values'] = ilUserSearchOptions::__prepareValues($definition['field_values']);
204  $fields[$counter]['lang'] = $definition['field_name'];
205  $fields[$counter]['db'] = $definition['field_id'];
206 
207  switch($definition['field_type'])
208  {
209  case UDF_TYPE_TEXT:
210  $fields[$counter]['type'] = FIELD_TYPE_UDF_TEXT;
211  break;
212 
213  case UDF_TYPE_SELECT:
214  $fields[$counter]['type'] = FIELD_TYPE_UDF_SELECT;
215  break;
216  }
217  ++$counter;
218  }
219  return $fields ? $fields : array();
220  }
221 
222  public static function __prepareValues($a_values)
223  {
224  global $lng;
225 
226  $new_values = array(0 => $lng->txt('please_choose'));
227  foreach($a_values as $value)
228  {
229  $new_values[$value] = $value;
230  }
231  return $new_values ? $new_values : array();
232  }
233 }
234 ?>