ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  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 $DIC;
75 
76  $lng = $DIC['lng'];
77 
78  // begin-patch lok
79  $lng->loadLanguageModule('user');
80  // end-patch lok
81 
82  $counter = 1;
83  foreach (ilUserSearchOptions::_getPossibleFields($a_admin) as $field) {
84  // TODO: check enabled
85  // DONE
86  if ($a_admin == false and !ilUserSearchOptions::_isEnabled($field)) {
87  continue;
88  }
89  $fields[$counter]['values'] = array();
90  $fields[$counter]['type'] = FIELD_TYPE_TEXT;
91  $fields[$counter]['lang'] = $lng->txt($field);
92  $fields[$counter]['db'] = $field;
93 
97  $fields[$counter]['autoComplete'] = false;
98  switch ($field) {
99  case 'login':
100  case 'firstname':
101  case 'lastname':
102  case 'email':
103  case 'second_email':
104  $fields[$counter]['autoComplete'] = true;
105  break;
106 
107  case 'title':
108  $fields[$counter]['lang'] = $lng->txt('person_title');
109  break;
110 
111  // SELECTS
112 
113  case 'gender':
114  $fields[$counter]['type'] = FIELD_TYPE_SELECT;
115  $fields[$counter]['values'] = array(
116  0 => $lng->txt('please_choose'),
117  'n' => $lng->txt('gender_n'),
118  'f' => $lng->txt('gender_f'),
119  'm' => $lng->txt('gender_m'),
120  );
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  $fields[$counter]['values'][$c] = $lng->txt('meta_c_' . $c);
132  }
133  asort($fields[$counter]['values']);
134  break;
135 
136  case 'org_units':
137  $fields[$counter]['type'] = FIELD_TYPE_SELECT;
138 
139  include_once './Modules/OrgUnit/classes/PathStorage/class.ilOrgUnitPathStorage.php';
141 
142  $options[0] = $lng->txt('select_one');
143  foreach ($paths as $org_ref_id => $path) {
144  $options[$org_ref_id] = $path;
145  }
146 
147  $fields[$counter]['values'] = $options;
148  break;
149 
150 
151  // begin-patch lok
152  case 'interests_general':
153  case 'interests_help_offered':
154  case 'interests_help_looking':
155  $fields[$counter]['type'] = FIELD_TYPE_MULTI;
156  break;
157  // end-patch lok
158 
159 
160 
161 
162  /*
163  case 'active':
164  $fields[$counter]['type'] = FIELD_TYPE_SELECT;
165  $fields[$counter]['values'] = array(-1 => $lng->txt('please_choose'),
166  '1' => $lng->txt('active'),
167  '0' => $lng->txt('inactive'));
168 
169  break;
170  */
171  }
172 
173  ++$counter;
174  }
175  $fields = ilUserSearchOptions::__appendUserDefinedFields($fields, $counter);
176 
177  return $fields ? $fields : array();
178  }
179 
180  public static function _getPossibleFields($a_admin = false)
181  {
182  return array('gender',
183  'lastname',
184  'firstname',
185  'login',
186  'title',
187  'institution',
188  'department',
189  'street',
190  'zipcode',
191  'city',
192  'country',
193  'sel_country',
194  'email',
195  'second_email',
196  'hobby',
197  'org_units',
198  // begin-patch lok
199  'matriculation',
200  'interests_general',
201  'interests_help_offered',
202  'interests_help_looking'
203  );
204  // end-patch lok
205  }
206 
207  public static function _isSearchable($a_key)
208  {
209  return in_array($a_key, ilUserSearchOptions::_getPossibleFields());
210  }
211 
212  public static function _isEnabled($a_key)
213  {
214  global $DIC;
215 
216  $ilias = $DIC['ilias'];
217 
218  // login is always enabled
219  if ($a_key == 'login') {
220  return true;
221  }
222 
223  return (bool) $ilias->getSetting('search_enabled_' . $a_key);
224  }
225 
226  public static function _saveStatus($a_key, $a_enabled)
227  {
228  global $DIC;
229 
230  $ilias = $DIC['ilias'];
231 
232  $ilias->setSetting('search_enabled_' . $a_key, (int) $a_enabled);
233  return true;
234  }
235 
236  public static function __appendUserDefinedFields($fields, $counter)
237  {
238  include_once './Services/User/classes/class.ilUserDefinedFields.php';
239 
240  $user_defined_fields = ilUserDefinedFields::_getInstance();
241 
242  foreach ($user_defined_fields->getSearchableDefinitions() as $definition) {
243  $fields[$counter]['values'] = ilUserSearchOptions::__prepareValues($definition['field_values']);
244  $fields[$counter]['lang'] = $definition['field_name'];
245  $fields[$counter]['db'] = $definition['field_id'];
246 
247  switch ($definition['field_type']) {
248  case UDF_TYPE_TEXT:
249  $fields[$counter]['type'] = FIELD_TYPE_UDF_TEXT;
250  break;
251 
252  case UDF_TYPE_SELECT:
253  $fields[$counter]['type'] = FIELD_TYPE_UDF_SELECT;
254  break;
255  }
256  ++$counter;
257  }
258  return $fields ? $fields : array();
259  }
260 
261  public static function __prepareValues($a_values)
262  {
263  global $DIC;
264 
265  $lng = $DIC['lng'];
266 
267  $new_values = array(0 => $lng->txt('please_choose'));
268  foreach ($a_values as $value) {
269  $new_values[$value] = $value;
270  }
271  return $new_values ? $new_values : array();
272  }
273 }
const UDF_TYPE_SELECT
$path
Definition: aliased.php:25
static _getInstance()
Get instance.
if($argc< 2) $paths
Definition: migrateto20.php:44
global $DIC
Definition: saml.php:7
const FIELD_TYPE_MULTI
const FIELD_TYPE_UDF_TEXT
const FIELD_TYPE_SELECT
static _saveStatus($a_key, $a_enabled)
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.
$lng
const UDF_TYPE_TEXT
const FIELD_TYPE_UDF_SELECT
Class ilUserSearchOptions.
static _getPossibleFields($a_admin=false)
static getCountryCodes()
Get country codes (DIN EN 3166-1)
const FIELD_TYPE_TEXT
static __appendUserDefinedFields($fields, $counter)
static _getSearchableFieldsInfo($a_admin=false)