ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCourseXMLParser.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 
25 include_once("Services/MetaData/classes/class.ilMDSaxParser.php");
26 include_once("Services/MetaData/classes/class.ilMD.php");
27 include_once('Services/Utilities/interfaces/interface.ilSaxSubsetParser.php');
28 include_once('Services/Utilities/classes/class.ilSaxController.php');
29 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
30 include_once 'Modules/Course/classes/class.ilCourseWaitingList.php';
31 include_once 'Modules/Course/classes/class.ilCourseConstants.php';
32 
33 
34 
44 {
45  var $lng;
46  var $md_obj = null; // current meta data object
47 
57  function ilCourseXMLParser($a_course_obj, $a_xml_file = '')
58  {
59  global $lng,$ilLog;
60 
61  parent::ilMDSaxParser($a_xml_file);
62 
63  $this->sax_controller = new ilSaxController();
64 
65  $this->log =& $ilLog;
66 
67  $this->course_obj = $a_course_obj;
68  $this->course_members = ilCourseParticipants::_getInstanceByObjId($this->course_obj->getId());
69  $this->course_waiting_list = new ilCourseWaitingList($this->course_obj->getId());
70  // flip the array so we can use array_key_exists
71  $this->course_members_array = array_flip($this->course_members->getParticipants());
72 
73  $this->md_obj = new ilMD($this->course_obj->getId(),0,'crs');
74  $this->setMDObject($this->md_obj);
75 
76  $this->lng =& $lng;
77  }
78 
85  function setHandlers($a_xml_parser)
86  {
87  $this->sax_controller->setHandlers($a_xml_parser);
88  $this->sax_controller->setDefaultElementHandler($this);
89 
90  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValueParser.php');
91  $this->sax_controller->setElementHandler(
92  $this->adv_md_handler = new ilAdvancedMDValueParser($this->course_obj->getId()),
93  'AdvancedMetaData');
94  }
95 
96 
97 
98 
106  function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
107  {
108  if($this->in_meta_data)
109  {
110  parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
111  return;
112  }
113 
114  switch($a_name)
115  {
116  case 'Course':
117 
118  if(strlen($a_attribs['importId']))
119  {
120  $this->log->write("CourseXMLParser: importId = ".$a_attribs['importId']);
121  $this->course_obj->setImportId($a_attribs['importId']);
122  ilObject::_writeImportId($this->course_obj->getId(),$a_attribs['importId']);
123  }
124  if(strlen($a_attribs['showMembers']))
125  {
126  $this->course_obj->setShowMembers(
127  $a_attribs['showMembers'] == 'Yes' ? true : false
128  );
129  }
130  break;
131 
132  case 'Admin':
133  if($id_data = $this->__parseId($a_attribs['id']))
134  {
135  if($id_data['local'] or $id_data['imported'])
136  {
137  $this->handleAdmin($a_attribs, $id_data);
138  }
139  }
140  break;
141 
142  case 'Tutor':
143  if($id_data = $this->__parseId($a_attribs['id']))
144  {
145  if($id_data['local'] or $id_data['imported'])
146  {
147  $this->handleTutor($a_attribs, $id_data);
148 
149  }
150  }
151  break;
152 
153  case 'Member':
154  if($id_data = $this->__parseId($a_attribs['id']))
155  {
156  if($id_data['local'] or $id_data['imported'])
157  {
158  $this->handleMember($a_attribs, $id_data);
159  }
160  }
161  break;
162 
163  case 'Subscriber':
164  if($id_data = $this->__parseId($a_attribs['id']))
165  {
166  if($id_data['local'] or $id_data['imported'])
167  {
168  $this->handleSubscriber($a_attribs, $id_data);
169  }
170  }
171  break;
172 
173  case 'WaitingList':
174  if($id_data = $this->__parseId($a_attribs['id']))
175  {
176  if($id_data['local'] or $id_data['imported'])
177  {
178  $this->handleWaitingList($a_attribs, $id_data);
179  }
180  }
181  break;
182 
183 
184  case 'Settings':
185  $this->in_settings = true;
186  break;
187  case 'Availability':
188  $this->in_availability = true;
189  break;
190 
191  case 'NotAvailable':
192  if($this->in_availability)
193  {
194  $this->course_obj->setActivationType(IL_CRS_ACTIVATION_OFFLINE);
195  }
196  elseif($this->in_registration)
197  {
198  $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_DEACTIVATED);
199  }
200 
201  break;
202 
203  case 'Unlimited':
204  if($this->in_availability)
205  {
206  $this->course_obj->setOfflineStatus(false);
207  $this->course_obj->setActivationType(IL_CRS_ACTIVATION_UNLIMITED);
208  }
209  elseif($this->in_registration)
210  {
211  $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_UNLIMITED);
212  }
213 
214  break;
215  case 'TemporarilyAvailable':
216  if($this->in_availability)
217  {
218  $this->course_obj->setOfflineStatus(false);
219  $this->course_obj->setActivationType(IL_CRS_ACTIVATION_LIMITED);
220  }
221  elseif($this->in_registration)
222  {
223  $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_LIMITED);
224  }
225  break;
226 
227  case 'Start':
228  break;
229 
230  case 'End':
231  break;
232 
233  case 'Syllabus':
234  break;
235 
236  case 'Contact':
237  break;
238 
239  case 'Name':
240  case 'Responsibility':
241  case 'Phone':
242  case 'Email':
243  case 'Consultation':
244  break;
245 
246  case 'Registration':
247  $this->in_registration = true;
248 
249  switch($a_attribs['registrationType'])
250  {
251  case 'Confirmation':
252  $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_CONFIRMATION);
253  break;
254 
255  case 'Direct':
256  $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_DIRECT);
257  break;
258 
259  case 'Password':
260  $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_PASSWORD);
261  break;
262  }
263 
264  $this->course_obj->setSubscriptionMaxMembers((int) $a_attribs['maxMembers']);
265  $this->course_obj->enableSubscriptionMembershipLimitation($this->course_obj->getSubscriptionMaxMembers() > 0);
266  $this->course_obj->setSubscriptionNotify($a_attribs['notification'] == 'Yes' ? true : false);
267  $this->course_obj->enableWaitingList($a_attribs['waitingList'] == 'Yes' ? true : false);
268  break;
269 
270  case 'Sort':
271  switch($a_attribs['type'])
272  {
273  case 'Manual':
274  $this->course_obj->setOrderType(ilContainer::SORT_MANUAL);
275  break;
276 
277  case 'Title':
278  $this->course_obj->setOrderType(ilContainer::SORT_TITLE);
279  break;
280 
281  case 'Activation':
282  $this->course_obj->setOrderType(ilContainer::SORT_ACTIVATION);
283  break;
284  }
285  break;
286 
287 
288  case 'Archive':
289  $this->in_archive = true;
290  switch($a_attribs['Access'])
291  {
292  case 'Disabled':
293  $this->course_obj->setArchiveType(IL_CRS_ARCHIVE_NONE);
294  break;
295 
296  case 'Read':
297  $this->course_obj->setArchiveType(IL_CRS_ARCHIVE_NONE);
298  #$this->course_obj->setViewMode(IL_CRS_VIEW_ARCHIVE);
299  break;
300 
301  case 'Download':
302  #$this->course_obj->setViewMode(IL_CRS_VIEW_ARCHIVE);
303  $this->course_obj->setArchiveType(IL_CRS_ARCHIVE_DOWNLOAD);
304  break;
305  }
306  break;
307 
308  case 'Disabled':
309  $this->course_obj->getSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_DEACTIVATED);
310  break;
311 
312  case "MetaData":
313  $this->in_meta_data = true;
314  parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
315  break;
316 
317  }
318  }
319 
328  private function handleMember ($a_attribs, $id_data)
329  {
330  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
331  // if action not set, or set and attach
332  {
333  if (!array_key_exists($id_data['usr_id'], $this->course_members_array))
334  // add only if member is not yet assigned as tutor or admin
335  {
336  $this->course_members->add($id_data['usr_id'],IL_CRS_MEMBER);
337  if($a_attribs['blocked'] == 'Yes')
338  {
339  $this->course_members->updateBlocked($id_data['usr_id'],true);
340  }
341  if($a_attribs['passed'] == 'Yes')
342  {
343  $this->course_members->updatePassed($id_data['usr_id'],true);
344  }
345  $this->course_members_array[$id_data['usr_id']] = "added";
346  }
347  else
348  // the member does exist. Now update status etc. only
349  {
350  if($a_attribs['blocked'] == 'Yes')
351  {
352  $this->course_members->updateBlocked($id_data['usr_id'],true);
353  }
354  if($a_attribs['passed'] == 'Yes')
355  {
356  $this->course_members->updatePassed($id_data['usr_id'],true);
357  }
358  }
359  }
360  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isMember($id_data['usr_id']))
361  // if action set and detach and is member of course
362  {
363  $this->course_members->delete($id_data['usr_id']);
364  }
365 
366  }
367 
368 
376  private function handleAdmin ($a_attribs, $id_data)
377  {
378  global $rbacadmin;
379 
380  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
381  // if action not set, or attach
382  {
383  if (!array_key_exists($id_data['usr_id'], $this->course_members_array))
384  // add only if member is not assigned yet
385  {
386  $this->course_members->add($id_data['usr_id'],IL_CRS_ADMIN);
387  if($a_attribs['notification'] == 'Yes')
388  {
389  $this->course_members->updateNotification($id_data['usr_id'],true);
390  }
391  if($a_attribs['passed'] == 'Yes')
392  {
393  $this->course_members->updatePassed($id_data['usr_id'],true);
394  }
395  $this->course_members_array[$id_data['usr_id']] = "added";
396  }
397  else
398  // update
399  {
400  if($a_attribs['notification'] == 'Yes')
401  {
402  $this->course_members->updateNotification($id_data['usr_id'],true);
403  }
404  if($a_attribs['passed'] == 'Yes')
405  {
406  $this->course_members->updatePassed($id_data['usr_id'],true);
407  }
408  $this->course_members->updateBlocked($id_data['usr_id'],false);
409  }
410  }
411  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isAdmin($id_data['usr_id']))
412  // if action set and detach and is admin of course
413  {
414  $this->course_members->delete($id_data['usr_id']);
415  }
416 
417  }
418 
419 
427  private function handleTutor ($a_attribs, $id_data) {
428  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
429  // if action not set, or attach
430  {
431  if (!array_key_exists($id_data['usr_id'], $this->course_members_array))
432  // add only if member is not assigned yet
433  {
434  $this->course_members->add($id_data['usr_id'],IL_CRS_TUTOR);
435  if($a_attribs['notification'] == 'Yes')
436  {
437  $this->course_members->updateNotification($id_data['usr_id'],true);
438  }
439  if($a_attribs['passed'] == 'Yes')
440  {
441  $this->course_members->updatePassed($id_data['usr_id'],true);
442  }
443  $this->course_members_array[$id_data['usr_id']] = "added";
444  }
445  else
446  {
447  if($a_attribs['notification'] == 'Yes')
448  {
449  $this->course_members->updateNotification($id_data['usr_id'],true);
450  }
451  if($a_attribs['passed'] == 'Yes')
452  {
453  $this->course_members->updatePassed($id_data['usr_id'],true);
454  }
455  $this->course_members->updateBlocked($id_data['usr_id'],false);
456  }
457  }
458  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isTutor($id_data['usr_id']))
459  // if action set and detach and is tutor of course
460  {
461  $this->course_members->delete($id_data['usr_id']);
462  }
463 
464  }
465 
466 
467 
474  private function handleSubscriber ($a_attribs, $id_data)
475  {
476  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
477  // if action not set, or attach
478  {
479  if (!$this->course_members->isSubscriber($id_data['usr_id']))
480  // add only if not exist
481  {
482  $this->course_members->addSubscriber($id_data['usr_id']);
483  }
484  $this->course_members->updateSubscriptionTime($id_data['usr_id'],$a_attribs['subscriptionTime']);
485 
486  }
487  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isSubscriber($id_data['usr_id']))
488  // if action set and detach and is subscriber
489  {
490  $this->course_members->deleteSubscriber($id_data["usr_id"]);
491  }
492 
493  }
494 
501  private function handleWaitingList ($a_attribs, $id_data)
502  {
503  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
504  // if action not set, or attach
505  {
506  if (!$this->course_waiting_list->isOnList($id_data['usr_id']))
507  // add only if not exists
508  {
509  $this->course_waiting_list->addToList($id_data['usr_id']);
510  }
511  $this->course_waiting_list->updateSubscriptionTime($id_data['usr_id'],$a_attribs['subscriptionTime']);
512 
513  }
514  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_waiting_list->isOnList($id_data['usr_id']))
515  // if action set and detach and is on list
516  {
517  $this->course_waiting_list->removeFromList($id_data['usr_id']);
518  }
519 
520  }
521 
522 
529  function handlerEndTag($a_xml_parser,$a_name)
530  {
531  if($this->in_meta_data)
532  {
533  parent::handlerEndTag($a_xml_parser,$a_name);
534  }
535 
536  switch($a_name)
537  {
538  case 'Course':
539 
540  $this->log->write('CourseXMLParser: import_id = '.$this->course_obj->getImportId());
541  $this->course_obj->MDUpdateListener('General');
542  $this->course_obj->update();
543  $this->adv_md_handler->save();
544  break;
545 
546  case 'Settings':
547  $this->in_settings = false;
548  break;
549 
550  case 'Availability':
551  $this->in_availability = false;
552  break;
553 
554  case 'Registration':
555  $this->in_registration = false;
556  break;
557 
558  case 'Archive':
559  $this->in_archive = false;
560  break;
561 
562  case 'Start':
563  if($this->in_availability)
564  {
565  $this->course_obj->setActivationStart(trim($this->cdata));
566  }
567  if($this->in_registration)
568  {
569  $this->course_obj->setSubscriptionStart(trim($this->cdata));
570  }
571  if($this->in_archive)
572  {
573  $this->course_obj->setArchiveStart(trim($this->cdata));
574  }
575  break;
576 
577  case 'End':
578  if($this->in_availability)
579  {
580  $this->course_obj->setActivationEnd(trim($this->cdata));
581  }
582  if($this->in_registration)
583  {
584  $this->course_obj->setSubscriptionEnd(trim($this->cdata));
585  }
586  if($this->in_archive)
587  {
588  $this->course_obj->setArchiveEnd(trim($this->cdata));
589  }
590  break;
591 
592  case 'Syllabus':
593  $this->course_obj->setSyllabus(trim($this->cdata));
594  break;
595 
596 
597  case 'ImportantInformation':
598  $this->course_obj->setImportantInformation(trim($this->cdata));
599  break;
600 
601  case 'Name':
602  $this->course_obj->setContactName(trim($this->cdata));
603  break;
604 
605  case 'Responsibility':
606  $this->course_obj->setContactResponsibility(trim($this->cdata));
607  break;
608 
609  case 'Phone':
610  $this->course_obj->setContactPhone(trim($this->cdata));
611  break;
612 
613  case 'Email':
614  $this->course_obj->setContactEmail(trim($this->cdata));
615  break;
616 
617  case 'Consultation':
618  $this->course_obj->setContactConsultation(trim($this->cdata));
619  break;
620 
621  case 'Password':
622  $this->course_obj->setSubscriptionPassword(trim($this->cdata));
623  break;
624 
625  case 'MetaData':
626  $this->in_meta_data = false;
627  parent::handlerEndTag($a_xml_parser,$a_name);
628  break;
629  }
630  $this->cdata = '';
631 
632  return;
633  }
634 
641  function handlerCharacterData($a_xml_parser,$a_data)
642  {
643  // call meta data handler
644  if($this->in_meta_data)
645  {
646  parent::handlerCharacterData($a_xml_parser,$a_data);
647  }
648  if($a_data != "\n")
649  {
650  // Replace multiple tabs with one space
651  $a_data = preg_replace("/\t+/"," ",$a_data);
652 
653  $this->cdata .= $a_data;
654  }
655  }
656 
657  // PRIVATE
658  function __parseId($a_id)
659  {
660  global $ilias;
661 
662  $fields = explode('_',$a_id);
663 
664  if(!is_array($fields) or
665  $fields[0] != 'il' or
666  !is_numeric($fields[1]) or
667  $fields[2] != 'usr' or
668  !is_numeric($fields[3]))
669  {
670  return false;
671  }
672  if($id = ilObjUser::_getImportedUserId($a_id))
673  {
674  return array('imported' => true,
675  'local' => false,
676  'usr_id' => $id);
677  }
678  if(($fields[1] == $ilias->getSetting('inst_id',0)) and strlen(ilObjUser::_lookupLogin($fields[3])))
679  {
680  return array('imported' => false,
681  'local' => true,
682  'usr_id' => $fields[3]);
683  }
684  return false;
685  }
686 
687 }
688 ?>