ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
25 include_once "./Services/Xml/classes/class.ilXmlWriter.php";
26 
40 {
41  const MODE_SOAP = 1;
42  const MODE_EXPORT = 2;
43 
44  private $mode = self::MODE_SOAP;
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 $ilias;
64 
65  parent::__construct();
66 
67  $this->EXPORT_VERSION = "2";
68 
69  $this->ilias = $ilias;
70  $this->course_obj = $course_obj;
71  }
72 
73  public function setMode($a_mode)
74  {
75  $this->mode = $a_mode;
76  }
77 
78  public function getMode()
79  {
80  return $this->mode;
81  }
82 
83  public function start()
84  {
85  if ($this->getMode() == self::MODE_SOAP) {
86  $this->__buildHeader();
87  $this->__buildCourseStart();
88  $this->__buildMetaData();
89  $this->__buildAdvancedMetaData();
90  if ($this->attach_users) {
91  $this->__buildAdmin();
92  $this->__buildTutor();
93  $this->__buildMember();
94  }
95  $this->__buildSubscriber();
96  $this->__buildWaitingList();
97 
98  $this->__buildSetting();
99  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
100  ilContainerSortingSettings::_exportContainerSortingSettings($this, $this->course_obj->getId());
101  ilContainer::_exportContainerSettings($this, $this->course_obj->getId());
102  $this->__buildFooter();
103  } elseif ($this->getMode() == self::MODE_EXPORT) {
104  $this->__buildCourseStart();
105  $this->__buildMetaData();
106  $this->__buildAdvancedMetaData();
107  $this->__buildSetting();
108  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
109  ilContainerSortingSettings::_exportContainerSortingSettings($this, $this->course_obj->getId());
110  ilContainer::_exportContainerSettings($this, $this->course_obj->getId());
111  $this->__buildFooter();
112  }
113  }
114 
115  public function getXML()
116  {
117  #var_dump("<pre>", htmlentities($this->xmlDumpMem()),"<pre>");
118  return $this->xmlDumpMem(true);
119  }
120 
121  // Called from nested class
122  public function modifyExportIdentifier($a_tag, $a_param, $a_value)
123  {
124  if ($a_tag == "Identifier" && $a_param == "Entry") {
125  $a_value = "il_" . $this->ilias->getSetting('inst_id') . "_crs_" . $this->course_obj->getId();
126  }
127 
128  return $a_value;
129  }
130 
131  // PRIVATE
132  public function __buildHeader()
133  {
134  $this->xmlSetDtdDef("<!DOCTYPE Course PUBLIC \"-//ILIAS//DTD Course//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_crs_5_0.dtd\">");
135  $this->xmlSetGenCmt("Export of ILIAS course " . $this->course_obj->getId() . " of installation " . $this->ilias->getSetting('inst_id') . ".");
136  $this->xmlHeader();
137 
138 
139  return true;
140  }
141 
142  public function __buildCourseStart()
143  {
144  $attrs["exportVersion"] = $this->EXPORT_VERSION;
145  $attrs["id"] = "il_" . $this->ilias->getSetting('inst_id') . '_crs_' . $this->course_obj->getId();
146  $attrs['showMembers'] = ($this->course_obj->getShowMembers() ? 'Yes' : 'No');
147  $this->xmlStartTag("Course", $attrs);
148  }
149 
150  public function __buildMetaData()
151  {
152  include_once 'Services/MetaData/classes/class.ilMD2XML.php';
153 
154  $md2xml = new ilMD2XML($this->course_obj->getId(), $this->course_obj->getId(), 'crs');
155  $md2xml->startExport();
156  $this->appendXML($md2xml->getXML());
157 
158  return true;
159  }
160 
167  private function __buildAdvancedMetaData()
168  {
169  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
170  ilAdvancedMDValues::_appendXMLByObjId($this, $this->course_obj->getId());
171  }
172 
173  public function __buildAdmin()
174  {
175  $admins = $this->course_obj->getMembersObject()->getAdmins();
176  $admins = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
177  'manage_members',
179  $this->course_obj->getRefId(),
180  $admins
181  );
182 
183  foreach ($admins as $id) {
184  $attr['id'] = 'il_' . $this->ilias->getSetting('inst_id') . '_usr_' . $id;
185  $attr['notification'] = ($this->course_obj->getMembersObject()->isNotificationEnabled($id)) ? 'Yes' : 'No';
186  $attr['passed'] = $this->course_obj->getMembersObject()->hasPassed($id) ? 'Yes' : 'No';
187 
188  $this->xmlStartTag('Admin', $attr);
189  $this->xmlEndTag('Admin');
190  }
191  return true;
192  }
193 
194  public function __buildTutor()
195  {
196  $tutors = $this->course_obj->getMembersObject()->getTutors();
197  $tutors = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
198  'manage_members',
200  $this->course_obj->getRefId(),
201  $tutors
202  );
203  foreach ($tutors as $id) {
204  $attr['id'] = 'il_' . $this->ilias->getSetting('inst_id') . '_usr_' . $id;
205  $attr['notification'] = ($this->course_obj->getMembersObject()->isNotificationEnabled($id)) ? 'Yes' : 'No';
206  $attr['passed'] = $this->course_obj->getMembersObject()->hasPassed($id) ? 'Yes' : 'No';
207 
208  $this->xmlStartTag('Tutor', $attr);
209  $this->xmlEndTag('Tutor');
210  }
211  return true;
212  }
213  public function __buildMember()
214  {
215  $members = $this->course_obj->getMembersObject()->getMembers();
216  $members = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
217  'manage_members',
219  $this->course_obj->getRefId(),
220  $members
221  );
222  foreach ($members as $id) {
223  $attr['id'] = 'il_' . $this->ilias->getSetting('inst_id') . '_usr_' . $id;
224  $attr['blocked'] = ($this->course_obj->getMembersObject()->isBlocked($id)) ? 'Yes' : 'No';
225  $attr['passed'] = $this->course_obj->getMembersObject()->hasPassed($id) ? 'Yes' : 'No';
226 
227  $this->xmlStartTag('Member', $attr);
228  $this->xmlEndTag('Member');
229  }
230  return true;
231  }
232 
233  public function __buildSubscriber()
234  {
235  $subs = $this->course_obj->getMembersObject()->getSubscribers();
236  $subs = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
237  'manage_members',
239  $this->course_obj->getRefId(),
240  $subs
241  );
242 
243  foreach ($subs as $id) {
244  $data = $this->course_obj->getMembersObject()->getSubscriberData($id);
245 
246  $attr['id'] = 'il_' . $this->ilias->getSetting('inst_id') . '_usr_' . $id;
247  $attr['subscriptionTime'] = $data['time'];
248 
249  $this->xmlStartTag('Subscriber', $attr);
250  $this->xmlEndTag('Subscriber');
251  }
252  return true;
253  }
254 
255  public function __buildWaitingList()
256  {
257  include_once 'Modules/Course/classes/class.ilCourseWaitingList.php';
258  $waiting_list = new ilCourseWaitingList($this->course_obj->getId());
259 
260  $wait = $waiting_list->getAllUsers();
261 
262  foreach ($wait as $data) {
263  $is_accessible = $GLOBALS['DIC']->access()->filterUserIdsByRbacOrPositionOfCurrentUser(
264  'manage_members',
266  $this->course_obj->getRefId(),
267  [$data['usr_id']]
268  );
269  if (!count($is_accessible)) {
270  continue;
271  }
272 
273  $attr['id'] = 'il_' . $this->ilias->getSetting('inst_id') . '_usr_' . $data['usr_id'];
274  $attr['position'] = $data['position'];
275  $attr['subscriptionTime'] = $data['time'];
276 
277  $this->xmlStartTag('WaitingList', $attr);
278  $this->xmlEndTag('WaitingList');
279  }
280  return true;
281  }
282 
283 
284  public function __buildSetting()
285  {
286  $this->xmlStartTag('Settings');
287 
288  // Availability
289  $this->xmlStartTag('Availability');
290  if ($this->course_obj->getOfflineStatus()) {
291  $this->xmlElement('NotAvailable');
292  } elseif ($this->course_obj->getActivationUnlimitedStatus()) {
293  $this->xmlElement('Unlimited');
294  } else {
295  $this->xmlStartTag('TemporarilyAvailable');
296  $this->xmlElement('Start', null, $this->course_obj->getActivationStart());
297  $this->xmlElement('End', null, $this->course_obj->getActivationEnd());
298  $this->xmlEndTag('TemporarilyAvailable');
299  }
300  $this->xmlEndTag('Availability');
301 
302  // Syllabus
303  $this->xmlElement('Syllabus', null, $this->course_obj->getSyllabus());
304  $this->xmlElement('ImportantInformation', null, $this->course_obj->getImportantInformation());
305 
306 
307  // Contact
308  $this->xmlStartTag('Contact');
309  $this->xmlElement('Name', null, $this->course_obj->getContactName());
310  $this->xmlElement('Responsibility', null, $this->course_obj->getContactResponsibility());
311  $this->xmlElement('Phone', null, $this->course_obj->getContactPhone());
312  $this->xmlElement('Email', null, $this->course_obj->getContactEmail());
313  $this->xmlElement('Consultation', null, $this->course_obj->getContactConsultation());
314  $this->xmlEndTag('Contact');
315 
316  // Registration
317  $attr = array();
318 
319  if ($this->course_obj->getSubscriptionType() == IL_CRS_SUBSCRIPTION_CONFIRMATION) {
320  $attr['registrationType'] = 'Confirmation';
321  } elseif ($this->course_obj->getSubscriptionType() == IL_CRS_SUBSCRIPTION_DIRECT) {
322  $attr['registrationType'] = 'Direct';
323  } else {
324  $attr['registrationType'] = 'Password';
325  }
326 
327  $attr['maxMembers'] = $this->course_obj->isSubscriptionMembershipLimited() ?
328  $this->course_obj->getSubscriptionMaxMembers() : 0;
329  $attr['notification'] = $this->course_obj->getSubscriptionNotify() ? 'Yes' : 'No';
330  $attr['waitingList'] = $this->course_obj->enabledWaitingList() ? 'Yes' : 'No';
331 
332  $this->xmlStartTag('Registration', $attr);
333 
334  if ($this->course_obj->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED) {
335  $this->xmlElement('Disabled');
336  } elseif ($this->course_obj->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_UNLIMITED) {
337  $this->xmlElement('Unlimited');
338  } else {
339  $this->xmlStartTag('TemporarilyAvailable');
340  $this->xmlElement('Start', null, $this->course_obj->getSubscriptionStart());
341  $this->xmlElement('End', null, $this->course_obj->getSubscriptionEnd());
342  $this->xmlEndTag('TemporarilyAvailable');
343  }
344  if (strlen($pwd = $this->course_obj->getSubscriptionPassword())) {
345  $this->xmlElement('Password', null, $pwd);
346  }
347  $this->xmlEndTag('Registration');
348 
349 
350  $this->xmlStartTag('Period');
351  $this->xmlElement('Start', null, ($this->course_obj->getCourseStart() && !$this->course_obj->getCourseStart()->isNull()) ? $this->course_obj->getCourseStart()->get(IL_CAL_UNIX) : null);
352  $this->xmlElement('End', null, ($this->course_obj->getCourseEnd() && !$this->course_obj->getCourseEnd()->isNull()) ? $this->course_obj->getCourseEnd()->get(IL_CAL_UNIX) : null);
353  $this->xmlEndTag('Period');
354  $this->xmlElement('WaitingListAutoFill', null, (int) $this->course_obj->hasWaitingListAutoFill());
355  $this->xmlElement('CancellationEnd', null, ($this->course_obj->getCancellationEnd() && !$this->course_obj->getCancellationEnd()->isNull()) ? $this->course_obj->getCancellationEnd()->get(IL_CAL_UNIX) : null);
356  $this->xmlElement('MinMembers', null, (int) $this->course_obj->getSubscriptionMinMembers());
357 
358  $this->xmlElement('ViewMode', null, $this->course_obj->getViewMode());
359 
360  $this->xmlEndTag('Settings');
361 
362  return true;
363  }
364 
365  public function __buildFooter()
366  {
367  $this->xmlEndTag('Course');
368  }
369 
375  public function setAttachUsers($value)
376  {
377  $this->attach_users = $value ? true : false;
378  }
379 }
static _exportContainerSettings(ilXmlWriter $a_xml, $a_obj_id)
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
setAttachUsers($value)
write access to attach user property, if set to false no users will be attached.
xmlSetGenCmt($genCmt)
Sets generated comment.
xmlSetDtdDef($dtdDef)
Sets dtd definition.
xmlDumpMem($format=true)
Returns xml document from memory.
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
if(!array_key_exists('StateId', $_REQUEST)) $id
XML writer class.
static _appendXMLByObjId(ilXmlWriter $a_xml_writer, $a_obj_id)
Get xml of object values.
const IL_CRS_SUBSCRIPTION_CONFIRMATION
const IL_CAL_UNIX
xmlEndTag($tag)
Writes an endtag.
__construct($course_obj)
constructor
getAllUsers()
get all users on waiting list
const IL_CRS_SUBSCRIPTION_UNLIMITED
redirection script todo: (a better solution should control the processing via a xml file) ...
xmlHeader()
Writes xml header public.
Create styles array
The data for the language used.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
modifyExportIdentifier($a_tag, $a_param, $a_value)
static _exportContainerSortingSettings(ilXmlWriter $xml, $obj_id)
sorting XML-export for all container objects
appendXML($a_str)
append xml string to document
const IL_CRS_SUBSCRIPTION_DIRECT
const IL_CRS_SUBSCRIPTION_DEACTIVATED
__buildAdvancedMetaData()
Build advanced meta data.