ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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
49 private $xml;
50 private $course_obj;
51 private $attach_users = true;
52
53
61 public function __construct($course_obj)
62 {
63 global $DIC;
64
65 $ilias = $DIC['ilias'];
66
67 parent::__construct();
68
69 $this->EXPORT_VERSION = "2";
70
71 $this->ilias = $ilias;
72 $this->course_obj = $course_obj;
73 }
74
75 public function setMode($a_mode)
76 {
77 $this->mode = $a_mode;
78 }
79
80 public function getMode()
81 {
82 return $this->mode;
83 }
84
85 public function start()
86 {
87 if ($this->getMode() == self::MODE_SOAP) {
88 $this->__buildHeader();
89 $this->__buildCourseStart();
90 $this->__buildMetaData();
92 if ($this->attach_users) {
93 $this->__buildAdmin();
94 $this->__buildTutor();
95 $this->__buildMember();
96 }
97 $this->__buildSubscriber();
98 $this->__buildWaitingList();
99
100 $this->__buildSetting();
101 include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
102 ilContainerSortingSettings::_exportContainerSortingSettings($this, $this->course_obj->getId());
103 ilContainer::_exportContainerSettings($this, $this->course_obj->getId());
104 $this->__buildFooter();
105 } elseif ($this->getMode() == self::MODE_EXPORT) {
106 $this->__buildCourseStart();
107 $this->__buildMetaData();
109 $this->__buildSetting();
110 include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
111 ilContainerSortingSettings::_exportContainerSortingSettings($this, $this->course_obj->getId());
112 ilContainer::_exportContainerSettings($this, $this->course_obj->getId());
113 $this->__buildFooter();
114 }
115 }
116
117 public function getXML()
118 {
119 #var_dump("<pre>", htmlentities($this->xmlDumpMem()),"<pre>");
120 return $this->xmlDumpMem(true);
121 }
122
123 // Called from nested class
124 public function modifyExportIdentifier($a_tag, $a_param, $a_value)
125 {
126 if ($a_tag == "Identifier" && $a_param == "Entry") {
127 $a_value = "il_" . $this->ilias->getSetting('inst_id') . "_crs_" . $this->course_obj->getId();
128 }
129
130 return $a_value;
131 }
132
133 // PRIVATE
134 public function __buildHeader()
135 {
136 $this->xmlSetDtdDef("<!DOCTYPE Course PUBLIC \"-//ILIAS//DTD Course//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_crs_5_0.dtd\">");
137 $this->xmlSetGenCmt("Export of ILIAS course " . $this->course_obj->getId() . " of installation " . $this->ilias->getSetting('inst_id') . ".");
138 $this->xmlHeader();
139
140
141 return true;
142 }
143
144 public function __buildCourseStart()
145 {
146 $attrs["exportVersion"] = $this->EXPORT_VERSION;
147 $attrs["id"] = "il_" . $this->ilias->getSetting('inst_id') . '_crs_' . $this->course_obj->getId();
148 $attrs['showMembers'] = ($this->course_obj->getShowMembers() ? 'Yes' : 'No');
149 $this->xmlStartTag("Course", $attrs);
150 }
151
152 public function __buildMetaData()
153 {
154 include_once 'Services/MetaData/classes/class.ilMD2XML.php';
155
156 $md2xml = new ilMD2XML($this->course_obj->getId(), $this->course_obj->getId(), 'crs');
157 $md2xml->startExport();
158 $this->appendXML($md2xml->getXML());
159
160 return true;
161 }
162
169 private function __buildAdvancedMetaData()
170 {
171 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
172 ilAdvancedMDValues::_appendXMLByObjId($this, $this->course_obj->getId());
173 }
174
175 public function __buildAdmin()
176 {
177 $admins = $this->course_obj->getMembersObject()->getAdmins();
178 $admins = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
179 'manage_members',
181 $this->course_obj->getRefId(),
182 $admins
183 );
184
185 foreach ($admins as $id) {
186 $attr['id'] = 'il_' . $this->ilias->getSetting('inst_id') . '_usr_' . $id;
187 $attr['notification'] = ($this->course_obj->getMembersObject()->isNotificationEnabled($id)) ? 'Yes' : 'No';
188 $attr['passed'] = $this->course_obj->getMembersObject()->hasPassed($id) ? 'Yes' : 'No';
189 $attr['contact'] = $this->course_obj->getMembersObject()->isContact($id) ? 'Yes' : 'No';
190
191 $this->xmlStartTag('Admin', $attr);
192 $this->xmlEndTag('Admin');
193 }
194 return true;
195 }
196
197 public function __buildTutor()
198 {
199 $tutors = $this->course_obj->getMembersObject()->getTutors();
200 $tutors = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
201 'manage_members',
203 $this->course_obj->getRefId(),
204 $tutors
205 );
206 foreach ($tutors as $id) {
207 $attr['id'] = 'il_' . $this->ilias->getSetting('inst_id') . '_usr_' . $id;
208 $attr['notification'] = ($this->course_obj->getMembersObject()->isNotificationEnabled($id)) ? 'Yes' : 'No';
209 $attr['passed'] = $this->course_obj->getMembersObject()->hasPassed($id) ? 'Yes' : 'No';
210 $attr['contact'] = $this->course_obj->getMembersObject()->isContact($id) ? 'Yes' : 'No';
211
212 $this->xmlStartTag('Tutor', $attr);
213 $this->xmlEndTag('Tutor');
214 }
215 return true;
216 }
217 public function __buildMember()
218 {
219 $members = $this->course_obj->getMembersObject()->getMembers();
220 $members = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
221 'manage_members',
223 $this->course_obj->getRefId(),
224 $members
225 );
226 foreach ($members as $id) {
227 $attr['id'] = 'il_' . $this->ilias->getSetting('inst_id') . '_usr_' . $id;
228 $attr['blocked'] = ($this->course_obj->getMembersObject()->isBlocked($id)) ? 'Yes' : 'No';
229 $attr['passed'] = $this->course_obj->getMembersObject()->hasPassed($id) ? 'Yes' : 'No';
230
231 $this->xmlStartTag('Member', $attr);
232 $this->xmlEndTag('Member');
233 }
234 return true;
235 }
236
237 public function __buildSubscriber()
238 {
239 $subs = $this->course_obj->getMembersObject()->getSubscribers();
240 $subs = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
241 'manage_members',
243 $this->course_obj->getRefId(),
244 $subs
245 );
246
247 foreach ($subs as $id) {
248 $data = $this->course_obj->getMembersObject()->getSubscriberData($id);
249
250 $attr['id'] = 'il_' . $this->ilias->getSetting('inst_id') . '_usr_' . $id;
251 $attr['subscriptionTime'] = $data['time'];
252
253 $this->xmlStartTag('Subscriber', $attr);
254 $this->xmlEndTag('Subscriber');
255 }
256 return true;
257 }
258
259 public function __buildWaitingList()
260 {
261 include_once 'Modules/Course/classes/class.ilCourseWaitingList.php';
262 $waiting_list = new ilCourseWaitingList($this->course_obj->getId());
263
264 $wait = $waiting_list->getAllUsers();
265
266 foreach ($wait as $data) {
267 $is_accessible = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
268 'manage_members',
270 $this->course_obj->getRefId(),
271 [$data['usr_id']]
272 );
273 if (!count($is_accessible)) {
274 continue;
275 }
276
277 $attr['id'] = 'il_' . $this->ilias->getSetting('inst_id') . '_usr_' . $data['usr_id'];
278 $attr['position'] = $data['position'];
279 $attr['subscriptionTime'] = $data['time'];
280
281 $this->xmlStartTag('WaitingList', $attr);
282 $this->xmlEndTag('WaitingList');
283 }
284 return true;
285 }
286
287
288 public function __buildSetting()
289 {
290 $this->xmlStartTag('Settings');
291
292 // Availability
293 $this->xmlStartTag('Availability');
294 if ($this->course_obj->getOfflineStatus()) {
295 $this->xmlElement('NotAvailable');
296 } elseif ($this->course_obj->getActivationUnlimitedStatus()) {
297 $this->xmlElement('Unlimited');
298 } else {
299 $this->xmlStartTag('TemporarilyAvailable');
300 $this->xmlElement('Start', null, $this->course_obj->getActivationStart());
301 $this->xmlElement('End', null, $this->course_obj->getActivationEnd());
302 $this->xmlEndTag('TemporarilyAvailable');
303 }
304 $this->xmlEndTag('Availability');
305
306 // Syllabus
307 $this->xmlElement('Syllabus', null, $this->course_obj->getSyllabus());
308 $this->xmlElement('ImportantInformation', null, $this->course_obj->getImportantInformation());
309
310
311 // Contact
312 $this->xmlStartTag('Contact');
313 $this->xmlElement('Name', null, $this->course_obj->getContactName());
314 $this->xmlElement('Responsibility', null, $this->course_obj->getContactResponsibility());
315 $this->xmlElement('Phone', null, $this->course_obj->getContactPhone());
316 $this->xmlElement('Email', null, $this->course_obj->getContactEmail());
317 $this->xmlElement('Consultation', null, $this->course_obj->getContactConsultation());
318 $this->xmlEndTag('Contact');
319
320 // Registration
321 $attr = array();
322
323 if ($this->course_obj->getSubscriptionType() == IL_CRS_SUBSCRIPTION_CONFIRMATION) {
324 $attr['registrationType'] = 'Confirmation';
325 } elseif ($this->course_obj->getSubscriptionType() == IL_CRS_SUBSCRIPTION_DIRECT) {
326 $attr['registrationType'] = 'Direct';
327 } else {
328 $attr['registrationType'] = 'Password';
329 }
330
331 $attr['maxMembers'] = $this->course_obj->isSubscriptionMembershipLimited() ?
332 $this->course_obj->getSubscriptionMaxMembers() : 0;
333 $attr['notification'] = $this->course_obj->getSubscriptionNotify() ? 'Yes' : 'No';
334 $attr['waitingList'] = $this->course_obj->enabledWaitingList() ? 'Yes' : 'No';
335
336 $this->xmlStartTag('Registration', $attr);
337
338 if ($this->course_obj->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED) {
339 $this->xmlElement('Disabled');
340 } elseif ($this->course_obj->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_UNLIMITED) {
341 $this->xmlElement('Unlimited');
342 } else {
343 $this->xmlStartTag('TemporarilyAvailable');
344 $this->xmlElement('Start', null, $this->course_obj->getSubscriptionStart());
345 $this->xmlElement('End', null, $this->course_obj->getSubscriptionEnd());
346 $this->xmlEndTag('TemporarilyAvailable');
347 }
348 if (strlen($pwd = $this->course_obj->getSubscriptionPassword())) {
349 $this->xmlElement('Password', null, $pwd);
350 }
351 $this->xmlEndTag('Registration');
352
353
354 $this->xmlStartTag('Period');
355 $this->xmlElement('Start', null, ($this->course_obj->getCourseStart() && !$this->course_obj->getCourseStart()->isNull()) ? $this->course_obj->getCourseStart()->get(IL_CAL_UNIX) : null);
356 $this->xmlElement('End', null, ($this->course_obj->getCourseEnd() && !$this->course_obj->getCourseEnd()->isNull()) ? $this->course_obj->getCourseEnd()->get(IL_CAL_UNIX) : null);
357 $this->xmlEndTag('Period');
358 $this->xmlElement('WaitingListAutoFill', null, (int) $this->course_obj->hasWaitingListAutoFill());
359 $this->xmlElement('CancellationEnd', null, ($this->course_obj->getCancellationEnd() && !$this->course_obj->getCancellationEnd()->isNull()) ? $this->course_obj->getCancellationEnd()->get(IL_CAL_UNIX) : null);
360 $this->xmlElement('MinMembers', null, (int) $this->course_obj->getSubscriptionMinMembers());
361
362 $this->xmlElement('ViewMode', null, $this->course_obj->getViewMode());
363
364 // cognos-blu-patch: begin
365 $this->xmlElement('ViewMode', null, $this->course_obj->getViewMode());
366
367 if ($this->course_obj->getViewMode() == IL_CRS_VIEW_TIMING) {
368 $this->xmlElement('TimingMode', null, $this->course_obj->getTimingMode());
369 }
370 // cognos-blu-patch: end
371
372 $this->xmlEndTag('Settings');
373
374 return true;
375 }
376
377 public function __buildFooter()
378 {
379 $this->xmlEndTag('Course');
380 }
381
387 public function setAttachUsers($value)
388 {
389 $this->attach_users = $value ? true : false;
390 }
391}
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
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.
if(!array_key_exists('StateId', $_REQUEST)) $id
$GLOBALS['JPEG_Segment_Names']
Global Variable: XMP_tag_captions.
redirection script todo: (a better solution should control the processing via a xml file)
global $DIC
Definition: saml.php:7
$data
Definition: bench.php:6