ILIAS  release_4-4 Revision
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 
62  {
63  global $ilias;
64 
65  parent::ilXmlWriter();
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  function start()
84  {
85  if($this->getMode() == self::MODE_SOAP)
86  {
87 
88  $this->__buildHeader();
89  $this->__buildCourseStart();
90  $this->__buildMetaData();
91  $this->__buildAdvancedMetaData();
92  if ($this->attach_users)
93  {
94  $this->__buildAdmin();
95  $this->__buildTutor();
96  $this->__buildMember();
97  }
98  $this->__buildSubscriber();
99  $this->__buildWaitingList();
100 
101  $this->__buildSetting();
102 
103  $this->__buildFooter();
104  }
105  elseif($this->getMode() == self::MODE_EXPORT)
106  {
107  $this->__buildCourseStart();
108  $this->__buildMetaData();
109  $this->__buildAdvancedMetaData();
110  $this->__buildSetting();
111  $this->__buildFooter();
112  }
113  }
114 
115  function getXML()
116  {
117  #var_dump("<pre>", htmlentities($this->xmlDumpMem()),"<pre>");
118  return $this->xmlDumpMem(false);
119  }
120 
121  // Called from nested class
122  function modifyExportIdentifier($a_tag, $a_param, $a_value)
123  {
124  if ($a_tag == "Identifier" && $a_param == "Entry")
125  {
126  $a_value = "il_".$this->ilias->getSetting('inst_id')."_crs_".$this->course_obj->getId();
127  }
128 
129  return $a_value;
130  }
131 
132  // PRIVATE
133  function __buildHeader()
134  {
135  $this->xmlSetDtdDef("<!DOCTYPE Course PUBLIC \"-//ILIAS//DTD Course//EN\" \"".ILIAS_HTTP_PATH."/xml/ilias_course_3_10.dtd\">");
136  $this->xmlSetGenCmt("Export of ILIAS course ". $this->course_obj->getId()." of installation ".$this->ilias->getSetting('inst_id').".");
137  $this->xmlHeader();
138 
139 
140  return true;
141  }
142 
144  {
145  $attrs["exportVersion"] = $this->EXPORT_VERSION;
146  $attrs["id"] = "il_".$this->ilias->getSetting('inst_id').'_crs_'.$this->course_obj->getId();
147  $attrs['showMembers'] = ($this->course_obj->getShowMembers() ? 'Yes' : 'No');
148  $this->xmlStartTag("Course", $attrs);
149  }
150 
151  function __buildMetaData()
152  {
153  include_once 'Services/MetaData/classes/class.ilMD2XML.php';
154 
155  $md2xml = new ilMD2XML($this->course_obj->getId(),$this->course_obj->getId(),'crs');
156  $md2xml->startExport();
157  $this->appendXML($md2xml->getXML());
158 
159  return true;
160  }
161 
168  private function __buildAdvancedMetaData()
169  {
170  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
171  ilAdvancedMDValues::_appendXMLByObjId($this,$this->course_obj->getId());
172  }
173 
174  function __buildAdmin()
175  {
176  foreach($this->course_obj->getMembersObject()->getAdmins() as $id)
177  {
178  $attr['id'] = 'il_'.$this->ilias->getSetting('inst_id').'_usr_'.$id;
179  $attr['notification'] = ($this->course_obj->getMembersObject()->isNotificationEnabled($id)) ? 'Yes' : 'No';
180  $attr['passed'] = $this->course_obj->getMembersObject()->hasPassed($id) ? 'Yes' : 'No';
181 
182  $this->xmlStartTag('Admin',$attr);
183  $this->xmlEndTag('Admin');
184  }
185  return true;
186  }
187 
188  function __buildTutor()
189  {
190  foreach($this->course_obj->getMembersObject()->getTutors() as $id)
191  {
192  $attr['id'] = 'il_'.$this->ilias->getSetting('inst_id').'_usr_'.$id;
193  $attr['notification'] = ($this->course_obj->getMembersObject()->isNotificationEnabled($id)) ? 'Yes' : 'No';
194  $attr['passed'] = $this->course_obj->getMembersObject()->hasPassed($id) ? 'Yes' : 'No';
195 
196  $this->xmlStartTag('Tutor',$attr);
197  $this->xmlEndTag('Tutor');
198  }
199  return true;
200  }
201  function __buildMember()
202  {
203  foreach($this->course_obj->getMembersObject()->getMembers() as $id)
204  {
205  $attr['id'] = 'il_'.$this->ilias->getSetting('inst_id').'_usr_'.$id;
206  $attr['blocked'] = ($this->course_obj->getMembersObject()->isBlocked($id)) ? 'Yes' : 'No';
207  $attr['passed'] = $this->course_obj->getMembersObject()->hasPassed($id) ? 'Yes' : 'No';
208 
209  $this->xmlStartTag('Member',$attr);
210  $this->xmlEndTag('Member');
211  }
212  return true;
213  }
214 
215  function __buildSubscriber()
216  {
217  foreach($this->course_obj->getMembersObject()->getSubscribers() as $id)
218  {
219  $data = $this->course_obj->getMembersObject()->getSubscriberData($id);
220 
221  $attr['id'] = 'il_'.$this->ilias->getSetting('inst_id').'_usr_'.$id;
222  $attr['subscriptionTime'] = $data['time'];
223 
224  $this->xmlStartTag('Subscriber',$attr);
225  $this->xmlEndTag('Subscriber');
226  }
227  return true;
228  }
229 
231  {
232  include_once 'Modules/Course/classes/class.ilCourseWaitingList.php';
233 
234  $waiting_list = new ilCourseWaitingList($this->course_obj->getId());
235 
236  foreach($waiting_list->getAllUsers() as $data)
237  {
238  $attr['id'] = 'il_'.$this->ilias->getSetting('inst_id').'_usr_'.$data['usr_id'];
239  $attr['position'] = $data['position'];
240  $attr['subscriptionTime'] = $data['time'];
241 
242  $this->xmlStartTag('WaitingList',$attr);
243  $this->xmlEndTag('WaitingList');
244  }
245  return true;
246  }
247 
248 
249  function __buildSetting()
250  {
251  $this->xmlStartTag('Settings');
252 
253  // Availability
254  $this->xmlStartTag('Availability');
255  if($this->course_obj->getOfflineStatus())
256  {
257  $this->xmlElement('NotAvailable');
258  }
259  elseif($this->course_obj->getActivationUnlimitedStatus())
260  {
261  $this->xmlElement('Unlimited');
262  }
263  else
264  {
265  $this->xmlStartTag('TemporarilyAvailable');
266  $this->xmlElement('Start',null,$this->course_obj->getActivationStart());
267  $this->xmlElement('End',null,$this->course_obj->getActivationEnd());
268  $this->xmlEndTag('TemporarilyAvailable');
269  }
270  $this->xmlEndTag('Availability');
271 
272  // Syllabus
273  $this->xmlElement('Syllabus',null,$this->course_obj->getSyllabus());
274  $this->xmlElement('ImportantInformation',null,$this->course_obj->getImportantInformation());
275 
276 
277  // Contact
278  $this->xmlStartTag('Contact');
279  $this->xmlElement('Name',null,$this->course_obj->getContactName());
280  $this->xmlElement('Responsibility',null,$this->course_obj->getContactResponsibility());
281  $this->xmlElement('Phone',null,$this->course_obj->getContactPhone());
282  $this->xmlElement('Email',null,$this->course_obj->getContactEmail());
283  $this->xmlElement('Consultation',null,$this->course_obj->getContactConsultation());
284  $this->xmlEndTag('Contact');
285 
286  // Registration
287  $attr = array();
288 
289  if($this->course_obj->getSubscriptionType() == IL_CRS_SUBSCRIPTION_CONFIRMATION)
290  {
291  $attr['registrationType'] = 'Confirmation';
292  }
293  elseif($this->course_obj->getSubscriptionType() == IL_CRS_SUBSCRIPTION_DIRECT)
294  {
295  $attr['registrationType'] = 'Direct';
296  }
297  else
298  {
299  $attr['registrationType'] = 'Password';
300  }
301 
302  $attr['maxMembers'] = $this->course_obj->isSubscriptionMembershipLimited() ?
303  $this->course_obj->getSubscriptionMaxMembers() : 0;
304  $attr['notification'] = $this->course_obj->getSubscriptionNotify() ? 'Yes' : 'No';
305  $attr['waitingList'] = $this->course_obj->enabledWaitingList() ? 'Yes' : 'No';
306 
307  $this->xmlStartTag('Registration',$attr);
308 
309  if($this->course_obj->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED)
310  {
311  $this->xmlElement('Disabled');
312  }
313  elseif($this->course_obj->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_UNLIMITED)
314  {
315  $this->xmlElement('Unlimited');
316  }
317  else
318  {
319  $this->xmlStartTag('TemporarilyAvailable');
320  $this->xmlElement('Start',null,$this->course_obj->getSubscriptionStart());
321  $this->xmlElement('End',null,$this->course_obj->getSubscriptionEnd());
322  $this->xmlEndTag('TemporarilyAvailable');
323  }
324  if(strlen($pwd = $this->course_obj->getSubscriptionPassword()))
325  {
326  $this->xmlElement('Password',null,$pwd);
327  }
328  $this->xmlEndTag('Registration');
329 
330  // Sort
331  $attr = array();
332  if($this->course_obj->getOrderType() == ilContainer::SORT_MANUAL)
333  {
334  $attr['type'] = 'Manual';
335  }
336  elseif($this->course_obj->getOrderType() == ilContainer::SORT_TITLE)
337  {
338  $attr['type'] = 'Title';
339  }
340  else
341  {
342  $attr['type'] = 'Activation';
343  }
344  $this->xmlElement('Sort',$attr);
345 
346  // Archives
347  $attr = array();
348  if($this->course_obj->getViewMode() != IL_CRS_VIEW_ARCHIVE)
349  {
350  $attr['Access'] = 'Disabled';
351  }
352  elseif($this->course_obj->getViewMode() == IL_CRS_VIEW_ARCHIVE)
353  {
354  $attr['Access'] = 'Read';
355  }
356  if($this->course_obj->getArchiveType() == IL_CRS_ARCHIVE_DOWNLOAD)
357  {
358  $attr['Access'] = 'Download';
359  }
360  $this->xmlStartTag('Archive',$attr);
361 
362  $this->xmlElement('Start',null,$this->course_obj->getArchiveStart());
363  $this->xmlElement('End',null,$this->course_obj->getArchiveEnd());
364 
365  $this->xmlEndTag('Archive');
366 
367  $this->xmlEndTag('Settings');
368 
369  return true;
370  }
371 
372  function __buildFooter()
373  {
374  $this->xmlEndTag('Course');
375  }
376 
382  function setAttachUsers ($value) {
383  $this->attach_users = $value ? true : false;
384  }
385 }
386 
387 
388 ?>
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.
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
ilCourseXMLWriter(&$course_obj)
constructor
XML writer class.
xmlElement($tag, $attrs=NULL, $data=Null, $encode=TRUE, $escape=TRUE)
Writes a basic element (no children, just textual content)
const IL_CRS_SUBSCRIPTION_CONFIRMATION
xmlEndTag($tag)
Writes an endtag.
const IL_CRS_SUBSCRIPTION_UNLIMITED
const IL_CRS_VIEW_ARCHIVE
redirection script todo: (a better solution should control the processing via a xml file) ...
xmlHeader()
Writes xml header public.
static _appendXMLByObjId(ilXmlWriter $xml_writer, $a_obj_id)
Get xml of object values.
modifyExportIdentifier($a_tag, $a_param, $a_value)
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
const IL_CRS_ARCHIVE_DOWNLOAD
appendXML($a_str)
append xml string to document
const IL_CRS_SUBSCRIPTION_DIRECT
xmlDumpMem($format=TRUE)
Returns xml document from memory.
const IL_CRS_SUBSCRIPTION_DEACTIVATED
__buildAdvancedMetaData()
Build advanced meta data.