ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilExportFieldsInfo.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
23 {
24  private static array $instances = [];
25 
27  private ilLanguage $lng;
28  private string $obj_type = '';
29  private array $possible_fields = array();
30 
35  private function __construct(string $a_type)
36  {
37  global $DIC;
38 
39  $this->lng = $DIC->language();
40  $this->settings = $DIC->settings();
41  $this->obj_type = $a_type;
42 
43  $this->read();
44  }
45 
49  public static function _getInstanceByType(string $a_type): ilExportFieldsInfo
50  {
51  if (!isset(self::$instances[$a_type])) {
52  self::$instances[$a_type] = new self($a_type);
53  }
54  return self::$instances[$a_type];
55  }
56 
57  public function getType(): string
58  {
59  return $this->obj_type;
60  }
61 
65  public function isExportable($a_field_name): bool
66  {
67  return array_key_exists($a_field_name, $this->possible_fields);
68  }
69 
74  public function getFieldsInfo(): array
75  {
77  }
78 
82  public function getExportableFields(): array
83  {
84  $fields = [];
85  foreach ($this->possible_fields as $field => $exportable) {
86  if ($exportable) {
87  $fields[] = $field;
88  }
89  }
90  return $fields;
91  }
92 
96  public function getSelectableFieldsInfo(int $a_obj_id): array
97  {
98  global $DIC;
99 
100  $user = $DIC->user();
101 
102  $fields = [];
103  foreach ($this->getExportableFields() as $field) {
104  switch ($field) {
105  case 'lastname':
106  case 'firstname':
107  break;
108 
109  case 'username':
110  $fields['login']['txt'] = $this->lng->txt('login');
111  $fields['login']['default'] = 1;
112  break;
113 
114  default:
115  // #18795
116  $caption = ($field == "title")
117  ? "person_title"
118  : $field;
119  $fields[$field]['txt'] = $this->lng->txt($caption);
120  $fields[$field]['default'] = 0;
121  break;
122  }
123  }
124 
125  if (ilBookingEntry::hasObjectBookingEntries($a_obj_id, $user->getId())) {
126  $this->lng->loadLanguageModule('dateplaner');
127  $fields['consultation_hour']['txt'] = $this->lng->txt('cal_ch_field_ch');
128  $fields['consultation_hour']['default'] = 0;
129  }
130 
131  $udf = [];
132  if ($this->getType() == 'crs') {
133  $udf = ilUserDefinedFields::_getInstance()->getCourseExportableFields();
134  } elseif ($this->getType() == 'grp') {
135  $udf = ilUserDefinedFields::_getInstance()->getGroupExportableFields();
136  }
137  if ($udf) {
138  foreach ($udf as $field_id => $field) {
139  $fields['udf_' . $field_id]['txt'] = $field['field_name'];
140  $fields['udf_' . $field_id]['default'] = 0;
141  }
142  }
143 
145  foreach ($cdf as $def) {
146  $fields['odf_' . $def->getId()]['txt'] = $def->getName();
147  $fields['odf_' . $def->getId()]['default'] = 0;
148  }
149 
150  if (count($cdf)) {
151  // add last edit
152  $fields['odf_last_update']['txt'] = $this->lng->txt($this->getType() . '_cdf_tbl_last_edit');
153  $fields['odf_last_update']['default'] = 0;
154  }
155  return $fields;
156  }
157 
162  public function exportableFieldsToInfoString(): string
163  {
164  $fields = [];
165  foreach ($this->getExportableFields() as $field) {
166  $fields[] = $this->lng->txt($field);
167  }
168  return implode('<br />', $fields);
169  }
170 
174  private function read(): void
175  {
176  $profile = new ilUserProfile();
177  $profile->skipGroup('settings');
178 
179  foreach ($profile->getStandardFields() as $key => $data) {
180  if ($this->getType() == 'crs') {
181  if (!array_key_exists('course_export_hide', $data) || !$data['course_export_hide']) {
182  if (isset($data['course_export_fix_value']) && $data['course_export_fix_value']) {
183  $this->possible_fields[$key] = $data['course_export_fix_value'];
184  } else {
185  $this->possible_fields[$key] = 0;
186  }
187  }
188  } elseif ($this->getType() == 'grp') {
189  if (!array_key_exists('group_export_hide', $data) || !$data['group_export_hide']) {
190  if (isset($data['group_export_fix_value']) and $data['group_export_fix_value']) {
191  $this->possible_fields[$key] = $data['group_export_fix_value'];
192  } else {
193  $this->possible_fields[$key] = 0;
194  }
195  }
196  }
197  }
198  $settings_all = $this->settings->getAll();
199 
200  $field_part_limit = 5;
201  $field_prefix = '';
202  switch ($this->getType()) {
203  case 'crs':
204  $field_prefix = 'usr_settings_course_export_';
205  $field_part_limit = 5;
206  break;
207 
208  case 'grp':
209  $field_prefix = 'usr_settings_group_export_';
210  $field_part_limit = 5;
211  break;
212  }
213 
214  foreach ($settings_all as $key => $value) {
215  if ($field_prefix && stristr($key, $field_prefix) and $value) {
216  // added limit for mantis 11096
217  $field_parts = explode('_', $key, $field_part_limit);
218  $field = $field_parts[count($field_parts) - 1];
219  if (array_key_exists($field, $this->possible_fields)) {
220  $this->possible_fields[$field] = 1;
221  }
222  }
223  }
224  }
225 
229  public function sortExportFields(): void
230  {
231  $start_order = array("lastname" => array(), "firstname" => array(), "username" => array());
232 
233  foreach ($start_order as $key => $value) {
234  if (isset($this->possible_fields[$key])) {
235  $start_order[$key] = $this->possible_fields[$key];
236  unset($this->possible_fields[$key]);
237  } else {
238  unset($start_order[$key]);
239  }
240  }
241 
242  if (count($start_order) > 0) {
243  $this->possible_fields = array_merge($start_order, $this->possible_fields);
244  }
245  }
246 }
static hasObjectBookingEntries(int $a_obj_id, int $a_usr_id)
Check if object has assigned consultation hour appointments.
Class ilUserProfile.
static _getFields(int $a_container_id, $a_sort=self::IL_CDF_SORT_NAME)
Get all fields of a container.
exportableFieldsToInfoString()
Get exportable fields as info string.
getFieldsInfo()
Get informations (exportable) about user data profile fields public.
global $DIC
Definition: feed.php:28
sortExportFields()
sort Exports fields User for Name Presentation Guideline
isExportable($a_field_name)
Check if field is exportable.
string $key
Consumer key/client ID value.
Definition: System.php:193
static _getInstanceByType(string $a_type)
Get Singleton Instance.
getExportableFields()
Get Exportable Fields.
__construct(string $a_type)
Private Singleton Constructor.
read()
Read info about exportable fields.
getSelectableFieldsInfo(int $a_obj_id)
Get selectable fields.