ILIAS  Release_4_4_x_branch Revision 61816
 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  case 'Owner':
184  if($id_data = $this->__parseId($a_attribs['id']))
185  {
186  if($id_data['local'] or $id_data['imported'])
187  {
188  $this->course_obj->setOwner($id_data['usr_id']);
189  $this->course_obj->updateOwner();
190  }
191  }
192  break;
193 
194 
195  case 'Settings':
196  $this->in_settings = true;
197  break;
198  case 'Availability':
199  $this->in_availability = true;
200  break;
201 
202  case 'NotAvailable':
203  if($this->in_availability)
204  {
205  $this->course_obj->setActivationType(IL_CRS_ACTIVATION_OFFLINE);
206  }
207  elseif($this->in_registration)
208  {
209  $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_DEACTIVATED);
210  }
211 
212  break;
213 
214  case 'Unlimited':
215  if($this->in_availability)
216  {
217  $this->course_obj->setOfflineStatus(false);
218  $this->course_obj->setActivationType(IL_CRS_ACTIVATION_UNLIMITED);
219  }
220  elseif($this->in_registration)
221  {
222  $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_UNLIMITED);
223  }
224 
225  break;
226  case 'TemporarilyAvailable':
227  if($this->in_availability)
228  {
229  $this->course_obj->setOfflineStatus(false);
230  $this->course_obj->setActivationType(IL_CRS_ACTIVATION_LIMITED);
231  }
232  elseif($this->in_registration)
233  {
234  $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_LIMITED);
235  }
236  break;
237 
238  case 'Start':
239  break;
240 
241  case 'End':
242  break;
243 
244  case 'Syllabus':
245  break;
246 
247  case 'Contact':
248  break;
249 
250  case 'Name':
251  case 'Responsibility':
252  case 'Phone':
253  case 'Email':
254  case 'Consultation':
255  break;
256 
257  case 'Registration':
258  $this->in_registration = true;
259 
260  switch($a_attribs['registrationType'])
261  {
262  case 'Confirmation':
263  $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_CONFIRMATION);
264  break;
265 
266  case 'Direct':
267  $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_DIRECT);
268  break;
269 
270  case 'Password':
271  $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_PASSWORD);
272  break;
273  }
274 
275  $this->course_obj->setSubscriptionMaxMembers((int) $a_attribs['maxMembers']);
276  $this->course_obj->enableSubscriptionMembershipLimitation($this->course_obj->getSubscriptionMaxMembers() > 0);
277  $this->course_obj->setSubscriptionNotify($a_attribs['notification'] == 'Yes' ? true : false);
278  $this->course_obj->enableWaitingList($a_attribs['waitingList'] == 'Yes' ? true : false);
279  break;
280 
281  case 'Sort':
282  switch($a_attribs['type'])
283  {
284  case 'Manual':
285  $this->course_obj->setOrderType(ilContainer::SORT_MANUAL);
286  break;
287 
288  case 'Title':
289  $this->course_obj->setOrderType(ilContainer::SORT_TITLE);
290  break;
291 
292  case 'Activation':
293  $this->course_obj->setOrderType(ilContainer::SORT_ACTIVATION);
294  break;
295  }
296  break;
297 
298 
299  case 'Archive':
300  $this->in_archive = true;
301  switch($a_attribs['Access'])
302  {
303  case 'Disabled':
304  $this->course_obj->setArchiveType(IL_CRS_ARCHIVE_NONE);
305  break;
306 
307  case 'Read':
308  $this->course_obj->setArchiveType(IL_CRS_ARCHIVE_NONE);
309  #$this->course_obj->setViewMode(IL_CRS_VIEW_ARCHIVE);
310  break;
311 
312  case 'Download':
313  #$this->course_obj->setViewMode(IL_CRS_VIEW_ARCHIVE);
314  $this->course_obj->setArchiveType(IL_CRS_ARCHIVE_DOWNLOAD);
315  break;
316  }
317  break;
318 
319  case 'Disabled':
320  $this->course_obj->getSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_DEACTIVATED);
321  break;
322 
323  case "MetaData":
324  $this->in_meta_data = true;
325  parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
326  break;
327 
328  }
329  }
330 
339  private function handleMember ($a_attribs, $id_data)
340  {
341  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
342  // if action not set, or set and attach
343  {
344  if (!array_key_exists($id_data['usr_id'], $this->course_members_array))
345  // add only if member is not yet assigned as tutor or admin
346  {
347  $this->course_members->add($id_data['usr_id'],IL_CRS_MEMBER);
348  if($a_attribs['blocked'] == 'Yes')
349  {
350  $this->course_members->updateBlocked($id_data['usr_id'],true);
351  }
352  if($a_attribs['passed'] == 'Yes')
353  {
354  $this->course_members->updatePassed($id_data['usr_id'],true);
355  }
356  $this->course_members_array[$id_data['usr_id']] = "added";
357  }
358  else
359  // the member does exist. Now update status etc. only
360  {
361  if($a_attribs['blocked'] == 'Yes')
362  {
363  $this->course_members->updateBlocked($id_data['usr_id'],true);
364  }
365  if($a_attribs['passed'] == 'Yes')
366  {
367  $this->course_members->updatePassed($id_data['usr_id'],true);
368  }
369  }
370  }
371  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isMember($id_data['usr_id']))
372  // if action set and detach and is member of course
373  {
374  $this->course_members->delete($id_data['usr_id']);
375  }
376 
377  }
378 
379 
387  private function handleAdmin ($a_attribs, $id_data)
388  {
389  global $rbacadmin;
390 
391  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
392  // if action not set, or attach
393  {
394  if (!array_key_exists($id_data['usr_id'], $this->course_members_array))
395  // add only if member is not assigned yet
396  {
397  $this->course_members->add($id_data['usr_id'],IL_CRS_ADMIN);
398  if($a_attribs['notification'] == 'Yes')
399  {
400  $this->course_members->updateNotification($id_data['usr_id'],true);
401  }
402  if($a_attribs['passed'] == 'Yes')
403  {
404  $this->course_members->updatePassed($id_data['usr_id'],true);
405  }
406  $this->course_members_array[$id_data['usr_id']] = "added";
407  }
408  else
409  // update
410  {
411  if($a_attribs['notification'] == 'Yes')
412  {
413  $this->course_members->updateNotification($id_data['usr_id'],true);
414  }
415  if($a_attribs['passed'] == 'Yes')
416  {
417  $this->course_members->updatePassed($id_data['usr_id'],true);
418  }
419  $this->course_members->updateBlocked($id_data['usr_id'],false);
420  }
421  }
422  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isAdmin($id_data['usr_id']))
423  // if action set and detach and is admin of course
424  {
425  $this->course_members->delete($id_data['usr_id']);
426  }
427 
428  }
429 
430 
438  private function handleTutor ($a_attribs, $id_data) {
439  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
440  // if action not set, or attach
441  {
442  if (!array_key_exists($id_data['usr_id'], $this->course_members_array))
443  // add only if member is not assigned yet
444  {
445  $this->course_members->add($id_data['usr_id'],IL_CRS_TUTOR);
446  if($a_attribs['notification'] == 'Yes')
447  {
448  $this->course_members->updateNotification($id_data['usr_id'],true);
449  }
450  if($a_attribs['passed'] == 'Yes')
451  {
452  $this->course_members->updatePassed($id_data['usr_id'],true);
453  }
454  $this->course_members_array[$id_data['usr_id']] = "added";
455  }
456  else
457  {
458  if($a_attribs['notification'] == 'Yes')
459  {
460  $this->course_members->updateNotification($id_data['usr_id'],true);
461  }
462  if($a_attribs['passed'] == 'Yes')
463  {
464  $this->course_members->updatePassed($id_data['usr_id'],true);
465  }
466  $this->course_members->updateBlocked($id_data['usr_id'],false);
467  }
468  }
469  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isTutor($id_data['usr_id']))
470  // if action set and detach and is tutor of course
471  {
472  $this->course_members->delete($id_data['usr_id']);
473  }
474 
475  }
476 
477 
478 
485  private function handleSubscriber ($a_attribs, $id_data)
486  {
487  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
488  // if action not set, or attach
489  {
490  if (!$this->course_members->isSubscriber($id_data['usr_id']))
491  // add only if not exist
492  {
493  $this->course_members->addSubscriber($id_data['usr_id']);
494  }
495  $this->course_members->updateSubscriptionTime($id_data['usr_id'],$a_attribs['subscriptionTime']);
496 
497  }
498  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isSubscriber($id_data['usr_id']))
499  // if action set and detach and is subscriber
500  {
501  $this->course_members->deleteSubscriber($id_data["usr_id"]);
502  }
503 
504  }
505 
512  private function handleWaitingList ($a_attribs, $id_data)
513  {
514  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
515  // if action not set, or attach
516  {
517  if (!$this->course_waiting_list->isOnList($id_data['usr_id']))
518  // add only if not exists
519  {
520  $this->course_waiting_list->addToList($id_data['usr_id']);
521  }
522  $this->course_waiting_list->updateSubscriptionTime($id_data['usr_id'],$a_attribs['subscriptionTime']);
523 
524  }
525  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_waiting_list->isOnList($id_data['usr_id']))
526  // if action set and detach and is on list
527  {
528  $this->course_waiting_list->removeFromList($id_data['usr_id']);
529  }
530 
531  }
532 
533 
540  function handlerEndTag($a_xml_parser,$a_name)
541  {
542  if($this->in_meta_data)
543  {
544  parent::handlerEndTag($a_xml_parser,$a_name);
545  }
546 
547  switch($a_name)
548  {
549  case 'Course':
550 
551  $this->log->write('CourseXMLParser: import_id = '.$this->course_obj->getImportId());
552  $this->course_obj->MDUpdateListener('General');
553  $this->course_obj->update();
554  $this->adv_md_handler->save();
555  break;
556 
557  case 'Settings':
558  $this->in_settings = false;
559  break;
560 
561  case 'Availability':
562  $this->in_availability = false;
563  break;
564 
565  case 'Registration':
566  $this->in_registration = false;
567  break;
568 
569  case 'Archive':
570  $this->in_archive = false;
571  break;
572 
573  case 'Start':
574  if($this->in_availability)
575  {
576  $this->course_obj->setActivationStart(trim($this->cdata));
577  }
578  if($this->in_registration)
579  {
580  $this->course_obj->setSubscriptionStart(trim($this->cdata));
581  }
582  if($this->in_archive)
583  {
584  $this->course_obj->setArchiveStart(trim($this->cdata));
585  }
586  break;
587 
588  case 'End':
589  if($this->in_availability)
590  {
591  $this->course_obj->setActivationEnd(trim($this->cdata));
592  }
593  if($this->in_registration)
594  {
595  $this->course_obj->setSubscriptionEnd(trim($this->cdata));
596  }
597  if($this->in_archive)
598  {
599  $this->course_obj->setArchiveEnd(trim($this->cdata));
600  }
601  break;
602 
603  case 'Syllabus':
604  $this->course_obj->setSyllabus(trim($this->cdata));
605  break;
606 
607 
608  case 'ImportantInformation':
609  $this->course_obj->setImportantInformation(trim($this->cdata));
610  break;
611 
612  case 'Name':
613  $this->course_obj->setContactName(trim($this->cdata));
614  break;
615 
616  case 'Responsibility':
617  $this->course_obj->setContactResponsibility(trim($this->cdata));
618  break;
619 
620  case 'Phone':
621  $this->course_obj->setContactPhone(trim($this->cdata));
622  break;
623 
624  case 'Email':
625  $this->course_obj->setContactEmail(trim($this->cdata));
626  break;
627 
628  case 'Consultation':
629  $this->course_obj->setContactConsultation(trim($this->cdata));
630  break;
631 
632  case 'Password':
633  $this->course_obj->setSubscriptionPassword(trim($this->cdata));
634  break;
635 
636  case 'MetaData':
637  $this->in_meta_data = false;
638  parent::handlerEndTag($a_xml_parser,$a_name);
639  break;
640  }
641  $this->cdata = '';
642 
643  return;
644  }
645 
652  function handlerCharacterData($a_xml_parser,$a_data)
653  {
654  // call meta data handler
655  if($this->in_meta_data)
656  {
657  parent::handlerCharacterData($a_xml_parser,$a_data);
658  }
659  if($a_data != "\n")
660  {
661  // Replace multiple tabs with one space
662  $a_data = preg_replace("/\t+/"," ",$a_data);
663 
664  $this->cdata .= $a_data;
665  }
666  }
667 
668  // PRIVATE
669  function __parseId($a_id)
670  {
671  global $ilias;
672 
673  $fields = explode('_',$a_id);
674 
675  if(!is_array($fields) or
676  $fields[0] != 'il' or
677  !is_numeric($fields[1]) or
678  $fields[2] != 'usr' or
679  !is_numeric($fields[3]))
680  {
681  return false;
682  }
683  if($id = ilObjUser::_getImportedUserId($a_id))
684  {
685  return array('imported' => true,
686  'local' => false,
687  'usr_id' => $id);
688  }
689  if(($fields[1] == $ilias->getSetting('inst_id',0)) and strlen(ilObjUser::_lookupLogin($fields[3])))
690  {
691  return array('imported' => false,
692  'local' => true,
693  'usr_id' => $fields[3]);
694  }
695  return false;
696  }
697 
698 }
699 ?>