ILIAS  Release_4_1_x_branch Revision 61804
 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 
43  {
44  global $ilDB;
45 
46  $this->db =& $ilDB;
47  $this->__read();
48  }
49 
50  function _getSearchableFieldsInfo($a_admin = false)
51  {
52  global $lng;
53 
54 
55  $counter = 1;
56  foreach(ilUserSearchOptions::_getPossibleFields($a_admin) as $field)
57  {
58  // TODO: check enabled
59  // DONE
60  if($a_admin == false and !ilUserSearchOptions::_isEnabled($field))
61  {
62  continue;
63  }
64  $fields[$counter]['values'] = array();
65  $fields[$counter]['type'] = FIELD_TYPE_TEXT;
66  $fields[$counter]['lang'] = $this->lng->txt($field);
67  $fields[$counter]['db'] = $field;
68 
69  switch($field)
70  {
71  case 'title':
72  $fields[$counter]['lang'] = $lng->txt('person_title');
73  break;
74 
75  // SELECTS
76 
77  case 'gender':
78  $fields[$counter]['type'] = FIELD_TYPE_SELECT;
79  $fields[$counter]['values'] = array(0 => $lng->txt('please_choose'),
80  'f' => $lng->txt('gender_f'),
81  'm' => $lng->txt('gender_m'));
82  break;
83 
84  case 'sel_country':
85  $fields[$counter]['type'] = FIELD_TYPE_SELECT;
86  $fields[$counter]['values'] = array(0 => $lng->txt('please_choose'));
87 
88  // #7843 -- see ilCountrySelectInputGUI
89  $lng->loadLanguageModule('meta');
90  include_once('./Services/Utilities/classes/class.ilCountry.php');
91  foreach (ilCountry::getCountryCodes() as $c)
92  {
93  $fields[$counter]['values'][$c] = $lng->txt('meta_c_'.$c);
94  }
95  asort($fields[$counter]['values']);
96  break;
97 
98  /*
99  case 'active':
100  $fields[$counter]['type'] = FIELD_TYPE_SELECT;
101  $fields[$counter]['values'] = array(-1 => $lng->txt('please_choose'),
102  '1' => $lng->txt('active'),
103  '0' => $lng->txt('inactive'));
104 
105  break;
106  */
107  }
108 
109  ++$counter;
110  }
111  $fields = ilUserSearchOptions::__appendUserDefinedFields($fields,$counter);
112 
113  return $fields ? $fields : array();
114  }
115 
116  function _getPossibleFields($a_admin = false)
117  {
118  if ($a_admin === true)
119  {
120  return array(
121  // 'active',
122  'gender',
123  'login',
124  'lastname',
125  'firstname',
126  'title',
127  'institution',
128  'department',
129  'street',
130  'zipcode',
131  'city',
132  'country',
133  'sel_country',
134  'email',
135  'matriculation');
136  }
137 
138  return array('gender',
139  'login',
140  'lastname',
141  'firstname',
142  'title',
143  'institution',
144  'department',
145  'street',
146  'zipcode',
147  'city',
148  'country',
149  'sel_country',
150  'email',
151  'hobby',
152  'matriculation');
153  }
154 
155  function _isSearchable($a_key)
156  {
157  return in_array($a_key,ilUserSearchOptions::_getPossibleFields());
158  }
159 
160  function _isEnabled($a_key)
161  {
162  global $ilias;
163 
164  // login is always enabled
165  if($a_key == 'login')
166  {
167  return true;
168  }
169 
170  return (bool) $ilias->getSetting('search_enabled_'.$a_key);
171  }
172 
173  function _saveStatus($a_key,$a_enabled)
174  {
175  global $ilias;
176 
177  $ilias->setSetting('search_enabled_'.$a_key,(int) $a_enabled);
178  return true;
179  }
180 
181  function __appendUserDefinedFields($fields,$counter)
182  {
183  include_once './Services/User/classes/class.ilUserDefinedFields.php';
184 
185  $user_defined_fields =& ilUserDefinedFields::_getInstance();
186 
187  foreach($user_defined_fields->getSearchableDefinitions() as $definition)
188  {
189  $fields[$counter]['values'] = ilUserSearchOptions::__prepareValues($definition['field_values']);
190  $fields[$counter]['lang'] = $definition['field_name'];
191  $fields[$counter]['db'] = $definition['field_id'];
192 
193  switch($definition['field_type'])
194  {
195  case UDF_TYPE_TEXT:
196  $fields[$counter]['type'] = FIELD_TYPE_UDF_TEXT;
197  break;
198 
199  case UDF_TYPE_SELECT:
200  $fields[$counter]['type'] = FIELD_TYPE_UDF_SELECT;
201  break;
202  }
203  ++$counter;
204  }
205  return $fields ? $fields : array();
206  }
207 
208  function __prepareValues($a_values)
209  {
210  $new_values = array(0 => $this->lng->txt('please_choose'));
211  foreach($a_values as $value)
212  {
213  $new_values[$value] = $value;
214  }
215  return $new_values ? $new_values : array();
216  }
217 }
218 ?>