ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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 
49 
59  function ilCourseXMLParser($a_course_obj, $a_xml_file = '')
60  {
61  global $lng,$ilLog;
62 
63  parent::ilMDSaxParser($a_xml_file);
64 
65  $this->sax_controller = new ilSaxController();
66 
67  $this->log =& $ilLog;
68 
69  $this->course_obj = $a_course_obj;
70  $this->course_members = ilCourseParticipants::_getInstanceByObjId($this->course_obj->getId());
71  $this->course_waiting_list = new ilCourseWaitingList($this->course_obj->getId());
72  // flip the array so we can use array_key_exists
73  $this->course_members_array = array_flip($this->course_members->getParticipants());
74 
75  $this->md_obj = new ilMD($this->course_obj->getId(),0,'crs');
76  $this->setMDObject($this->md_obj);
77 
78  $this->lng =& $lng;
79  }
80 
87  function setHandlers($a_xml_parser)
88  {
89  $this->sax_controller->setHandlers($a_xml_parser);
90  $this->sax_controller->setDefaultElementHandler($this);
91 
92  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValueParser.php');
93  $this->sax_controller->setElementHandler(
94  $this->adv_md_handler = new ilAdvancedMDValueParser($this->course_obj->getId()),
95  'AdvancedMetaData');
96  }
97 
98 
99 
100 
108  function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
109  {
110  if($this->in_meta_data)
111  {
112  parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
113  return;
114  }
115 
116  switch($a_name)
117  {
118  case 'Course':
119 
120  if(strlen($a_attribs['importId']))
121  {
122  $this->log->write("CourseXMLParser: importId = ".$a_attribs['importId']);
123  $this->course_obj->setImportId($a_attribs['importId']);
124  ilObject::_writeImportId($this->course_obj->getId(),$a_attribs['importId']);
125  }
126  if(strlen($a_attribs['showMembers']))
127  {
128  $this->course_obj->setShowMembers(
129  $a_attribs['showMembers'] == 'Yes' ? true : false
130  );
131  }
132  break;
133 
134  case 'Admin':
135  if($id_data = $this->__parseId($a_attribs['id']))
136  {
137  if($id_data['local'] or $id_data['imported'])
138  {
139  $this->handleAdmin($a_attribs, $id_data);
140  }
141  }
142  break;
143 
144  case 'Tutor':
145  if($id_data = $this->__parseId($a_attribs['id']))
146  {
147  if($id_data['local'] or $id_data['imported'])
148  {
149  $this->handleTutor($a_attribs, $id_data);
150 
151  }
152  }
153  break;
154 
155  case 'Member':
156  if($id_data = $this->__parseId($a_attribs['id']))
157  {
158  if($id_data['local'] or $id_data['imported'])
159  {
160  $this->handleMember($a_attribs, $id_data);
161  }
162  }
163  break;
164 
165  case 'Subscriber':
166  if($id_data = $this->__parseId($a_attribs['id']))
167  {
168  if($id_data['local'] or $id_data['imported'])
169  {
170  $this->handleSubscriber($a_attribs, $id_data);
171  }
172  }
173  break;
174 
175  case 'WaitingList':
176  if($id_data = $this->__parseId($a_attribs['id']))
177  {
178  if($id_data['local'] or $id_data['imported'])
179  {
180  $this->handleWaitingList($a_attribs, $id_data);
181  }
182  }
183  break;
184 
185  case 'Owner':
186  if($id_data = $this->__parseId($a_attribs['id']))
187  {
188  if($id_data['local'] or $id_data['imported'])
189  {
190  $this->course_obj->setOwner($id_data['usr_id']);
191  $this->course_obj->updateOwner();
192  }
193  }
194  break;
195 
196 
197  case 'Settings':
198  $this->in_settings = true;
199  break;
200  case 'Availability':
201  $this->in_availability = true;
202  break;
203 
204  case 'NotAvailable':
205  if($this->in_availability)
206  {
207  $this->course_obj->setActivationType(IL_CRS_ACTIVATION_OFFLINE);
208  }
209  elseif($this->in_registration)
210  {
211  $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_DEACTIVATED);
212  }
213 
214  break;
215 
216  case 'Unlimited':
217  if($this->in_availability)
218  {
219  $this->course_obj->setOfflineStatus(false);
220  $this->course_obj->setActivationType(IL_CRS_ACTIVATION_UNLIMITED);
221  }
222  elseif($this->in_registration)
223  {
224  $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_UNLIMITED);
225  }
226 
227  break;
228  case 'TemporarilyAvailable':
229  if($this->in_availability)
230  {
231  $this->course_obj->setOfflineStatus(false);
232  $this->course_obj->setActivationType(IL_CRS_ACTIVATION_LIMITED);
233  }
234  elseif($this->in_registration)
235  {
236  $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_LIMITED);
237  }
238  break;
239 
240  case 'Start':
241  break;
242 
243  case 'End':
244  break;
245 
246  case 'Syllabus':
247  break;
248 
249  case 'Contact':
250  break;
251 
252  case 'Name':
253  case 'Responsibility':
254  case 'Phone':
255  case 'Email':
256  case 'Consultation':
257  break;
258 
259  case 'Registration':
260  $this->in_registration = true;
261 
262  switch($a_attribs['registrationType'])
263  {
264  case 'Confirmation':
265  $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_CONFIRMATION);
266  break;
267 
268  case 'Direct':
269  $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_DIRECT);
270  break;
271 
272  case 'Password':
273  $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_PASSWORD);
274  break;
275  }
276 
277  $this->course_obj->setSubscriptionMaxMembers((int) $a_attribs['maxMembers']);
278  $this->course_obj->enableSubscriptionMembershipLimitation($this->course_obj->getSubscriptionMaxMembers() > 0);
279  $this->course_obj->setSubscriptionNotify($a_attribs['notification'] == 'Yes' ? true : false);
280  $this->course_obj->enableWaitingList($a_attribs['waitingList'] == 'Yes' ? true : false);
281  break;
282 
283  case 'Sort':
284  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
285  ilContainerSortingSettings::_importContainerSortingSettings($a_attribs, $this->course_obj->getId());
286 
287  //#17837
288  $this->course_obj->setOrderType(
289  ilContainerSortingSettings::getInstanceByObjId($this->course_obj->getId())->getSortMode()
290  );
291  break;
292 
293 
294  case 'Archive':
295  $this->in_archive = true;
296  switch($a_attribs['Access'])
297  {
298  case 'Disabled':
299  $this->course_obj->setArchiveType(IL_CRS_ARCHIVE_NONE);
300  break;
301 
302  case 'Read':
303  $this->course_obj->setArchiveType(IL_CRS_ARCHIVE_NONE);
304  #$this->course_obj->setViewMode(IL_CRS_VIEW_ARCHIVE);
305  break;
306 
307  case 'Download':
308  #$this->course_obj->setViewMode(IL_CRS_VIEW_ARCHIVE);
309  $this->course_obj->setArchiveType(IL_CRS_ARCHIVE_DOWNLOAD);
310  break;
311  }
312  break;
313 
314  case 'Disabled':
315  $this->course_obj->getSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_DEACTIVATED);
316  break;
317 
318  case "MetaData":
319  $this->in_meta_data = true;
320  parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
321  break;
322 
323  case 'ContainerSetting':
324  $this->current_container_setting = $a_attribs['id'];
325  break;
326 
327  case 'Period':
328  $this->in_period = true;
329  break;
330 
331  case 'WaitingListAutoFill':
332  case 'CancellationEnd':
333  case 'MinMembers':
334  break;
335  }
336  }
337 
346  private function handleMember ($a_attribs, $id_data)
347  {
348  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
349  // if action not set, or set and attach
350  {
351  if (!array_key_exists($id_data['usr_id'], $this->course_members_array))
352  // add only if member is not yet assigned as tutor or admin
353  {
354  $this->course_members->add($id_data['usr_id'],IL_CRS_MEMBER);
355  if($a_attribs['blocked'] == 'Yes')
356  {
357  $this->course_members->updateBlocked($id_data['usr_id'],true);
358  }
359  if($a_attribs['passed'] == 'Yes')
360  {
361  $this->course_members->updatePassed($id_data['usr_id'],true);
362  }
363  $this->course_members_array[$id_data['usr_id']] = "added";
364  }
365  else
366  // the member does exist. Now update status etc. only
367  {
368  if($a_attribs['blocked'] == 'Yes')
369  {
370  $this->course_members->updateBlocked($id_data['usr_id'],true);
371  }
372  if($a_attribs['passed'] == 'Yes')
373  {
374  $this->course_members->updatePassed($id_data['usr_id'],true);
375  }
376  }
377  }
378  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isMember($id_data['usr_id']))
379  // if action set and detach and is member of course
380  {
381  $this->course_members->delete($id_data['usr_id']);
382  }
383 
384  }
385 
386 
394  private function handleAdmin ($a_attribs, $id_data)
395  {
396  global $rbacadmin;
397 
398  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
399  // if action not set, or attach
400  {
401  if (!array_key_exists($id_data['usr_id'], $this->course_members_array))
402  // add only if member is not assigned yet
403  {
404  $this->course_members->add($id_data['usr_id'],IL_CRS_ADMIN);
405  if($a_attribs['notification'] == 'Yes')
406  {
407  $this->course_members->updateNotification($id_data['usr_id'],true);
408  }
409  if($a_attribs['passed'] == 'Yes')
410  {
411  $this->course_members->updatePassed($id_data['usr_id'],true);
412  }
413  $this->course_members_array[$id_data['usr_id']] = "added";
414  }
415  else
416  // update
417  {
418  if($a_attribs['notification'] == 'Yes')
419  {
420  $this->course_members->updateNotification($id_data['usr_id'],true);
421  }
422  if($a_attribs['passed'] == 'Yes')
423  {
424  $this->course_members->updatePassed($id_data['usr_id'],true);
425  }
426  $this->course_members->updateBlocked($id_data['usr_id'],false);
427  }
428  }
429  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isAdmin($id_data['usr_id']))
430  // if action set and detach and is admin of course
431  {
432  $this->course_members->delete($id_data['usr_id']);
433  }
434 
435  }
436 
437 
445  private function handleTutor ($a_attribs, $id_data) {
446  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
447  // if action not set, or attach
448  {
449  if (!array_key_exists($id_data['usr_id'], $this->course_members_array))
450  // add only if member is not assigned yet
451  {
452  $this->course_members->add($id_data['usr_id'],IL_CRS_TUTOR);
453  if($a_attribs['notification'] == 'Yes')
454  {
455  $this->course_members->updateNotification($id_data['usr_id'],true);
456  }
457  if($a_attribs['passed'] == 'Yes')
458  {
459  $this->course_members->updatePassed($id_data['usr_id'],true);
460  }
461  $this->course_members_array[$id_data['usr_id']] = "added";
462  }
463  else
464  {
465  if($a_attribs['notification'] == 'Yes')
466  {
467  $this->course_members->updateNotification($id_data['usr_id'],true);
468  }
469  if($a_attribs['passed'] == 'Yes')
470  {
471  $this->course_members->updatePassed($id_data['usr_id'],true);
472  }
473  $this->course_members->updateBlocked($id_data['usr_id'],false);
474  }
475  }
476  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isTutor($id_data['usr_id']))
477  // if action set and detach and is tutor of course
478  {
479  $this->course_members->delete($id_data['usr_id']);
480  }
481 
482  }
483 
484 
485 
492  private function handleSubscriber ($a_attribs, $id_data)
493  {
494  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
495  // if action not set, or attach
496  {
497  if (!$this->course_members->isSubscriber($id_data['usr_id']))
498  // add only if not exist
499  {
500  $this->course_members->addSubscriber($id_data['usr_id']);
501  }
502  $this->course_members->updateSubscriptionTime($id_data['usr_id'],$a_attribs['subscriptionTime']);
503 
504  }
505  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isSubscriber($id_data['usr_id']))
506  // if action set and detach and is subscriber
507  {
508  $this->course_members->deleteSubscriber($id_data["usr_id"]);
509  }
510 
511  }
512 
519  private function handleWaitingList ($a_attribs, $id_data)
520  {
521  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
522  // if action not set, or attach
523  {
524  if (!$this->course_waiting_list->isOnList($id_data['usr_id']))
525  // add only if not exists
526  {
527  $this->course_waiting_list->addToList($id_data['usr_id']);
528  }
529  $this->course_waiting_list->updateSubscriptionTime($id_data['usr_id'],$a_attribs['subscriptionTime']);
530 
531  }
532  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_waiting_list->isOnList($id_data['usr_id']))
533  // if action set and detach and is on list
534  {
535  $this->course_waiting_list->removeFromList($id_data['usr_id']);
536  }
537 
538  }
539 
540 
547  function handlerEndTag($a_xml_parser,$a_name)
548  {
549  if($this->in_meta_data)
550  {
551  parent::handlerEndTag($a_xml_parser,$a_name);
552  }
553 
554  switch($a_name)
555  {
556  case 'Course':
557 
558  $this->log->write('CourseXMLParser: import_id = '.$this->course_obj->getImportId());
559  $this->course_obj->MDUpdateListener('General');
560  $this->course_obj->update();
561  $this->adv_md_handler->save();
562  break;
563 
564  case 'Settings':
565  $this->in_settings = false;
566  break;
567 
568  case 'Availability':
569  $this->in_availability = false;
570  break;
571 
572  case 'Registration':
573  $this->in_registration = false;
574  break;
575 
576  case 'Archive':
577  $this->in_archive = false;
578  break;
579 
580  case 'Start':
581  if($this->in_availability)
582  {
583  $this->course_obj->setActivationStart(trim($this->cdata));
584  }
585  if($this->in_registration)
586  {
587  $this->course_obj->setSubscriptionStart(trim($this->cdata));
588  }
589  if($this->in_archive)
590  {
591  $this->course_obj->setArchiveStart(trim($this->cdata));
592  }
593  if($this->in_period)
594  {
595  if((int)$this->cdata)
596  {
597  $this->course_obj->setCourseStart(new ilDate((int)$this->cdata, IL_CAL_UNIX));
598  }
599  }
600  break;
601 
602  case 'End':
603  if($this->in_availability)
604  {
605  $this->course_obj->setActivationEnd(trim($this->cdata));
606  }
607  if($this->in_registration)
608  {
609  $this->course_obj->setSubscriptionEnd(trim($this->cdata));
610  }
611  if($this->in_archive)
612  {
613  $this->course_obj->setArchiveEnd(trim($this->cdata));
614  }
615  if($this->in_period)
616  {
617  if((int)$this->cdata)
618  {
619  $this->course_obj->setCourseEnd(new ilDate((int)$this->cdata, IL_CAL_UNIX));
620  }
621  }
622  break;
623 
624  case 'Syllabus':
625  $this->course_obj->setSyllabus(trim($this->cdata));
626  break;
627 
628 
629  case 'ImportantInformation':
630  $this->course_obj->setImportantInformation(trim($this->cdata));
631  break;
632 
633  case 'Name':
634  $this->course_obj->setContactName(trim($this->cdata));
635  break;
636 
637  case 'Responsibility':
638  $this->course_obj->setContactResponsibility(trim($this->cdata));
639  break;
640 
641  case 'Phone':
642  $this->course_obj->setContactPhone(trim($this->cdata));
643  break;
644 
645  case 'Email':
646  $this->course_obj->setContactEmail(trim($this->cdata));
647  break;
648 
649  case 'Consultation':
650  $this->course_obj->setContactConsultation(trim($this->cdata));
651  break;
652 
653  case 'Password':
654  $this->course_obj->setSubscriptionPassword(trim($this->cdata));
655  break;
656 
657  case 'MetaData':
658  $this->in_meta_data = false;
659  parent::handlerEndTag($a_xml_parser,$a_name);
660  break;
661 
662  case 'ContainerSetting':
663  if($this->current_container_setting)
664  {
666  $this->course_obj->getId(),
668  $this->cdata);
669  }
670  break;
671 
672  case 'Period':
673  $this->in_period = false;
674  break;
675 
676  case 'WaitingListAutoFill':
677  $this->course_obj->setWaitingListAutoFill($this->cdata);
678  break;
679 
680  case 'CancellationEnd':
681  if((int)$this->cdata)
682  {
683  $this->course_obj->setCancellationEnd(new ilDate((int)$this->cdata, IL_CAL_UNIX));
684  }
685  break;
686 
687  case 'MinMembers':
688  if((int)$this->cdata)
689  {
690  $this->course_obj->setSubscriptionMinMembers((int)$this->cdata);
691  }
692  break;
693  }
694  $this->cdata = '';
695 
696  return;
697  }
698 
705  function handlerCharacterData($a_xml_parser,$a_data)
706  {
707  // call meta data handler
708  if($this->in_meta_data)
709  {
710  parent::handlerCharacterData($a_xml_parser,$a_data);
711  }
712  if($a_data != "\n")
713  {
714  // Replace multiple tabs with one space
715  $a_data = preg_replace("/\t+/"," ",$a_data);
716 
717  $this->cdata .= $a_data;
718  }
719  }
720 
721  // PRIVATE
722  function __parseId($a_id)
723  {
724  global $ilias;
725 
726  $fields = explode('_',$a_id);
727 
728  if(!is_array($fields) or
729  $fields[0] != 'il' or
730  !is_numeric($fields[1]) or
731  $fields[2] != 'usr' or
732  !is_numeric($fields[3]))
733  {
734  return false;
735  }
736  if($id = ilObjUser::_getImportedUserId($a_id))
737  {
738  return array('imported' => true,
739  'local' => false,
740  'usr_id' => $id);
741  }
742  if(($fields[1] == $ilias->getSetting('inst_id',0)) and strlen(ilObjUser::_lookupLogin($fields[3])))
743  {
744  return array('imported' => false,
745  'local' => true,
746  'usr_id' => $fields[3]);
747  }
748  return false;
749  }
750 
751 }
752 ?>
static _lookupLogin($a_user_id)
lookup login
const IL_CRS_ACTIVATION_LIMITED
const IL_CRS_SUBSCRIPTION_LIMITED
ilCourseXMLParser($a_course_obj, $a_xml_file='')
Constructor.
static _importContainerSortingSettings($attibs, $obj_id)
sorting import for all container objects
handleMember($a_attribs, $id_data)
attach or detach user/member/admin from course member
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
setHandlers($a_xml_parser)
set event handlers
_writeContainerSetting($a_id, $a_keyword, $a_value)
handleAdmin($a_attribs, $id_data)
attach or detach admin from course member
const IL_CRS_TUTOR
const IL_CRS_SUBSCRIPTION_CONFIRMATION
const IL_CAL_UNIX
handleWaitingList($a_attribs, $id_data)
attach or detach members from waitinglist
const IL_CRS_ARCHIVE_NONE
_getImportedUserId($i2_id)
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
const IL_CRS_MEMBER
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
const IL_CRS_SUBSCRIPTION_PASSWORD
_writeImportId($a_obj_id, $a_import_id)
write import id to db (static)
Class for single dates.
const IL_CRS_ACTIVATION_OFFLINE
const IL_CRS_SUBSCRIPTION_UNLIMITED
handleTutor($a_attribs, $id_data)
attach or detach admin from course member
const IL_CRS_ADMIN
Base class for course and group participants.
Interface definition for sax subset parsers.
Controller class for sax element handlers.
const IL_CRS_ARCHIVE_DOWNLOAD
const IL_CRS_SUBSCRIPTION_DIRECT
static getInstanceByObjId($a_obj_id)
Get singleton instance.
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
handleSubscriber($a_attribs, $id_data)
attach or detach members from subscribers
const IL_CRS_SUBSCRIPTION_DEACTIVATED
const IL_CRS_ACTIVATION_UNLIMITED