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