ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  {
109  return $this->possible_fields;
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('username');
148  $fields['login']['default'] = 1;
149  break;
150  default:
151  $fields[$field]['txt'] = $lng->txt($field);
152  $fields[$field]['default'] = 0;
153  break;
154  }
155  }
156 
157  include_once './Services/User/classes/class.ilUserDefinedFields.php';
158  if($this->getType() == 'crs')
159  {
160  $udf = ilUserDefinedFields::_getInstance()->getCourseExportableFields();
161  }
162  elseif($this->getType() == 'grp')
163  {
164  $udf = ilUserDefinedFields::_getInstance()->getGroupExportableFields();
165  }
166  if($udf)
167  {
168  foreach($udf as $field_id => $field)
169  {
170  $fields['udf_'.$field_id]['txt'] = $field['field_name'];
171  $fields['udf_'.$field_id]['default'] = 0;
172  }
173  }
174 
175  include_once './Modules/Course/classes/Export/class.ilCourseDefinedFieldDefinition.php';
177  foreach($cdf as $def)
178  {
179  $fields['odf_'.$def->getId()]['txt'] = $def->getName();
180  $fields['odf_'.$def->getId()]['default'] = 0;
181  }
182 
183  return $fields;
184  }
185 
193  {
194  $fields = array();
195  foreach($this->getExportableFields() as $field)
196  {
197  $fields[] = $this->lng->txt($field);
198  }
199  return implode('<br />',$fields);
200  }
201 
208  private function read()
209  {
210  include_once './Services/User/classes/class.ilUserProfile.php';
211 
212  $profile = new ilUserProfile();
213  $profile->skipGroup('settings');
214 
215  foreach($profile->getStandardFields() as $key => $data)
216  {
217  if($this->getType() == 'crs')
218  {
219  if(!$data['course_export_hide'])
220  {
221  if(isset($data['course_export_fix_value']) and $data['course_export_fix_value'])
222  {
223  $this->possible_fields[$key] = $data['course_export_fix_value'];
224  }
225  else
226  {
227  $this->possible_fields[$key] = 0;
228  }
229  }
230  }
231  elseif($this->getType() == 'grp')
232  {
233  if(!$data['group_export_hide'])
234  {
235  if(isset($data['group_export_fix_value']) and $data['group_export_fix_value'])
236  {
237  $this->possible_fields[$key] = $data['group_export_fix_value'];
238  }
239  else
240  {
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  {
251  case 'crs':
252  $field_prefix = 'usr_settings_course_export_';
253  $field_part_limit = 5;
254  break;
255 
256  case 'grp':
257  $field_prefix = 'usr_settings_group_export_';
258  $field_part_limit = 5;
259  break;
260  }
261 
262  foreach($settings_all as $key => $value)
263  {
264  if(stristr($key,$field_prefix) and $value)
265  {
266  // added limit for mantis 11096
267  $field_parts = explode('_',$key,$field_part_limit);
268  $field = $field_parts[count($field_parts) - 1];
269  if(array_key_exists($field,$this->possible_fields))
270  {
271  $this->possible_fields[$field] = 1;
272  }
273  }
274  }
275  return true;
276  }
277 }
278 ?>