ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilCourseXMLWriter.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=0);
20
31{
32 public const int MODE_SOAP = 1;
33 public const int MODE_EXPORT = 2;
34
35 public const string EXPORT_VERSION = '8.0';
36
37 private int $mode = self::MODE_SOAP;
38
39 private string $xml = '';
41 private bool $attach_users = true;
42
45
47 {
48 global $DIC;
49
50 $this->setting = $DIC->settings();
51 $this->access = $DIC->access();
52
54 $this->course_obj = $course_obj;
55 }
56
57 public function setMode(int $a_mode): void
58 {
59 $this->mode = $a_mode;
60 }
61
62 public function getMode(): int
63 {
64 return $this->mode;
65 }
66
67 public function start(): void
68 {
69 if ($this->getMode() == self::MODE_SOAP) {
70 $this->__buildHeader();
71 $this->__buildCourseStart();
74 if ($this->attach_users) {
75 $this->__buildAdmin();
76 $this->__buildTutor();
77 $this->__buildMember();
78 }
79 $this->__buildSubscriber();
80 $this->__buildWaitingList();
81
82 $this->__buildSetting();
83 ilContainerSortingSettings::_exportContainerSortingSettings($this, $this->course_obj->getId());
84 ilContainer::_exportContainerSettings($this, $this->course_obj->getId());
85 $this->__buildFooter();
86 } elseif ($this->getMode() == self::MODE_EXPORT) {
87 $this->__buildCourseStart();
88 $this->__buildSetting();
89 ilContainerSortingSettings::_exportContainerSortingSettings($this, $this->course_obj->getId());
90 ilContainer::_exportContainerSettings($this, $this->course_obj->getId());
91 $this->__buildFooter();
92 }
93 }
94
95 public function getXML(): string
96 {
97 return $this->xmlDumpMem(true);
98 }
99
100 public function modifyExportIdentifier($a_tag, $a_param, $a_value)
101 {
102 if ($a_tag == "Identifier" && $a_param == "Entry") {
103 $a_value = "il_" . $this->setting->get('inst_id') . "_crs_" . $this->course_obj->getId();
104 }
105
106 return $a_value;
107 }
108
109 // PRIVATE
110 public function __buildHeader(): void
111 {
112 $this->xmlSetGenCmt("Export of ILIAS course " . $this->course_obj->getId() . " of installation " . $this->setting->get('inst_id') . ".");
113 $this->xmlHeader();
114 }
115
116 public function __buildTitleDescription(): void
117 {
118 $this->xmlElement('Title', null, $this->course_obj->getTitle());
119
120 if ($desc = $this->course_obj->getDescription()) {
121 $this->xmlElement('Description', null, $desc);
122 }
123 }
124
125 public function __buildCourseStart(): void
126 {
127 $attrs["exportVersion"] = self::EXPORT_VERSION;
128 $attrs["id"] = "il_" . $this->setting->get('inst_id') . '_crs_' . $this->course_obj->getId();
129 $attrs['showMembers'] = ($this->course_obj->getShowMembers() ? 'Yes' : 'No');
130 $this->xmlStartTag("Course", $attrs);
131 }
132
133 private function __buildAdvancedMetaData(): void
134 {
135 ilAdvancedMDValues::_appendXMLByObjId($this, $this->course_obj->getId());
136 }
137
138 public function __buildAdmin(): void
139 {
140 $admins = $this->course_obj->getMembersObject()->getAdmins();
141 $admins = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
142 'manage_members',
144 $this->course_obj->getRefId(),
145 $admins
146 );
147
148 foreach ($admins as $id) {
149 $attr['id'] = 'il_' . $this->setting->get('inst_id') . '_usr_' . $id;
150 $attr['notification'] = ($this->course_obj->getMembersObject()->isNotificationEnabled($id)) ? 'Yes' : 'No';
151 $attr['passed'] = $this->course_obj->getMembersObject()->hasPassed($id) ? 'Yes' : 'No';
152 $attr['contact'] = $this->course_obj->getMembersObject()->isContact($id) ? 'Yes' : 'No';
153
154 $this->xmlStartTag('Admin', $attr);
155 $this->xmlEndTag('Admin');
156 }
157 }
158
159 public function __buildTutor(): void
160 {
161 $tutors = $this->course_obj->getMembersObject()->getTutors();
162 $tutors = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
163 'manage_members',
165 $this->course_obj->getRefId(),
166 $tutors
167 );
168 foreach ($tutors as $id) {
169 $attr['id'] = 'il_' . $this->setting->get('inst_id') . '_usr_' . $id;
170 $attr['notification'] = ($this->course_obj->getMembersObject()->isNotificationEnabled($id)) ? 'Yes' : 'No';
171 $attr['passed'] = $this->course_obj->getMembersObject()->hasPassed($id) ? 'Yes' : 'No';
172 $attr['contact'] = $this->course_obj->getMembersObject()->isContact($id) ? 'Yes' : 'No';
173
174 $this->xmlStartTag('Tutor', $attr);
175 $this->xmlEndTag('Tutor');
176 }
177 }
178
179 public function __buildMember(): void
180 {
181 $members = $this->course_obj->getMembersObject()->getMembers();
182 $members = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
183 'manage_members',
185 $this->course_obj->getRefId(),
186 $members
187 );
188 foreach ($members as $id) {
189 $attr['id'] = 'il_' . $this->setting->get('inst_id') . '_usr_' . $id;
190 $attr['blocked'] = ($this->course_obj->getMembersObject()->isBlocked($id)) ? 'Yes' : 'No';
191 $attr['passed'] = $this->course_obj->getMembersObject()->hasPassed($id) ? 'Yes' : 'No';
192
193 $this->xmlStartTag('Member', $attr);
194 $this->xmlEndTag('Member');
195 }
196 }
197
198 public function __buildSubscriber(): void
199 {
200 $subs = $this->course_obj->getMembersObject()->getSubscribers();
201 $subs = $this->access->filterUserIdsByRbacOrPositionOfCurrentUser(
202 'manage_members',
204 $this->course_obj->getRefId(),
205 $subs
206 );
207
208 foreach ($subs as $id) {
209 $data = $this->course_obj->getMembersObject()->getSubscriberData($id);
210
211 $attr['id'] = 'il_' . $this->setting->get('inst_id') . '_usr_' . $id;
212 $attr['subscriptionTime'] = $data['time'];
213
214 $this->xmlStartTag('Subscriber', $attr);
215 $this->xmlEndTag('Subscriber');
216 }
217 }
218
219 public function __buildWaitingList(): void
220 {
221 $waiting_list = new ilCourseWaitingList($this->course_obj->getId());
222 $wait = $waiting_list->getAllUsers();
223 foreach ($wait as $data) {
224 $is_accessible = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
225 'manage_members',
227 $this->course_obj->getRefId(),
228 [$data['usr_id']]
229 );
230 if (count($is_accessible) === 0) {
231 continue;
232 }
233
234 $attr['id'] = 'il_' . $this->setting->get('inst_id') . '_usr_' . $data['usr_id'];
235 $attr['position'] = $data['position'];
236 $attr['subscriptionTime'] = $data['time'];
237
238 $this->xmlStartTag('WaitingList', $attr);
239 $this->xmlEndTag('WaitingList');
240 }
241 }
242
243 public function __buildSetting(): void
244 {
245 $this->xmlStartTag('Settings');
246
247 // Availability
248 $this->xmlStartTag('Availability');
249 if ($this->course_obj->getOfflineStatus()) {
250 $this->xmlElement('NotAvailable');
251 } elseif ($this->course_obj->getActivationUnlimitedStatus()) {
252 $this->xmlElement('Unlimited');
253 } else {
254 $this->xmlStartTag('TemporarilyAvailable');
255 $this->xmlElement('Start', null, $this->course_obj->getActivationStart());
256 $this->xmlElement('End', null, $this->course_obj->getActivationEnd());
257 $this->xmlEndTag('TemporarilyAvailable');
258 }
259 $this->xmlEndTag('Availability');
260
261 // Syllabus
262 $this->xmlElement('Syllabus', null, $this->course_obj->getSyllabus());
263 $this->xmlElement('ImportantInformation', null, $this->course_obj->getImportantInformation());
264 $this->xmlElement('TargetGroup', null, $this->course_obj->getTargetGroup());
265
266 // Contact
267 $this->xmlStartTag('Contact');
268 $this->xmlElement('Name', null, $this->course_obj->getContactName());
269 $this->xmlElement('Responsibility', null, $this->course_obj->getContactResponsibility());
270 $this->xmlElement('Phone', null, $this->course_obj->getContactPhone());
271 $this->xmlElement('Email', null, $this->course_obj->getContactEmail());
272 $this->xmlElement('Consultation', null, $this->course_obj->getContactConsultation());
273 $this->xmlEndTag('Contact');
274
275 // Registration
276 $attr = array();
277
278 if ($this->course_obj->getSubscriptionType() == ilCourseConstants::IL_CRS_SUBSCRIPTION_CONFIRMATION) {
279 $attr['registrationType'] = 'Confirmation';
280 } elseif ($this->course_obj->getSubscriptionType() == ilCourseConstants::IL_CRS_SUBSCRIPTION_DIRECT) {
281 $attr['registrationType'] = 'Direct';
282 } else {
283 $attr['registrationType'] = 'Password';
284 }
285
286 $attr['maxMembers'] = $this->course_obj->isSubscriptionMembershipLimited() ?
287 $this->course_obj->getSubscriptionMaxMembers() : 0;
288 $attr['notification'] = $this->course_obj->getSubscriptionNotify() ? 'Yes' : 'No';
289 $attr['waitingList'] = $this->course_obj->enabledWaitingList() ? 'Yes' : 'No';
290
291 $this->xmlStartTag('Registration', $attr);
292
293 if ($this->course_obj->getSubscriptionLimitationType() == ilCourseConstants::IL_CRS_SUBSCRIPTION_DEACTIVATED) {
294 $this->xmlElement('Disabled');
295 } elseif ($this->course_obj->getSubscriptionLimitationType() == ilCourseConstants::IL_CRS_SUBSCRIPTION_UNLIMITED) {
296 $this->xmlElement('Unlimited');
297 } else {
298 $this->xmlStartTag('TemporarilyAvailable');
299 $this->xmlElement('Start', null, $this->course_obj->getSubscriptionStart());
300 $this->xmlElement('End', null, $this->course_obj->getSubscriptionEnd());
301 $this->xmlEndTag('TemporarilyAvailable');
302 }
303 if (strlen($pwd = $this->course_obj->getSubscriptionPassword())) {
304 $this->xmlElement('Password', null, $pwd);
305 }
306 $this->xmlEndTag('Registration');
307
308 $this->xmlStartTag('Period', ['withTime' => $this->course_obj->getCourseStartTimeIndication() ? 1 : 0]);
309 $this->xmlElement(
310 'Start',
311 null,
312 $this->course_obj->getCourseStart()
313 ? $this->course_obj->getCourseStart()->get(IL_CAL_UNIX)
314 : null
315 );
316 $this->xmlElement(
317 'End',
318 null,
319 $this->course_obj->getCourseEnd()
320 ? $this->course_obj->getCourseEnd()->get(IL_CAL_UNIX)
321 : null
322 );
323 $this->xmlEndTag('Period');
324 $this->xmlElement('WaitingListAutoFill', null, (int) $this->course_obj->hasWaitingListAutoFill());
325 $this->xmlElement(
326 'CancellationEnd',
327 null,
328 ($this->course_obj->getCancellationEnd() && !$this->course_obj->getCancellationEnd()->isNull()) ? $this->course_obj->getCancellationEnd()->get(IL_CAL_UNIX) : null
329 );
330 $this->xmlElement('MinMembers', null, $this->course_obj->getSubscriptionMinMembers());
331
332 $this->xmlElement('ViewMode', null, $this->course_obj->getViewMode());
333 if ($this->course_obj->getViewMode() == ilCourseConstants::IL_CRS_VIEW_TIMING) {
334 $this->xmlElement('TimingMode', null, $this->course_obj->getTimingMode());
335 }
336
337 $this->xmlElement('TutorialSupportBlock', [
338 'active' => $this->course_obj->getTutorialSupportBlockSettingValue()
339 ]);
340
341 $this->xmlElement(
342 'SessionLimit',
343 [
344 'active' => $this->course_obj->isSessionLimitEnabled() ? 1 : 0,
345 'previous' => $this->course_obj->getNumberOfPreviousSessions(),
346 'next' => $this->course_obj->getNumberOfNextSessions()
347 ]
348 );
349
350 $this->xmlElement(
351 'WelcomeMail',
352 [
353 'status' => $this->course_obj->getAutoNotification() ? 1 : 0
354 ]
355 );
356
357 $this->xmlElement('StatusDetermination', null, (int) $this->course_obj->getStatusDetermination());
358 $this->xmlElement('MailToMembersType', null, (int) $this->course_obj->getMailToMembersType());
359 $this->xmlElement('CourseMap', [
360 'enabled' => (int) $this->course_obj->getEnableCourseMap(),
361 'latitude' => $this->course_obj->getLatitude(),
362 'longitude' => $this->course_obj->getLongitude(),
363 'location_zoom' => $this->course_obj->getLocationZoom()
364 ]);
365
366 $this->xmlEndTag('Settings');
367 }
368
369 public function __buildFooter(): void
370 {
371 $this->xmlEndTag('Course');
372 }
373
374 public function setAttachUsers($value): void
375 {
376 $this->attach_users = (bool) $value;
377 }
378}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
const IL_CAL_UNIX
static _appendXMLByObjId(ilXmlWriter $a_xml_writer, int $a_obj_id)
Get xml of object values.
static _exportContainerSortingSettings(ilXmlWriter $xml, int $obj_id)
sorting XML-export for all container objects
static _exportContainerSettings(ilXmlWriter $a_xml, int $a_obj_id)
XML writer class Class to simplify manual writing of xml documents.
modifyExportIdentifier($a_tag, $a_param, $a_value)
__construct(ilObjCourse $course_obj)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ILIAS Setting Class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlSetGenCmt(string $genCmt)
Sets generated comment.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlHeader()
Writes xml header.
xmlEndTag(string $tag)
Writes an endtag.
xmlDumpMem(bool $format=true)
Returns xml document from memory.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$GLOBALS["DIC"]
Definition: wac.php:54