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