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