ILIAS  Release_3_10_x_branch Revision 61812
 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 
30 
40 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
41 include_once 'Modules/Course/classes/class.ilCourseWaitingList.php';
42 
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 
75  $this->setMDObject($this->md_obj);
76 
77  $this->lng =& $lng;
78  }
79 
86  function setHandlers($a_xml_parser)
87  {
88  $this->sax_controller->setHandlers($a_xml_parser);
89  $this->sax_controller->setDefaultElementHandler($this);
90 
91  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValueParser.php');
92  $this->sax_controller->setElementHandler(
93  $this->adv_md_handler = new ilAdvancedMDValueParser($this->course_obj->getId()),
94  'AdvancedMetaData');
95  }
96 
97 
98 
99 
107  function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
108  {
109  if($this->in_meta_data)
110  {
111  parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
112 
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 
186  case 'Settings':
187  $this->in_settings = true;
188  break;
189  case 'Availability':
190  $this->in_availability = true;
191  break;
192 
193  case 'NotAvailable':
194  if($this->in_availability)
195  {
196  $this->course_obj->setActivationType(IL_CRS_ACTIVATION_OFFLINE);
197  }
198  elseif($this->in_registration)
199  {
200  $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_DEACTIVATED);
201  }
202 
203  break;
204 
205  case 'Unlimited':
206  if($this->in_availability)
207  {
208  $this->course_obj->setActivationType(IL_CRS_ACTIVATION_UNLIMITED);
209  }
210  elseif($this->in_registration)
211  {
212  $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_UNLIMITED);
213  }
214 
215  break;
216  case 'TemporarilyAvailable':
217  if($this->in_availability)
218  {
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  $this->course_obj->setSubscriptionMaxMembers((int) $a_attribs['maxMembers']);
264  $this->course_obj->setSubscriptionNotify($a_attribs['notification'] == 'Yes' ? true : false);
265  $this->course_obj->enableWaitingList($a_attribs['waitingList'] == 'Yes' ? true : false);
266  break;
267 
268  case 'Sort':
269  switch($a_attribs['type'])
270  {
271  case 'Manual':
272  $this->course_obj->setOrderType(ilContainer::SORT_MANUAL);
273  break;
274 
275  case 'Title':
276  $this->course_obj->setOrderType(ilContainer::SORT_TITLE);
277  break;
278 
279  case 'Activation':
280  $this->course_obj->setOrderType(ilContainer::SORT_ACTIVATION);
281  break;
282  }
283  break;
284 
285 
286  case 'Archive':
287  $this->in_archive = true;
288  switch($a_attribs['Access'])
289  {
290  case 'Disabled':
291  $this->course_obj->setArchiveType(IL_CRS_ARCHIVE_NONE);
292  break;
293 
294  case 'Read':
295  $this->course_obj->setArchiveType(IL_CRS_ARCHIVE_NONE);
296  #$this->course_obj->setViewMode(IL_CRS_VIEW_ARCHIVE);
297  break;
298 
299  case 'Download':
300  #$this->course_obj->setViewMode(IL_CRS_VIEW_ARCHIVE);
301  $this->course_obj->setArchiveType(IL_CRS_ARCHIVE_DOWNLOAD);
302  break;
303  }
304  break;
305 
306  case 'Disabled':
307  $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_DEACTIVATED);
308  break;
309 
310  case "MetaData":
311  $this->in_meta_data = true;
312  parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
313  break;
314 
315  }
316  }
317 
326  private function handleMember ($a_attribs, $id_data)
327  {
328  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
329  // if action not set, or set and attach
330  {
331  if (!array_key_exists($id_data['usr_id'], $this->course_members_array))
332  // add only if member is not yet assigned as tutor or admin
333  {
334  $this->course_members->add($id_data['usr_id'],IL_CRS_MEMBER);
335  if($a_attribs['blocked'] == 'Yes')
336  {
337  $this->course_members->updateBlocked($id_data['usr_id'],true);
338  }
339  if($a_attribs['passed'] == 'Yes')
340  {
341  $this->course_members->updatePassed($id_data['usr_id'],true);
342  }
343  $this->course_members_array[$id_data['usr_id']] = "added";
344  }
345  else
346  // the member does exist. Now update status etc. only
347  {
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  }
357  }
358  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isMember($id_data['usr_id']))
359  // if action set and detach and is member of course
360  {
361  $this->course_members->delete($id_data['usr_id']);
362  }
363 
364  }
365 
366 
374  private function handleAdmin ($a_attribs, $id_data)
375  {
376  global $rbacadmin;
377 
378  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
379  // if action not set, or attach
380  {
381  if (!array_key_exists($id_data['usr_id'], $this->course_members_array))
382  // add only if member is not assigned yet
383  {
384  $this->course_members->add($id_data['usr_id'],IL_CRS_ADMIN);
385  if($a_attribs['notification'] == 'Yes')
386  {
387  $this->course_members->updateNotification($id_data['usr_id'],true);
388  }
389  if($a_attribs['passed'] == 'Yes')
390  {
391  $this->course_members->updatePassed($id_data['usr_id'],true);
392  }
393  $this->course_members_array[$id_data['usr_id']] = "added";
394  }
395  else
396  // update
397  {
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->updateBlocked($id_data['usr_id'],false);
407  }
408  }
409  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isAdmin($id_data['usr_id']))
410  // if action set and detach and is admin of course
411  {
412  $this->course_members->delete($id_data['usr_id']);
413  }
414 
415  }
416 
417 
425  private function handleTutor ($a_attribs, $id_data) {
426  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
427  // if action not set, or attach
428  {
429  if (!array_key_exists($id_data['usr_id'], $this->course_members_array))
430  // add only if member is not assigned yet
431  {
432  $this->course_members->add($id_data['usr_id'],IL_CRS_TUTOR);
433  if($a_attribs['notification'] == 'Yes')
434  {
435  $this->course_members->updateNotification($id_data['usr_id'],true);
436  }
437  if($a_attribs['passed'] == 'Yes')
438  {
439  $this->course_members->updatePassed($id_data['usr_id'],true);
440  }
441  $this->course_members_array[$id_data['usr_id']] = "added";
442  }
443  else
444  {
445  if($a_attribs['notification'] == 'Yes')
446  {
447  $this->course_members->updateNotification($id_data['usr_id'],true);
448  }
449  if($a_attribs['passed'] == 'Yes')
450  {
451  $this->course_members->updatePassed($id_data['usr_id'],true);
452  }
453  $this->course_members->updateBlocked($id_data['usr_id'],false);
454  }
455  }
456  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isTutor($id_data['usr_id']))
457  // if action set and detach and is tutor of course
458  {
459  $this->course_members->delete($id_data['usr_id']);
460  }
461 
462  }
463 
464 
465 
472  private function handleSubscriber ($a_attribs, $id_data) {
473  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
474  // if action not set, or attach
475  {
476  if (!$this->course_members->isSubscriber($id_data['usr_id']))
477  // add only if not exist
478  {
479  $this->course_members->addSubscriber($id_data['usr_id']);
480  }
481  $this->course_members->updateSubscriptionTime($id_data['usr_id'],$a_attribs['subscriptionTime']);
482 
483  }
484  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isSubscriber($id_data['usr_id']))
485  // if action set and detach and is subscriber
486  {
487  $this->course_members->deleteSubscriber($id_data["usr_id"]);
488  }
489 
490  }
491 
498  private function handleWaitingList ($a_attribs, $id_data)
499  {
500  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
501  // if action not set, or attach
502  {
503  if (!$this->course_waiting_list->isOnList($id_data['usr_id']))
504  // add only if not exists
505  {
506  $this->course_waiting_list->addToList($id_data['usr_id']);
507  }
508  $this->course_waiting_list->updateSubscriptionTime($id_data['usr_id'],$a_attribs['subscriptionTime']);
509 
510  }
511  elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_waiting_list->isOnList($id_data['usr_id']))
512  // if action set and detach and is on list
513  {
514  $this->course_waiting_list->removeFromList($id_data['usr_id']);
515  }
516 
517  }
518 
519 
526  function handlerEndTag($a_xml_parser,$a_name)
527  {
528  if($this->in_meta_data)
529  {
530  parent::handlerEndTag($a_xml_parser,$a_name);
531  }
532 
533  switch($a_name)
534  {
535  case 'Course':
536 
537  $this->log->write('CourseXMLParser: import_id = '.$this->course_obj->getImportId());
538  $this->course_obj->updateSettings();
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 ?>