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