ILIAS  Release_4_0_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 
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  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
472  // if action not set, or attach
473  {
474  if (!$this->course_members->isSubscriber($id_data['usr_id']))
475  // add only if not exist
476  {
477  $this->course_members->addSubscriber($id_data['usr_id']);
478  }
479  $this->course_members->updateSubscriptionTime($id_data['usr_id'],$a_attribs['subscriptionTime']);
480 
481  }
482  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isSubscriber($id_data['usr_id']))
483  // if action set and detach and is subscriber
484  {
485  $this->course_members->deleteSubscriber($id_data["usr_id"]);
486  }
487 
488  }
489 
496  private function handleWaitingList ($a_attribs, $id_data)
497  {
498  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
499  // if action not set, or attach
500  {
501  if (!$this->course_waiting_list->isOnList($id_data['usr_id']))
502  // add only if not exists
503  {
504  $this->course_waiting_list->addToList($id_data['usr_id']);
505  }
506  $this->course_waiting_list->updateSubscriptionTime($id_data['usr_id'],$a_attribs['subscriptionTime']);
507 
508  }
509  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_waiting_list->isOnList($id_data['usr_id']))
510  // if action set and detach and is on list
511  {
512  $this->course_waiting_list->removeFromList($id_data['usr_id']);
513  }
514 
515  }
516 
517 
524  function handlerEndTag($a_xml_parser,$a_name)
525  {
526  if($this->in_meta_data)
527  {
528  parent::handlerEndTag($a_xml_parser,$a_name);
529  }
530 
531  switch($a_name)
532  {
533  case 'Course':
534 
535  $this->log->write('CourseXMLParser: import_id = '.$this->course_obj->getImportId());
536  $this->course_obj->MDUpdateListener('General');
537  $this->course_obj->update();
538  $this->adv_md_handler->save();
539  break;
540 
541  case 'Settings':
542  $this->in_settings = false;
543  break;
544 
545  case 'Availability':
546  $this->in_availability = false;
547  break;
548 
549  case 'Registration':
550  $this->in_registration = false;
551  break;
552 
553  case 'Archive':
554  $this->in_archive = false;
555  break;
556 
557  case 'Start':
558  if($this->in_availability)
559  {
560  $this->course_obj->setActivationStart(trim($this->cdata));
561  }
562  if($this->in_registration)
563  {
564  $this->course_obj->setSubscriptionStart(trim($this->cdata));
565  }
566  if($this->in_archive)
567  {
568  $this->course_obj->setArchiveStart(trim($this->cdata));
569  }
570  break;
571 
572  case 'End':
573  if($this->in_availability)
574  {
575  $this->course_obj->setActivationEnd(trim($this->cdata));
576  }
577  if($this->in_registration)
578  {
579  $this->course_obj->setSubscriptionEnd(trim($this->cdata));
580  }
581  if($this->in_archive)
582  {
583  $this->course_obj->setArchiveEnd(trim($this->cdata));
584  }
585  break;
586 
587  case 'Syllabus':
588  $this->course_obj->setSyllabus(trim($this->cdata));
589  break;
590 
591 
592  case 'ImportantInformation':
593  $this->course_obj->setImportantInformation(trim($this->cdata));
594  break;
595 
596  case 'Name':
597  $this->course_obj->setContactName(trim($this->cdata));
598  break;
599 
600  case 'Responsibility':
601  $this->course_obj->setContactResponsibility(trim($this->cdata));
602  break;
603 
604  case 'Phone':
605  $this->course_obj->setContactPhone(trim($this->cdata));
606  break;
607 
608  case 'Email':
609  $this->course_obj->setContactEmail(trim($this->cdata));
610  break;
611 
612  case 'Consultation':
613  $this->course_obj->setContactConsultation(trim($this->cdata));
614  break;
615 
616  case 'Password':
617  $this->course_obj->setSubscriptionPassword(trim($this->cdata));
618  break;
619 
620  case 'MetaData':
621  $this->in_meta_data = false;
622  parent::handlerEndTag($a_xml_parser,$a_name);
623  break;
624  }
625  $this->cdata = '';
626 
627  return;
628  }
629 
636  function handlerCharacterData($a_xml_parser,$a_data)
637  {
638  // call meta data handler
639  if($this->in_meta_data)
640  {
641  parent::handlerCharacterData($a_xml_parser,$a_data);
642  }
643  if($a_data != "\n")
644  {
645  // Replace multiple tabs with one space
646  $a_data = preg_replace("/\t+/"," ",$a_data);
647 
648  $this->cdata .= $a_data;
649  }
650  }
651 
652  // PRIVATE
653  function __parseId($a_id)
654  {
655  global $ilias;
656 
657  $fields = explode('_',$a_id);
658 
659  if(!is_array($fields) or
660  $fields[0] != 'il' or
661  !is_numeric($fields[1]) or
662  $fields[2] != 'usr' or
663  !is_numeric($fields[3]))
664  {
665  return false;
666  }
667  if($id = ilObjUser::_getImportedUserId($a_id))
668  {
669  return array('imported' => true,
670  'local' => false,
671  'usr_id' => $id);
672  }
673  if(($fields[1] == $ilias->getSetting('inst_id',0)) and strlen(ilObjUser::_lookupLogin($fields[3])))
674  {
675  return array('imported' => false,
676  'local' => true,
677  'usr_id' => $fields[3]);
678  }
679  return false;
680  }
681 
682 }
683 ?>