Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00033 define('FIELD_TYPE_UDF_SELECT',1);
00034 define('FIELD_TYPE_UDF_TEXT',2);
00035 define('FIELD_TYPE_SELECT',3);
00036 define('FIELD_TYPE_TEXT',4);
00037
00038 class ilUserSearchOptions
00039 {
00040 var $db = null;
00041
00042 function ilUserSearchOptions()
00043 {
00044 global $ilDB;
00045
00046 $this->db =& $ilDB;
00047 $this->__read();
00048 }
00049
00050 function _getSearchableFieldsInfo($a_admin = false)
00051 {
00052 global $lng;
00053
00054
00055
00056 #$fields[0]['values'] = array();
00057 #$fields[0]['type'] = FIELD_TYPE_TEXT;
00058 #$fields[0]['lang'] = $this->lng->txt('login');
00059 #$fields[0]['db'] = 'login';
00060
00061
00062 $counter = 1;
00063 foreach(ilUserSearchOptions::_getPossibleFields($a_admin) as $field)
00064 {
00065
00066
00067 if($a_admin == false and !ilUserSearchOptions::_isEnabled($field))
00068 {
00069 continue;
00070 }
00071 $fields[$counter]['values'] = array();
00072 $fields[$counter]['type'] = FIELD_TYPE_TEXT;
00073 $fields[$counter]['lang'] = $this->lng->txt($field);
00074 $fields[$counter]['db'] = $field;
00075
00076
00077 if($field == 'gender')
00078 {
00079 $fields[$counter]['values'] = array(0 => $lng->txt('please_choose'),
00080 'f' => $lng->txt('gender_f'),
00081 'm' => $lng->txt('gender_m'));
00082 $fields[$counter]['type'] = FIELD_TYPE_SELECT;
00083 }
00084 if($field == 'title')
00085 {
00086 $fields[$counter]['lang'] = $lng->txt('person_title');
00087 }
00088
00089
00090
00091
00092
00093
00094
00095 ++$counter;
00096 }
00097
00098
00099 $fields = ilUserSearchOptions::__appendUserDefinedFields($fields,$counter);
00100
00101 return $fields ? $fields : array();
00102 }
00103
00104 function _getPossibleFields($a_admin = false)
00105 {
00106 if ($a_admin === true)
00107 {
00108 return array(
00109
00110 'gender',
00111 'login',
00112 'lastname',
00113 'firstname',
00114 'title',
00115 'institution',
00116 'department',
00117 'street',
00118 'zipcode',
00119 'city',
00120 'country',
00121 'email',
00122 'matriculation');
00123 }
00124
00125 return array('gender',
00126 'login',
00127 'lastname',
00128 'firstname',
00129 'title',
00130 'institution',
00131 'department',
00132 'street',
00133 'zipcode',
00134 'city',
00135 'country',
00136 'email',
00137 'hobby',
00138 'matriculation');
00139 }
00140
00141 function _isSearchable($a_key)
00142 {
00143 return in_array($a_key,ilUserSearchOptions::_getPossibleFields());
00144 }
00145
00146 function _isEnabled($a_key)
00147 {
00148 global $ilias;
00149
00150
00151 if($a_key == 'login')
00152 {
00153 return true;
00154 }
00155
00156 return (bool) $ilias->getSetting('search_enabled_'.$a_key);
00157 }
00158
00159 function _saveStatus($a_key,$a_enabled)
00160 {
00161 global $ilias;
00162
00163 $ilias->setSetting('search_enabled_'.$a_key,(int) $a_enabled);
00164 return true;
00165 }
00166
00167 function __appendUserDefinedFields($fields,$counter)
00168 {
00169 include_once './Services/User/classes/class.ilUserDefinedFields.php';
00170
00171 $user_defined_fields =& ilUserDefinedFields::_getInstance();
00172
00173 foreach($user_defined_fields->getSearchableDefinitions() as $definition)
00174 {
00175 $fields[$counter]['values'] = ilUserSearchOptions::__prepareValues($definition['field_values']);
00176 $fields[$counter]['lang'] = $definition['field_name'];
00177 $fields[$counter]['db'] = $definition['field_id'];
00178
00179 switch($definition['field_type'])
00180 {
00181 case UDF_TYPE_TEXT:
00182 $fields[$counter]['type'] = FIELD_TYPE_UDF_TEXT;
00183 break;
00184
00185 case UDF_TYPE_SELECT:
00186 $fields[$counter]['type'] = FIELD_TYPE_UDF_SELECT;
00187 break;
00188 }
00189 ++$counter;
00190 }
00191 return $fields ? $fields : array();
00192 }
00193
00194 function __prepareValues($a_values)
00195 {
00196 $new_values = array(0 => $this->lng->txt('please_choose'));
00197 foreach($a_values as $value)
00198 {
00199 $new_values[$value] = $value;
00200 }
00201 return $new_values ? $new_values : array();
00202 }
00203 }
00204 ?>