ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
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 
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->__buildObject($this->course_obj->getRefId());
104 
105  $this->__buildFooter();
106  }
107  elseif($this->getMode() == self::MODE_EXPORT)
108  {
109  $this->__buildCourseStart();
110  $this->__buildMetaData();
111  $this->__buildAdvancedMetaData();
112  $this->__buildSetting();
113  $this->__buildFooter();
114  }
115  }
116 
117  function getXML()
118  {
119  #var_dump("<pre>", htmlentities($this->xmlDumpMem()),"<pre>");
120  return $this->xmlDumpMem(false);
121  }
122 
123  // Called from nested class
124  function modifyExportIdentifier($a_tag, $a_param, $a_value)
125  {
126  if ($a_tag == "Identifier" && $a_param == "Entry")
127  {
128  $a_value = "il_".$this->ilias->getSetting('inst_id')."_crs_".$this->course_obj->getId();
129  }
130 
131  return $a_value;
132  }
133 
134  // PRIVATE
135  function __buildHeader()
136  {
137  $this->xmlSetDtdDef("<!DOCTYPE Course PUBLIC \"-//ILIAS//DTD Course//EN\" \"".ILIAS_HTTP_PATH."/xml/ilias_course_3_10.dtd\">");
138  $this->xmlSetGenCmt("Export of ILIAS course ". $this->course_obj->getId()." of installation ".$this->ilias->getSetting('inst_id').".");
139  $this->xmlHeader();
140 
141 
142  return true;
143  }
144 
146  {
147  $attrs["exportVersion"] = $this->EXPORT_VERSION;
148  $attrs["id"] = "il_".$this->ilias->getSetting('inst_id').'_crs_'.$this->course_obj->getId();
149  $attrs['showMembers'] = ($this->course_obj->getShowMembers() ? 'Yes' : 'No');
150  $this->xmlStartTag("Course", $attrs);
151  }
152 
153  function __buildMetaData()
154  {
155  include_once 'Services/MetaData/classes/class.ilMD2XML.php';
156 
157  $md2xml = new ilMD2XML($this->course_obj->getId(),$this->course_obj->getId(),'crs');
158  $md2xml->startExport();
159  $this->appendXML($md2xml->getXML());
160 
161  return true;
162  }
163 
170  private function __buildAdvancedMetaData()
171  {
172  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValues.php');
173  ilAdvancedMDValues::_appendXMLByObjId($this,$this->course_obj->getId());
174  }
175 
176  function __buildAdmin()
177  {
178  $this->course_obj->initCourseMemberObject();
179 
180  foreach($this->course_obj->members_obj->getAdmins() as $id)
181  {
182  $attr['id'] = 'il_'.$this->ilias->getSetting('inst_id').'_usr_'.$id;
183  $attr['notification'] = ($this->course_obj->members_obj->isNotificationEnabled($id)) ? 'Yes' : 'No';
184  $attr['passed'] = $this->course_obj->members_obj->hasPassed($id) ? 'Yes' : 'No';
185 
186  $this->xmlStartTag('Admin',$attr);
187  $this->xmlEndTag('Admin');
188  }
189  return true;
190  }
191 
192  function __buildTutor()
193  {
194  $this->course_obj->initCourseMemberObject();
195 
196  foreach($this->course_obj->members_obj->getTutors() as $id)
197  {
198  $attr['id'] = 'il_'.$this->ilias->getSetting('inst_id').'_usr_'.$id;
199  $attr['notification'] = ($this->course_obj->members_obj->isNotificationEnabled($id)) ? 'Yes' : 'No';
200  $attr['passed'] = $this->course_obj->members_obj->hasPassed($id) ? 'Yes' : 'No';
201 
202  $this->xmlStartTag('Tutor',$attr);
203  $this->xmlEndTag('Tutor');
204  }
205  return true;
206  }
207  function __buildMember()
208  {
209  $this->course_obj->initCourseMemberObject();
210 
211  foreach($this->course_obj->members_obj->getMembers() as $id)
212  {
213  $attr['id'] = 'il_'.$this->ilias->getSetting('inst_id').'_usr_'.$id;
214  $attr['blocked'] = ($this->course_obj->members_obj->isBlocked($id)) ? 'Yes' : 'No';
215  $attr['passed'] = $this->course_obj->members_obj->hasPassed($id) ? 'Yes' : 'No';
216 
217  $this->xmlStartTag('Member',$attr);
218  $this->xmlEndTag('Member');
219  }
220  return true;
221  }
222 
223  function __buildSubscriber()
224  {
225  $this->course_obj->initCourseMemberObject();
226 
227  foreach($this->course_obj->members_obj->getSubscribers() as $id)
228  {
229  $data = $this->course_obj->members_obj->getSubscriberData($id);
230 
231  $attr['id'] = 'il_'.$this->ilias->getSetting('inst_id').'_usr_'.$id;
232  $attr['subscriptionTime'] = $data['time'];
233 
234  $this->xmlStartTag('Subscriber',$attr);
235  $this->xmlEndTag('Subscriber');
236  }
237  return true;
238  }
239 
241  {
242  include_once 'Modules/Course/classes/class.ilCourseWaitingList.php';
243 
244  $waiting_list = new ilCourseWaitingList($this->course_obj->getId());
245 
246  foreach($waiting_list->getAllUsers() as $data)
247  {
248  $attr['id'] = 'il_'.$this->ilias->getSetting('inst_id').'_usr_'.$data['usr_id'];
249  $attr['position'] = $data['position'];
250  $attr['subscriptionTime'] = $data['time'];
251 
252  $this->xmlStartTag('WaitingList',$attr);
253  $this->xmlEndTag('WaitingList');
254  }
255  return true;
256  }
257 
258 
259  function __buildSetting()
260  {
261  $this->xmlStartTag('Settings');
262 
263  // Availability
264  $this->xmlStartTag('Availability');
265  if($this->course_obj->getOfflineStatus())
266  {
267  $this->xmlElement('NotAvailable');
268  }
269  elseif($this->course_obj->getActivationUnlimitedStatus())
270  {
271  $this->xmlElement('Unlimited');
272  }
273  else
274  {
275  $this->xmlStartTag('TemporarilyAvailable');
276  $this->xmlElement('Start',null,$this->course_obj->getActivationStart());
277  $this->xmlElement('End',null,$this->course_obj->getActivationEnd());
278  $this->xmlEndTag('TemporarilyAvailable');
279  }
280  $this->xmlEndTag('Availability');
281 
282  // Syllabus
283  $this->xmlElement('Syllabus',null,$this->course_obj->getSyllabus());
284  $this->xmlElement('ImportantInformation',null,$this->course_obj->getImportantInformation());
285 
286 
287  // Contact
288  $this->xmlStartTag('Contact');
289  $this->xmlElement('Name',null,$this->course_obj->getContactName());
290  $this->xmlElement('Responsibility',null,$this->course_obj->getContactResponsibility());
291  $this->xmlElement('Phone',null,$this->course_obj->getContactPhone());
292  $this->xmlElement('Email',null,$this->course_obj->getContactEmail());
293  $this->xmlElement('Consultation',null,$this->course_obj->getContactConsultation());
294  $this->xmlEndTag('Contact');
295 
296  // Registration
297  $attr = array();
298 
299  if($this->course_obj->getSubscriptionType() == IL_CRS_SUBSCRIPTION_CONFIRMATION)
300  {
301  $attr['registrationType'] = 'Confirmation';
302  }
303  elseif($this->course_obj->getSubscriptionType() == IL_CRS_SUBSCRIPTION_DIRECT)
304  {
305  $attr['registrationType'] = 'Direct';
306  }
307  else
308  {
309  $attr['registrationType'] = 'Password';
310  }
311 
312  $attr['maxMembers'] = $this->course_obj->getSubscriptionMaxMembers();
313  $attr['notification'] = $this->course_obj->getSubscriptionNotify() ? 'Yes' : 'No';
314  $attr['waitingList'] = $this->course_obj->enabledWaitingList() ? 'Yes' : 'No';
315 
316  $this->xmlStartTag('Registration',$attr);
317 
318  if($this->course_obj->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED)
319  {
320  $this->xmlElement('Disabled');
321  }
322  elseif($this->course_obj->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_UNLIMITED)
323  {
324  $this->xmlElement('Unlimited');
325  }
326  else
327  {
328  $this->xmlStartTag('TemporarilyAvailable');
329  $this->xmlElement('Start',null,$this->course_obj->getSubscriptionStart());
330  $this->xmlElement('End',null,$this->course_obj->getSubscriptionEnd());
331  $this->xmlEndTag('TemporarilyAvailable');
332  }
333  if(strlen($pwd = $this->course_obj->getSubscriptionPassword()))
334  {
335  $this->xmlElement('Password',null,$pwd);
336  }
337  $this->xmlEndTag('Registration');
338 
339  // Sort
340  $attr = array();
341  if($this->course_obj->getOrderType() == ilContainer::SORT_MANUAL)
342  {
343  $attr['type'] = 'Manual';
344  }
345  elseif($this->course_obj->getOrderType() == ilContainer::SORT_TITLE)
346  {
347  $attr['type'] = 'Title';
348  }
349  else
350  {
351  $attr['type'] = 'Activation';
352  }
353  $this->xmlElement('Sort',$attr);
354 
355  // Archives
356  $attr = array();
357  if($this->course_obj->getViewMode() != IL_CRS_VIEW_ARCHIVE)
358  {
359  $attr['Access'] = 'Disabled';
360  }
361  elseif($this->course_obj->getViewMode() == IL_CRS_VIEW_ARCHIVE)
362  {
363  $attr['Access'] = 'Read';
364  }
365  if($this->course_obj->getArchiveType() == IL_CRS_ARCHIVE_DOWNLOAD)
366  {
367  $attr['Access'] = 'Download';
368  }
369  $this->xmlStartTag('Archive',$attr);
370 
371  $this->xmlElement('Start',null,$this->course_obj->getArchiveStart());
372  $this->xmlElement('End',null,$this->course_obj->getArchiveEnd());
373 
374  $this->xmlEndTag('Archive');
375 
376  $this->xmlEndTag('Settings');
377 
378  return true;
379  }
380 
381 
382  // recursive
383  function __buildObject($a_parent_id)
384  {
385  $this->course_obj->initCourseItemObject();
386  $this->course_obj->items_obj->setParentId($a_parent_id);
387 
388  foreach($this->course_obj->items_obj->getAllItems() as $item)
389  {
390 
391  if(!$tmp_obj =& ilObjectFactory::getInstanceByRefId($item['child'],false))
392  {
393  continue;
394  }
395 
396  $attr = array();
397  $attr['id'] = 'il_'.$this->ilias->getSetting('inst_id').'_'.$tmp_obj->getType().'_'.$item['child'];
398  $attr['type'] = $tmp_obj->getType();
399  $attr['Unlimited'] = $item['activation_unlimited'] ? 1 : 0;
400  $attr['Position'] = $item['position'];
401 
402  $this->xmlStartTag('Object',$attr);
403  $this->xmlElement('Title',null,$item['title']);
404  $this->xmlElement('Description',null,$item['description']);
405  $this->xmlElement('Start',null,$item['activation_start']);
406  $this->xmlElement('End',null,$item['activation_end']);
407 
408  if($item['type'] == 'file')
409  {
410  $this->xmlElement('FileType',null,$tmp_obj->getFileType());
411  }
412 
413  $this->__buildObject($item['child']);
414 
415  $this->xmlEndTag('Object');
416 
417  unset($tmp_obj);
418  }
419  }
420 
421  function __buildFooter()
422  {
423  $this->xmlEndTag('Course');
424  }
425 
431  function setAttachUsers ($value) {
432  $this->attach_users = $value ? true : false;
433  }
434 }
435 
436 
437 ?>