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