ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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 $DIC;
54
55 $ilDB = $DIC['ilDB'];
56 $ilSetting = $DIC['ilSetting'];
57 $lng = $DIC['lng'];
58
59 $this->db = $ilDB;
60 $this->lng = $lng;
61 $this->settings = $ilSetting;
62
63 $this->obj_type = $a_type;
64
65 $this->read();
66 }
67
74 public static function _getInstanceByType($a_type)
75 {
76 if (is_object(self::$instance[$a_type])) {
77 return self::$instance[$a_type];
78 }
79 return self::$instance[$a_type] = new ilExportFieldsInfo($a_type);
80 }
81
86 public function getType()
87 {
88 return $this->obj_type;
89 }
90
99 public function isExportable($a_field_name)
100 {
101 return array_key_exists($a_field_name, $this->possible_fields);
102 }
103
110 public function getFieldsInfo()
111 {
113 }
114
120 public function getExportableFields()
121 {
122 foreach ($this->possible_fields as $field => $exportable) {
123 if ($exportable) {
124 $fields[] = $field;
125 }
126 }
127 return $fields ? $fields : array();
128 }
129
134 public function getSelectableFieldsInfo($a_obj_id)
135 {
136 global $DIC;
137
138 $lng = $DIC['lng'];
139
140 $fields = array();
141 foreach ($this->getExportableFields() as $field) {
142 switch ($field) {
143 case 'lastname':
144 case 'firstname':
145 break;
146
147 case 'username':
148 $fields['login']['txt'] = $lng->txt('login');
149 $fields['login']['default'] = 1;
150 break;
151
152 default:
153 // #18795
154 $caption = ($field == "title")
155 ? "person_title"
156 : $field;
157 $fields[$field]['txt'] = $lng->txt($caption);
158 $fields[$field]['default'] = 0;
159 break;
160 }
161 }
162
163 include_once './Services/Booking/classes/class.ilBookingEntry.php';
164 if (ilBookingEntry::hasObjectBookingEntries($a_obj_id, $GLOBALS['DIC']['ilUser']->getId())) {
165 $GLOBALS['DIC']['lng']->loadLanguageModule('dateplaner');
166 $fields['consultation_hour']['txt'] = $GLOBALS['DIC']['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 $udf = ilUserDefinedFields::_getInstance()->getCourseExportableFields();
173 } elseif ($this->getType() == 'grp') {
174 $udf = ilUserDefinedFields::_getInstance()->getGroupExportableFields();
175 }
176 if ($udf) {
177 foreach ($udf as $field_id => $field) {
178 $fields['udf_' . $field_id]['txt'] = $field['field_name'];
179 $fields['udf_' . $field_id]['default'] = 0;
180 }
181 }
182
183 include_once './Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php';
185 foreach ($cdf as $def) {
186 $fields['odf_' . $def->getId()]['txt'] = $def->getName();
187 $fields['odf_' . $def->getId()]['default'] = 0;
188 }
189
190 if (count($cdf)) {
191 // add last edit
192 $fields['odf_last_update']['txt'] = $GLOBALS['DIC']['lng']->txt($this->getType() . '_cdf_tbl_last_edit');
193 $fields['odf_last_update']['default'] = 0;
194 }
195
196 return $fields;
197 }
198
206 {
207 $fields = array();
208 foreach ($this->getExportableFields() as $field) {
209 $fields[] = $this->lng->txt($field);
210 }
211 return implode('<br />', $fields);
212 }
213
220 private function read()
221 {
222 include_once './Services/User/classes/class.ilUserProfile.php';
223
224 $profile = new ilUserProfile();
225 $profile->skipGroup('settings');
226
227 foreach ($profile->getStandardFields() as $key => $data) {
228 if ($this->getType() == 'crs') {
229 if (!$data['course_export_hide']) {
230 if (isset($data['course_export_fix_value']) and $data['course_export_fix_value']) {
231 $this->possible_fields[$key] = $data['course_export_fix_value'];
232 } else {
233 $this->possible_fields[$key] = 0;
234 }
235 }
236 } elseif ($this->getType() == 'grp') {
237 if (!$data['group_export_hide']) {
238 if (isset($data['group_export_fix_value']) and $data['group_export_fix_value']) {
239 $this->possible_fields[$key] = $data['group_export_fix_value'];
240 } else {
241 $this->possible_fields[$key] = 0;
242 }
243 }
244 }
245 }
246 $settings_all = $this->settings->getAll();
247
248 $field_part_limit = 5;
249 switch ($this->getType()) {
250 case 'crs':
251 $field_prefix = 'usr_settings_course_export_';
252 $field_part_limit = 5;
253 break;
254
255 case 'grp':
256 $field_prefix = 'usr_settings_group_export_';
257 $field_part_limit = 5;
258 break;
259 }
260
261 foreach ($settings_all as $key => $value) {
262 if ($field_prefix && stristr($key, $field_prefix) and $value) {
263 // added limit for mantis 11096
264 $field_parts = explode('_', $key, $field_part_limit);
265 $field = $field_parts[count($field_parts) - 1];
266 if (array_key_exists($field, $this->possible_fields)) {
267 $this->possible_fields[$field] = 1;
268 }
269 }
270 }
271 return true;
272 }
273
277 public function sortExportFields()
278 {
279 $start_order = array("lastname" => array(), "firstname" => array(), "username" => array());
280
281 foreach ($start_order as $key => $value) {
282 if (isset($this->possible_fields[$key])) {
283 $start_order[$key] = $this->possible_fields[$key];
284 unset($this->possible_fields[$key]);
285 } else {
286 unset($start_order[$key]);
287 }
288 }
289
290 if (count($start_order) > 0) {
291 $this->possible_fields = array_merge($start_order, $this->possible_fields);
292 }
293 }
294}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
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.
global $ilSetting
Definition: privfeed.php:17
settings()
Definition: settings.php:2
global $ilDB
$data
Definition: storeScorm.php:23
$a_type
Definition: workflow.php:92
$DIC
Definition: xapitoken.php:46