ILIAS  Release_4_2_x_branch Revision 61807
 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  foreach($this->course_obj->getMembersObject()->getAdmins() as $id)
179  {
180  $attr['id'] = 'il_'.$this->ilias->getSetting('inst_id').'_usr_'.$id;
181  $attr['notification'] = ($this->course_obj->getMembersObject()->isNotificationEnabled($id)) ? 'Yes' : 'No';
182  $attr['passed'] = $this->course_obj->getMembersObject()->hasPassed($id) ? 'Yes' : 'No';
183 
184  $this->xmlStartTag('Admin',$attr);
185  $this->xmlEndTag('Admin');
186  }
187  return true;
188  }
189 
190  function __buildTutor()
191  {
192  foreach($this->course_obj->getMembersObject()->getTutors() as $id)
193  {
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 
198  $this->xmlStartTag('Tutor',$attr);
199  $this->xmlEndTag('Tutor');
200  }
201  return true;
202  }
203  function __buildMember()
204  {
205  foreach($this->course_obj->getMembersObject()->getMembers() as $id)
206  {
207  $attr['id'] = 'il_'.$this->ilias->getSetting('inst_id').'_usr_'.$id;
208  $attr['blocked'] = ($this->course_obj->getMembersObject()->isBlocked($id)) ? 'Yes' : 'No';
209  $attr['passed'] = $this->course_obj->getMembersObject()->hasPassed($id) ? 'Yes' : 'No';
210 
211  $this->xmlStartTag('Member',$attr);
212  $this->xmlEndTag('Member');
213  }
214  return true;
215  }
216 
217  function __buildSubscriber()
218  {
219  foreach($this->course_obj->getMembersObject()->getSubscribers() as $id)
220  {
221  $data = $this->course_obj->getMembersObject()->getSubscriberData($id);
222 
223  $attr['id'] = 'il_'.$this->ilias->getSetting('inst_id').'_usr_'.$id;
224  $attr['subscriptionTime'] = $data['time'];
225 
226  $this->xmlStartTag('Subscriber',$attr);
227  $this->xmlEndTag('Subscriber');
228  }
229  return true;
230  }
231 
233  {
234  include_once 'Modules/Course/classes/class.ilCourseWaitingList.php';
235 
236  $waiting_list = new ilCourseWaitingList($this->course_obj->getId());
237 
238  foreach($waiting_list->getAllUsers() as $data)
239  {
240  $attr['id'] = 'il_'.$this->ilias->getSetting('inst_id').'_usr_'.$data['usr_id'];
241  $attr['position'] = $data['position'];
242  $attr['subscriptionTime'] = $data['time'];
243 
244  $this->xmlStartTag('WaitingList',$attr);
245  $this->xmlEndTag('WaitingList');
246  }
247  return true;
248  }
249 
250 
251  function __buildSetting()
252  {
253  $this->xmlStartTag('Settings');
254 
255  // Availability
256  $this->xmlStartTag('Availability');
257  if($this->course_obj->getOfflineStatus())
258  {
259  $this->xmlElement('NotAvailable');
260  }
261  elseif($this->course_obj->getActivationUnlimitedStatus())
262  {
263  $this->xmlElement('Unlimited');
264  }
265  else
266  {
267  $this->xmlStartTag('TemporarilyAvailable');
268  $this->xmlElement('Start',null,$this->course_obj->getActivationStart());
269  $this->xmlElement('End',null,$this->course_obj->getActivationEnd());
270  $this->xmlEndTag('TemporarilyAvailable');
271  }
272  $this->xmlEndTag('Availability');
273 
274  // Syllabus
275  $this->xmlElement('Syllabus',null,$this->course_obj->getSyllabus());
276  $this->xmlElement('ImportantInformation',null,$this->course_obj->getImportantInformation());
277 
278 
279  // Contact
280  $this->xmlStartTag('Contact');
281  $this->xmlElement('Name',null,$this->course_obj->getContactName());
282  $this->xmlElement('Responsibility',null,$this->course_obj->getContactResponsibility());
283  $this->xmlElement('Phone',null,$this->course_obj->getContactPhone());
284  $this->xmlElement('Email',null,$this->course_obj->getContactEmail());
285  $this->xmlElement('Consultation',null,$this->course_obj->getContactConsultation());
286  $this->xmlEndTag('Contact');
287 
288  // Registration
289  $attr = array();
290 
291  if($this->course_obj->getSubscriptionType() == IL_CRS_SUBSCRIPTION_CONFIRMATION)
292  {
293  $attr['registrationType'] = 'Confirmation';
294  }
295  elseif($this->course_obj->getSubscriptionType() == IL_CRS_SUBSCRIPTION_DIRECT)
296  {
297  $attr['registrationType'] = 'Direct';
298  }
299  else
300  {
301  $attr['registrationType'] = 'Password';
302  }
303 
304  $attr['maxMembers'] = $this->course_obj->getSubscriptionMaxMembers();
305  $attr['notification'] = $this->course_obj->getSubscriptionNotify() ? 'Yes' : 'No';
306  $attr['waitingList'] = $this->course_obj->enabledWaitingList() ? 'Yes' : 'No';
307 
308  $this->xmlStartTag('Registration',$attr);
309 
310  if($this->course_obj->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_DEACTIVATED)
311  {
312  $this->xmlElement('Disabled');
313  }
314  elseif($this->course_obj->getSubscriptionLimitationType() == IL_CRS_SUBSCRIPTION_UNLIMITED)
315  {
316  $this->xmlElement('Unlimited');
317  }
318  else
319  {
320  $this->xmlStartTag('TemporarilyAvailable');
321  $this->xmlElement('Start',null,$this->course_obj->getSubscriptionStart());
322  $this->xmlElement('End',null,$this->course_obj->getSubscriptionEnd());
323  $this->xmlEndTag('TemporarilyAvailable');
324  }
325  if(strlen($pwd = $this->course_obj->getSubscriptionPassword()))
326  {
327  $this->xmlElement('Password',null,$pwd);
328  }
329  $this->xmlEndTag('Registration');
330 
331  // Sort
332  $attr = array();
333  if($this->course_obj->getOrderType() == ilContainer::SORT_MANUAL)
334  {
335  $attr['type'] = 'Manual';
336  }
337  elseif($this->course_obj->getOrderType() == ilContainer::SORT_TITLE)
338  {
339  $attr['type'] = 'Title';
340  }
341  else
342  {
343  $attr['type'] = 'Activation';
344  }
345  $this->xmlElement('Sort',$attr);
346 
347  // Archives
348  $attr = array();
349  if($this->course_obj->getViewMode() != IL_CRS_VIEW_ARCHIVE)
350  {
351  $attr['Access'] = 'Disabled';
352  }
353  elseif($this->course_obj->getViewMode() == IL_CRS_VIEW_ARCHIVE)
354  {
355  $attr['Access'] = 'Read';
356  }
357  if($this->course_obj->getArchiveType() == IL_CRS_ARCHIVE_DOWNLOAD)
358  {
359  $attr['Access'] = 'Download';
360  }
361  $this->xmlStartTag('Archive',$attr);
362 
363  $this->xmlElement('Start',null,$this->course_obj->getArchiveStart());
364  $this->xmlElement('End',null,$this->course_obj->getArchiveEnd());
365 
366  $this->xmlEndTag('Archive');
367 
368  $this->xmlEndTag('Settings');
369 
370  return true;
371  }
372 
373 
374  // recursive
375  function __buildObject($a_parent_id)
376  {
377  $this->course_obj->initCourseItemObject();
378  $this->course_obj->items_obj->setParentId($a_parent_id);
379 
380  foreach($this->course_obj->items_obj->getAllItems() as $item)
381  {
382 
383  if(!$tmp_obj =& ilObjectFactory::getInstanceByRefId($item['child'],false))
384  {
385  continue;
386  }
387 
388  $attr = array();
389  $attr['id'] = 'il_'.$this->ilias->getSetting('inst_id').'_'.$tmp_obj->getType().'_'.$item['child'];
390  $attr['type'] = $tmp_obj->getType();
391  $attr['Unlimited'] = $item['activation_unlimited'] ? 1 : 0;
392  $attr['Position'] = $item['position'];
393 
394  $this->xmlStartTag('Object',$attr);
395  $this->xmlElement('Title',null,$item['title']);
396  $this->xmlElement('Description',null,$item['description']);
397  $this->xmlElement('Start',null,$item['activation_start']);
398  $this->xmlElement('End',null,$item['activation_end']);
399 
400  if($item['type'] == 'file')
401  {
402  $this->xmlElement('FileType',null,$tmp_obj->getFileType());
403  }
404 
405  $this->__buildObject($item['child']);
406 
407  $this->xmlEndTag('Object');
408 
409  unset($tmp_obj);
410  }
411  }
412 
413  function __buildFooter()
414  {
415  $this->xmlEndTag('Course');
416  }
417 
423  function setAttachUsers ($value) {
424  $this->attach_users = $value ? true : false;
425  }
426 }
427 
428 
429 ?>