ILIAS  Release_4_0_x_branch Revision 61816
 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 
70  if($field == 'gender')
71  {
72  $fields[$counter]['values'] = array(0 => $lng->txt('please_choose'),
73  'f' => $lng->txt('gender_f'),
74  'm' => $lng->txt('gender_m'));
75  $fields[$counter]['type'] = FIELD_TYPE_SELECT;
76  }
77  if($field == 'title')
78  {
79  $fields[$counter]['lang'] = $lng->txt('person_title');
80  }
81  /*if($field == 'active')
82  {
83  $fields[$counter]['values'] = array(-1 => $lng->txt('please_choose'),
84  '1' => $lng->txt('active'),
85  '0' => $lng->txt('inactive'));
86  $fields[$counter]['type'] = FIELD_TYPE_SELECT;
87  }*/
88  ++$counter;
89  }
90  $fields = ilUserSearchOptions::__appendUserDefinedFields($fields,$counter);
91 
92  return $fields ? $fields : array();
93  }
94 
95  function _getPossibleFields($a_admin = false)
96  {
97  if ($a_admin === true)
98  {
99  return array(
100  // 'active',
101  'gender',
102  'login',
103  'lastname',
104  'firstname',
105  'title',
106  'institution',
107  'department',
108  'street',
109  'zipcode',
110  'city',
111  'country',
112  'email',
113  'matriculation');
114  }
115 
116  return array('gender',
117  'login',
118  'lastname',
119  'firstname',
120  'title',
121  'institution',
122  'department',
123  'street',
124  'zipcode',
125  'city',
126  'country',
127  'email',
128  'hobby',
129  'matriculation');
130  }
131 
132  function _isSearchable($a_key)
133  {
134  return in_array($a_key,ilUserSearchOptions::_getPossibleFields());
135  }
136 
137  function _isEnabled($a_key)
138  {
139  global $ilias;
140 
141  // login is always enabled
142  if($a_key == 'login')
143  {
144  return true;
145  }
146 
147  return (bool) $ilias->getSetting('search_enabled_'.$a_key);
148  }
149 
150  function _saveStatus($a_key,$a_enabled)
151  {
152  global $ilias;
153 
154  $ilias->setSetting('search_enabled_'.$a_key,(int) $a_enabled);
155  return true;
156  }
157 
158  function __appendUserDefinedFields($fields,$counter)
159  {
160  include_once './Services/User/classes/class.ilUserDefinedFields.php';
161 
162  $user_defined_fields =& ilUserDefinedFields::_getInstance();
163 
164  foreach($user_defined_fields->getSearchableDefinitions() as $definition)
165  {
166  $fields[$counter]['values'] = ilUserSearchOptions::__prepareValues($definition['field_values']);
167  $fields[$counter]['lang'] = $definition['field_name'];
168  $fields[$counter]['db'] = $definition['field_id'];
169 
170  switch($definition['field_type'])
171  {
172  case UDF_TYPE_TEXT:
173  $fields[$counter]['type'] = FIELD_TYPE_UDF_TEXT;
174  break;
175 
176  case UDF_TYPE_SELECT:
177  $fields[$counter]['type'] = FIELD_TYPE_UDF_SELECT;
178  break;
179  }
180  ++$counter;
181  }
182  return $fields ? $fields : array();
183  }
184 
185  function __prepareValues($a_values)
186  {
187  $new_values = array(0 => $this->lng->txt('please_choose'));
188  foreach($a_values as $value)
189  {
190  $new_values[$value] = $value;
191  }
192  return $new_values ? $new_values : array();
193  }
194 }
195 ?>