ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExportFieldsInfo.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23use ILIAS\User\Profile\Fields\Field as ProfileField;
24
31{
32 private static array $instances = [];
33
37 private string $obj_type = '';
38 private array $possible_fields = array();
39
44 private function __construct(string $a_type)
45 {
46 global $DIC;
47
48 $this->lng = $DIC->language();
49 $this->settings = $DIC->settings();
50 $this->profile = $DIC['user']->getProfile();
51 $this->obj_type = $a_type;
52
53 $this->read();
54 }
55
59 public static function _getInstanceByType(string $a_type): ilExportFieldsInfo
60 {
61 if (!isset(self::$instances[$a_type])) {
62 self::$instances[$a_type] = new self($a_type);
63 }
64 return self::$instances[$a_type];
65 }
66
67 public function getType(): string
68 {
69 return $this->obj_type;
70 }
71
75 public function isExportable($a_field_name): bool
76 {
77 return array_key_exists($a_field_name, $this->possible_fields);
78 }
79
84 public function getFieldsInfo(): array
85 {
87 }
88
92 public function getExportableFields(): array
93 {
94 $fields = [];
95 foreach ($this->possible_fields as $field => $exportable) {
96 if ($exportable) {
97 $fields[] = $field;
98 }
99 }
100 return $fields;
101 }
102
106 public function getSelectableFieldsInfo(?int $a_obj_id = null): array
107 {
108 global $DIC;
109
110 $user = $DIC->user();
111 $profile = $DIC['user']->getProfile();
112
113 $fields = [];
114 foreach ($this->getExportableFields() as $field) {
115 switch ($field) {
116 case 'lastname':
117 case 'firstname':
118 break;
119
120 case 'username':
121 $fields['login']['txt'] = $this->lng->txt('login');
122 $fields['login']['default'] = 1;
123 break;
124
125 default:
126 // #18795
127 $caption = ($field == "title")
128 ? "person_title"
129 : $field;
130 $fields[$field]['txt'] = $this->lng->txt($caption);
131 $fields[$field]['default'] = 0;
132 break;
133 }
134 }
135
136 if ($a_obj_id && ilBookingEntry::hasObjectBookingEntries($a_obj_id, $user->getId())) {
137 $this->lng->loadLanguageModule('dateplaner');
138 $fields['consultation_hour']['txt'] = $this->lng->txt('cal_ch_field_ch');
139 $fields['consultation_hour']['default'] = 0;
140 }
141
142 $udf = $profile->getVisibleUserDefinedFields(Context::buildFromObjectType($this->getType()));
143 if ($udf !== []) {
144 foreach ($udf as $field_id => $field) {
145 $fields['udf_' . $field_id]['txt'] = $field->getLabel($this->lng);
146 $fields['udf_' . $field_id]['default'] = 0;
147 }
148 }
149
150 if ($a_obj_id) {
152 foreach ($cdf as $def) {
153 $fields['odf_' . $def->getId()]['txt'] = $def->getName();
154 $fields['odf_' . $def->getId()]['default'] = 0;
155 }
156 if (count($cdf)) {
157 // add last edit
158 $fields['odf_last_update']['txt'] = $this->lng->txt($this->getType() . '_cdf_tbl_last_edit');
159 $fields['odf_last_update']['default'] = 0;
160 }
161 }
162 return $fields;
163 }
164
169 public function exportableFieldsToInfoString(): string
170 {
171 $fields = [];
172 foreach ($this->getExportableFields() as $field) {
173 $fields[] = $this->lng->txt($field);
174 }
175 return implode('<br />', $fields);
176 }
177
181 private function read(): void
182 {
183 $type = $this->getType();
184 $this->possible_fields = array_reduce(
185 $this->profile->getFields(),
186 function (array $c, ProfileField $v) use ($type): array {
187 if ($v->isCustom()) {
188 return $c;
189 }
190 if ($type === 'crs') {
191 $c[$v->getIdentifier()] = $v->isVisibleInCourses();
192 }
193
194 if ($type === 'grp') {
195 $c[$v->getIdentifier()] = $v->isVisibleInGroups();
196 }
197
198 if ($type === 'prg') {
199 $c[$v->getIdentifier()] = $v->isVisibleInStudyProgrammes();
200 }
201
202 return $c;
203 },
205 );
206 }
207
211 public function sortExportFields(): void
212 {
213 $start_order = ['lastname' => [], 'firstname' => [], 'username' => []];
214
215 foreach (array_keys($start_order) as $key) {
216 if (isset($this->possible_fields[$key])) {
217 $start_order[$key] = $this->possible_fields[$key];
218 unset($this->possible_fields[$key]);
219 } else {
220 unset($start_order[$key]);
221 }
222 }
223
224 if (count($start_order) > 0) {
225 $this->possible_fields = array_merge($start_order, $this->possible_fields);
226 }
227 }
228}
static hasObjectBookingEntries(int $a_obj_id, int $a_usr_id)
Check if object has assigned consultation hour appointments.
static _getFields(int $a_container_id, $a_sort=self::IL_CDF_SORT_NAME)
Get all fields of a container.
getFieldsInfo()
Get informations (exportable) about user data profile fields @access public.
sortExportFields()
sort Exports fields User for Name Presentation Guideline
static _getInstanceByType(string $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.
__construct(string $a_type)
Private Singleton Constructor.
getSelectableFieldsInfo(?int $a_obj_id=null)
Get selectable fields.
language handling
ILIAS Setting Class.
$c
Definition: deliver.php:25
getVisibleUserDefinedFields(Context $context)
if(!file_exists('../ilias.ini.php'))
global $DIC
Definition: shib_login.php:26