ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilCourseXMLWriter.php
Go to the documentation of this file.
1<?php
2
3/*
4 +-----------------------------------------------------------------------------+
5 | ILIAS open source |
6 +-----------------------------------------------------------------------------+
7 | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
8 | |
9 | This program is free software; you can redistribute it and/or |
10 | modify it under the terms of the GNU General Public License |
11 | as published by the Free Software Foundation; either version 2 |
12 | of the License, or (at your option) any later version. |
13 | |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17 | GNU General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU General Public License |
20 | along with this program; if not, write to the Free Software |
21 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22 +-----------------------------------------------------------------------------+
23*/
24
25include_once "./Services/Xml/classes/class.ilXmlWriter.php";
26
40{
41 const MODE_SOAP = 1;
42 const MODE_EXPORT = 2;
43
45
46
47 private $ilias;
48
52 private $xml;
53
57 private $course_obj;
58
59 private $attach_users = true;
60
61
69 public function __construct($course_obj)
70 {
71 global $DIC;
72
73 $ilias = $DIC['ilias'];
74
76
77 $this->EXPORT_VERSION = "2";
78
79 $this->ilias = $ilias;
80 $this->course_obj = $course_obj;
81 }
82
83 public function setMode($a_mode)
84 {
85 $this->mode = $a_mode;
86 }
87
88 public function getMode()
89 {
90 return $this->mode;
91 }
92
93 public function start()
94 {
95 if ($this->getMode() == self::MODE_SOAP) {
96 $this->__buildHeader();
97 $this->__buildCourseStart();
98 $this->__buildMetaData();
100 if ($this->attach_users) {
101 $this->__buildAdmin();
102 $this->__buildTutor();
103 $this->__buildMember();
104 }
105 $this->__buildSubscriber();
106 $this->__buildWaitingList();
107
108 $this->__buildSetting();
109 include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
110 ilContainerSortingSettings::_exportContainerSortingSettings($this, $this->course_obj->getId());
111 ilContainer::_exportContainerSettings($this, $this->course_obj->getId());
112 $this->__buildFooter();
113 } elseif ($this->getMode() == self::MODE_EXPORT) {
114 $this->__buildCourseStart();
115 $this->__buildMetaData();
117 $this->__buildSetting();
118 include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
119 ilContainerSortingSettings::_exportContainerSortingSettings($this, $this->course_obj->getId());
120 ilContainer::_exportContainerSettings($this, $this->course_obj->getId());
121 $this->__buildFooter();
122 }
123 }
124
125 public function getXML()
126 {
127 #var_dump("<pre>", htmlentities($this->xmlDumpMem()),"<pre>");
128 return $this->xmlDumpMem(true);
129 }
130
131 // Called from nested class
132 public function modifyExportIdentifier($a_tag, $a_param, $a_value)
133 {
134 if ($a_tag == "Identifier" && $a_param == "Entry") {
135 $a_value = "il_" . $this->ilias->getSetting('inst_id') . "_crs_" . $this->course_obj->getId();
136 }
137
138 return $a_value;
139 }
140
141 // PRIVATE
142 public function __buildHeader()
143 {
144 $this->xmlSetDtdDef("<!DOCTYPE Course PUBLIC \"-//ILIAS//DTD Course//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_crs_5_0.dtd\">");
145 $this->xmlSetGenCmt("Export of ILIAS course " . $this->course_obj->getId() . " of installation " . $this->ilias->getSetting('inst_id') . ".");
146 $this->xmlHeader();
147
148
149 return true;
150 }
151
152 public function __buildCourseStart()
153 {
154 $attrs["exportVersion"] = $this->EXPORT_VERSION;
155 $attrs["id"] = "il_" . $this->ilias->getSetting('inst_id') . '_crs_' . $this->course_obj->getId();
156 $attrs['showMembers'] = ($this->course_obj->getShowMembers() ? 'Yes' : 'No');
157 $this->xmlStartTag("Course", $attrs);
158 }
159
160 public function __buildMetaData()
161 {
162 include_once 'Services/MetaData/classes/class.ilMD2XML.php';
163
164 $md2xml = new ilMD2XML($this->course_obj->getId(), $this->course_obj->getId(), 'crs');
165 $md2xml->startExport();
166 $this->appendXML($md2xml->getXML());
167
168 return true;
169 }
170
177 private function __buildAdvancedMetaData()
178 {
179 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
180 ilAdvancedMDValues::_appendXMLByObjId($this, $this->course_obj->getId());
181 }
182
183 public function __buildAdmin()
184 {
185 $admins = $this->course_obj->getMembersObject()->getAdmins();
186 $admins = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
187 'manage_members',
189 $this->course_obj->getRefId(),
190 $admins
191 );
192
193 foreach ($admins as $id) {
194 $attr['id'] = 'il_' . $this->ilias->getSetting('inst_id') . '_usr_' . $id;
195 $attr['notification'] = ($this->course_obj->getMembersObject()->isNotificationEnabled($id)) ? 'Yes' : 'No';
196 $attr['passed'] = $this->course_obj->getMembersObject()->hasPassed($id) ? 'Yes' : 'No';
197 $attr['contact'] = $this->course_obj->getMembersObject()->isContact($id) ? 'Yes' : 'No';
198
199 $this->xmlStartTag('Admin', $attr);
200 $this->xmlEndTag('Admin');
201 }
202 return true;
203 }
204
205 public function __buildTutor()
206 {
207 $tutors = $this->course_obj->getMembersObject()->getTutors();
208 $tutors = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
209 'manage_members',
211 $this->course_obj->getRefId(),
212 $tutors
213 );
214 foreach ($tutors as $id) {
215 $attr['id'] = 'il_' . $this->ilias->getSetting('inst_id') . '_usr_' . $id;
216 $attr['notification'] = ($this->course_obj->getMembersObject()->isNotificationEnabled($id)) ? 'Yes' : 'No';
217 $attr['passed'] = $this->course_obj->getMembersObject()->hasPassed($id) ? 'Yes' : 'No';
218 $attr['contact'] = $this->course_obj->getMembersObject()->isContact($id) ? 'Yes' : 'No';
219
220 $this->xmlStartTag('Tutor', $attr);
221 $this->xmlEndTag('Tutor');
222 }
223 return true;
224 }
225 public function __buildMember()
226 {
227 $members = $this->course_obj->getMembersObject()->getMembers();
228 $members = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
229 'manage_members',
231 $this->course_obj->getRefId(),
232 $members
233 );
234 foreach ($members as $id) {
235 $attr['id'] = 'il_' . $this->ilias->getSetting('inst_id') . '_usr_' . $id;
236 $attr['blocked'] = ($this->course_obj->getMembersObject()->isBlocked($id)) ? 'Yes' : 'No';
237 $attr['passed'] = $this->course_obj->getMembersObject()->hasPassed($id) ? 'Yes' : 'No';
238
239 $this->xmlStartTag('Member', $attr);
240 $this->xmlEndTag('Member');
241 }
242 return true;
243 }
244
245 public function __buildSubscriber()
246 {
247 $subs = $this->course_obj->getMembersObject()->getSubscribers();
248 $subs = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
249 'manage_members',
251 $this->course_obj->getRefId(),
252 $subs
253 );
254
255 foreach ($subs as $id) {
256 $data = $this->course_obj->getMembersObject()->getSubscriberData($id);
257
258 $attr['id'] = 'il_' . $this->ilias->getSetting('inst_id') . '_usr_' . $id;
259 $attr['subscriptionTime'] = $data['time'];
260
261 $this->xmlStartTag('Subscriber', $attr);
262 $this->xmlEndTag('Subscriber');
263 }
264 return true;
265 }
266
267 public function __buildWaitingList()
268 {
269 include_once 'Modules/Course/classes/class.ilCourseWaitingList.php';
270 $waiting_list = new ilCourseWaitingList($this->course_obj->getId());
271
272 $wait = $waiting_list->getAllUsers();
273
274 foreach ($wait as $data) {
275 $is_accessible = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
276 'manage_members',
278 $this->course_obj->getRefId(),
279 [$data['usr_id']]
280 );
281 if (!count($is_accessible)) {
282 continue;
283 }
284
285 $attr['id'] = 'il_' . $this->ilias->getSetting('inst_id') . '_usr_' . $data['usr_id'];
286 $attr['position'] = $data['position'];
287 $attr['subscriptionTime'] = $data['time'];
288
289 $this->xmlStartTag('WaitingList', $attr);
290 $this->xmlEndTag('WaitingList');
291 }
292 return true;
293 }
294
295
299 public function __buildSetting()
300 {
301 $this->xmlStartTag('Settings');
302
303 // Availability
304 $this->xmlStartTag('Availability');
305 if ($this->course_obj->getOfflineStatus()) {
306 $this->xmlElement('NotAvailable');
307 } elseif ($this->course_obj->getActivationUnlimitedStatus()) {
308 $this->xmlElement('Unlimited');
309 } else {
310 $this->xmlStartTag('TemporarilyAvailable');
311 $this->xmlElement('Start', null, $this->course_obj->getActivationStart());
312 $this->xmlElement('End', null, $this->course_obj->getActivationEnd());
313 $this->xmlEndTag('TemporarilyAvailable');
314 }
315 $this->xmlEndTag('Availability');
316
317 // Syllabus
318 $this->xmlElement('Syllabus', null, $this->course_obj->getSyllabus());
319 $this->xmlElement('ImportantInformation', null, $this->course_obj->getImportantInformation());
320 $this->xmlElement('TargetGroup', null, $this->course_obj->getTargetGroup());
321
322
323 // Contact
324 $this->xmlStartTag('Contact');
325 $this->xmlElement('Name', null, $this->course_obj->getContactName());
326 $this->xmlElement('Responsibility', null, $this->course_obj->getContactResponsibility());
327 $this->xmlElement('Phone', null, $this->course_obj->getContactPhone());
328 $this->xmlElement('Email', null, $this->course_obj->getContactEmail());
329 $this->xmlElement('Consultation', null, $this->course_obj->getContactConsultation());
330 $this->xmlEndTag('Contact');
331
332 // Registration
333 $attr = array();
334
335 if ($this->course_obj->getSubscriptionType() == IL_CRS_SUBSCRIPTION_CONFIRMATION) {
336 $attr['registrationType'] = 'Confirmation';
337 } elseif ($this->course_obj->getSubscriptionType() == IL_CRS_SUBSCRIPTION_DIRECT) {
338 $attr['registrationType'] = 'Direct';
339 } else {
340 $attr['registrationType'] = 'Password';
341 }
342
343 $attr['maxMembers'] = $this->course_obj->isSubscriptionMembershipLimited() ?
344 $this->course_obj->getSubscriptionMaxMembers() : 0;
345 $attr['notification'] = $this->course_obj->getSubscriptionNotify() ? 'Yes' : 'No';
346 $attr['waitingList'] = $this->course_obj->enabledWaitingList() ? 'Yes' : 'No';
347
348 $this->xmlStartTag('Registration', $attr);
349
350 if ($this->course_obj->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED) {
351 $this->xmlElement('Disabled');
352 } elseif ($this->course_obj->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_UNLIMITED) {
353 $this->xmlElement('Unlimited');
354 } else {
355 $this->xmlStartTag('TemporarilyAvailable');
356 $this->xmlElement('Start', null, $this->course_obj->getSubscriptionStart());
357 $this->xmlElement('End', null, $this->course_obj->getSubscriptionEnd());
358 $this->xmlEndTag('TemporarilyAvailable');
359 }
360 if (strlen($pwd = $this->course_obj->getSubscriptionPassword())) {
361 $this->xmlElement('Password', null, $pwd);
362 }
363 $this->xmlEndTag('Registration');
364
365
366 $this->xmlStartTag('Period', ['withTime' => $this->course_obj->getCourseStartTimeIndication() ? 1 : 0]);
367 $this->xmlElement(
368 'Start',
369 null,
370 $this->course_obj->getCourseStart()
371 ? $this->course_obj->getCourseStart()->get(IL_CAL_UNIX)
372 : null
373 );
374 $this->xmlElement(
375 'End',
376 null,
377 $this->course_obj->getCourseEnd()
378 ? $this->course_obj->getCourseEnd()->get(IL_CAL_UNIX)
379 : null
380 );
381 $this->xmlEndTag('Period');
382 $this->xmlElement('WaitingListAutoFill', null, (int) $this->course_obj->hasWaitingListAutoFill());
383 $this->xmlElement('CancellationEnd', null, ($this->course_obj->getCancellationEnd() && !$this->course_obj->getCancellationEnd()->isNull()) ? $this->course_obj->getCancellationEnd()->get(IL_CAL_UNIX) : null);
384 $this->xmlElement('MinMembers', null, (int) $this->course_obj->getSubscriptionMinMembers());
385
386 $this->xmlElement('ViewMode', null, $this->course_obj->getViewMode());
387 if ($this->course_obj->getViewMode() == IL_CRS_VIEW_TIMING) {
388 $this->xmlElement('TimingMode', null, $this->course_obj->getTimingMode());
389 }
390
391 $this->xmlElement(
392 'SessionLimit',
393 [
394 'active' => $this->course_obj->isSessionLimitEnabled() ? 1 : 0,
395 'previous' => $this->course_obj->getNumberOfPreviousSessions(),
396 'next' => $this->course_obj->getNumberOfNextSessions()
397 ]
398 );
399
400 $this->xmlElement(
401 'WelcomeMail',
402 [
403 'status' => $this->course_obj->getAutoNotification() ? 1 : 0
404 ]
405 );
406
407 $this->xmlElement('StatusDetermination', null, (int) $this->course_obj->getStatusDetermination());
408 $this->xmlElement('MailToMembersType', null, (int) $this->course_obj->getMailToMembersType());
409 $this->xmlElement('CourseMap', [
410 'enabled' => (int) $this->course_obj->getEnableCourseMap(),
411 'latitude' => $this->course_obj->getLatitude(),
412 'longitude' => $this->course_obj->getLongitude(),
413 'location_zoom' => $this->course_obj->getLocationZoom()
414 ]);
415
416
417 $this->xmlEndTag('Settings');
418
419 return true;
420 }
421
422 public function __buildFooter()
423 {
424 $this->xmlEndTag('Course');
425 }
426
432 public function setAttachUsers($value)
433 {
434 $this->attach_users = $value ? true : false;
435 }
436}
if(!defined('PATH_SEPARATOR')) $GLOBALS['_PEAR_default_error_mode']
Definition: PEAR.php:64
An exception for terminatinating execution or to throw for unit testing.
const IL_CRS_SUBSCRIPTION_CONFIRMATION
const IL_CRS_VIEW_TIMING
const IL_CRS_SUBSCRIPTION_UNLIMITED
const IL_CRS_SUBSCRIPTION_DEACTIVATED
const IL_CRS_SUBSCRIPTION_DIRECT
const IL_CAL_UNIX
return true
Flag indicating whether or not HTTP headers will be sent when outputting captcha image/audio.
static _appendXMLByObjId(ilXmlWriter $a_xml_writer, $a_obj_id)
Get xml of object values.
static _exportContainerSortingSettings(ilXmlWriter $xml, $obj_id)
sorting XML-export for all container objects
static _exportContainerSettings(ilXmlWriter $a_xml, $a_obj_id)
__construct($course_obj)
constructor
modifyExportIdentifier($a_tag, $a_param, $a_value)
__buildAdvancedMetaData()
Build advanced meta data.
setAttachUsers($value)
write access to attach user property, if set to false no users will be attached.
XML writer class.
xmlEndTag($tag)
Writes an endtag.
xmlSetGenCmt($genCmt)
Sets generated comment.
xmlDumpMem($format=true)
Returns xml document from memory.
xmlHeader()
Writes xml header @access public.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
appendXML($a_str)
append xml string to document
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
xmlSetDtdDef($dtdDef)
Sets dtd definition.
global $DIC
Definition: goto.php:24
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
redirection script todo: (a better solution should control the processing via a xml file)
$data
Definition: storeScorm.php:23