ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilExportFieldsInfo.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 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
34{
35 private static $instance = null;
36
37 private $settings;
38 private $db;
39 private $lng;
40
41 private $obj_type = '';
42
43 private $possible_fields = array();
44
51 private function __construct($a_type)
52 {
53 global $ilDB,$ilSetting,$lng;
54
55 $this->db = $ilDB;
56 $this->lng = $lng;
57 $this->settings = $ilSetting;
58
59 $this->obj_type = $a_type;
60
61 $this->read();
62 }
63
70 public static function _getInstanceByType($a_type)
71 {
72 if(is_object(self::$instance[$a_type]))
73 {
74 return self::$instance[$a_type];
75 }
76 return self::$instance[$a_type] = new ilExportFieldsInfo($a_type);
77 }
78
83 public function getType()
84 {
85 return $this->obj_type;
86 }
87
96 public function isExportable($a_field_name)
97 {
98 return array_key_exists($a_field_name,$this->possible_fields);
99 }
100
107 public function getFieldsInfo()
108 {
110 }
111
117 public function getExportableFields()
118 {
119 foreach($this->possible_fields as $field => $exportable)
120 {
121 if($exportable)
122 {
123 $fields[] = $field;
124 }
125 }
126 return $fields ? $fields : array();
127 }
128
133 public function getSelectableFieldsInfo($a_obj_id)
134 {
135 global $lng;
136
137 $fields = array();
138 foreach($this->getExportableFields() as $field)
139 {
140 switch($field)
141 {
142 case 'lastname':
143 case 'firstname':
144 break;
145
146 case 'username':
147 $fields['login']['txt'] = $lng->txt('login');
148 $fields['login']['default'] = 1;
149 break;
150
151 default:
152 // #18795
153 $caption = ($field == "title")
154 ? "person_title"
155 : $field;
156 $fields[$field]['txt'] = $lng->txt($caption);
157 $fields[$field]['default'] = 0;
158 break;
159 }
160 }
161
162 include_once './Services/Booking/classes/class.ilBookingEntry.php';
163 if(ilBookingEntry::hasObjectBookingEntries($a_obj_id, $GLOBALS['ilUser']->getId()))
164 {
165 $GLOBALS['lng']->loadLanguageModule('dateplaner');
166 $fields['consultation_hour']['txt'] = $GLOBALS['lng']->txt('cal_ch_field_ch');
167 $fields['consultation_hour']['default'] = 0;
168 }
169
170 include_once './Services/User/classes/class.ilUserDefinedFields.php';
171 if($this->getType() == 'crs')
172 {
173 $udf = ilUserDefinedFields::_getInstance()->getCourseExportableFields();
174 }
175 elseif($this->getType() == 'grp')
176 {
177 $udf = ilUserDefinedFields::_getInstance()->getGroupExportableFields();
178 }
179 if($udf)
180 {
181 foreach($udf as $field_id => $field)
182 {
183 $fields['udf_'.$field_id]['txt'] = $field['field_name'];
184 $fields['udf_'.$field_id]['default'] = 0;
185 }
186 }
187
188 include_once './Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php';
190 foreach($cdf as $def)
191 {
192 $fields['odf_'.$def->getId()]['txt'] = $def->getName();
193 $fields['odf_'.$def->getId()]['default'] = 0;
194 }
195
196 if(count($cdf))
197 {
198 // add last edit
199 $fields['odf_last_update']['txt'] = $GLOBALS['lng']->txt($this->getType().'_cdf_tbl_last_edit');
200 $fields['odf_last_update']['default'] = 0;
201 }
202
203 return $fields;
204 }
205
213 {
214 $fields = array();
215 foreach($this->getExportableFields() as $field)
216 {
217 $fields[] = $this->lng->txt($field);
218 }
219 return implode('<br />',$fields);
220 }
221
228 private function read()
229 {
230 include_once './Services/User/classes/class.ilUserProfile.php';
231
232 $profile = new ilUserProfile();
233 $profile->skipGroup('settings');
234
235 foreach($profile->getStandardFields() as $key => $data)
236 {
237 if($this->getType() == 'crs')
238 {
239 if(!$data['course_export_hide'])
240 {
241 if(isset($data['course_export_fix_value']) and $data['course_export_fix_value'])
242 {
243 $this->possible_fields[$key] = $data['course_export_fix_value'];
244 }
245 else
246 {
247 $this->possible_fields[$key] = 0;
248 }
249 }
250 }
251 elseif($this->getType() == 'grp')
252 {
253 if(!$data['group_export_hide'])
254 {
255 if(isset($data['group_export_fix_value']) and $data['group_export_fix_value'])
256 {
257 $this->possible_fields[$key] = $data['group_export_fix_value'];
258 }
259 else
260 {
261 $this->possible_fields[$key] = 0;
262 }
263 }
264 }
265 }
266 $settings_all = $this->settings->getAll();
267
268 $field_part_limit = 5;
269 switch($this->getType())
270 {
271 case 'crs':
272 $field_prefix = 'usr_settings_course_export_';
273 $field_part_limit = 5;
274 break;
275
276 case 'grp':
277 $field_prefix = 'usr_settings_group_export_';
278 $field_part_limit = 5;
279 break;
280 }
281
282 foreach($settings_all as $key => $value)
283 {
284 if(stristr($key,$field_prefix) and $value)
285 {
286 // added limit for mantis 11096
287 $field_parts = explode('_',$key,$field_part_limit);
288 $field = $field_parts[count($field_parts) - 1];
289 if(array_key_exists($field,$this->possible_fields))
290 {
291 $this->possible_fields[$field] = 1;
292 }
293 }
294 }
295 return true;
296 }
297
301 public function sortExportFields()
302 {
303
304 $start_order = array("lastname" => array(), "firstname" => array(), "username" => array());
305
306 foreach($start_order as $key => $value)
307 {
308 if(isset($this->possible_fields[$key]))
309 {
310 $start_order[$key] = $this->possible_fields[$key];
311 unset($this->possible_fields[$key]);
312 }else
313 {
314 unset($start_order[$key]);
315 }
316 }
317
318 if(count($start_order) > 0)
319 {
320 $this->possible_fields = array_merge($start_order, $this->possible_fields);
321 }
322 }
323}
324?>
static hasObjectBookingEntries($a_obj_id, $a_usr_id)
Check if object has assigned consultation hour appointments.
static _getFields($a_container_id, $a_sort=IL_CDF_SORT_NAME)
Get all fields of a container.
getFieldsInfo()
Get informations (exportable) about user data profile fields.
__construct($a_type)
Private Singleton Constructor.
sortExportFields()
sort Exports fields User for Name Presentation Guideline
static _getInstanceByType($a_type)
Get Singleton Instance.
isExportable($a_field_name)
Check if field is exportable.
getExportableFields()
Get Exportable Fields.
read()
Read info about exportable fields.
exportableFieldsToInfoString()
Get exportable fields as info string.
getSelectableFieldsInfo($a_obj_id)
Get selectable fields.
static _getInstance()
Get instance.
Class ilUserProfile.
$data
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
global $ilSetting
Definition: privfeed.php:40
global $ilDB