ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
25include_once("Services/MetaData/classes/class.ilMDSaxParser.php");
26include_once("Services/MetaData/classes/class.ilMD.php");
27include_once('Services/Utilities/interfaces/interface.ilSaxSubsetParser.php');
28include_once('Services/Utilities/classes/class.ilSaxController.php');
29include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
30include_once 'Modules/Course/classes/class.ilCourseWaitingList.php';
31include_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 public function __construct($a_course_obj, $a_xml_file = '')
60 {
61 global $lng,$ilLog;
62
63 parent::__construct($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 case 'Disabled':
294 $this->course_obj->getSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_DEACTIVATED);
295 break;
296
297 case "MetaData":
298 $this->in_meta_data = true;
299 parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
300 break;
301
302 case 'ContainerSetting':
303 $this->current_container_setting = $a_attribs['id'];
304 break;
305
306 case 'Period':
307 $this->in_period = true;
308 break;
309
310 case 'WaitingListAutoFill':
311 case 'CancellationEnd':
312 case 'MinMembers':
313 break;
314 }
315 }
316
325 private function handleMember ($a_attribs, $id_data)
326 {
327 if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
328 // if action not set, or set and attach
329 {
330 if (!array_key_exists($id_data['usr_id'], $this->course_members_array))
331 // add only if member is not yet assigned as tutor or admin
332 {
333 $this->course_members->add($id_data['usr_id'],IL_CRS_MEMBER);
334 if($a_attribs['blocked'] == 'Yes')
335 {
336 $this->course_members->updateBlocked($id_data['usr_id'],true);
337 }
338 if($a_attribs['passed'] == 'Yes')
339 {
340 $this->course_members->updatePassed($id_data['usr_id'],true);
341 }
342 $this->course_members_array[$id_data['usr_id']] = "added";
343 }
344 else
345 // the member does exist. Now update status etc. only
346 {
347 if($a_attribs['blocked'] == 'Yes')
348 {
349 $this->course_members->updateBlocked($id_data['usr_id'],true);
350 }
351 if($a_attribs['passed'] == 'Yes')
352 {
353 $this->course_members->updatePassed($id_data['usr_id'],true);
354 }
355 }
356 }
357 elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isMember($id_data['usr_id']))
358 // if action set and detach and is member of course
359 {
360 $this->course_members->delete($id_data['usr_id']);
361 }
362
363 }
364
365
373 private function handleAdmin ($a_attribs, $id_data)
374 {
375 global $rbacadmin;
376
377 if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
378 // if action not set, or attach
379 {
380 if (!array_key_exists($id_data['usr_id'], $this->course_members_array))
381 // add only if member is not assigned yet
382 {
383 $this->course_members->add($id_data['usr_id'],IL_CRS_ADMIN);
384 if($a_attribs['notification'] == 'Yes')
385 {
386 $this->course_members->updateNotification($id_data['usr_id'],true);
387 }
388 if($a_attribs['passed'] == 'Yes')
389 {
390 $this->course_members->updatePassed($id_data['usr_id'],true);
391 }
392 $this->course_members_array[$id_data['usr_id']] = "added";
393 }
394 else
395 // update
396 {
397 if($a_attribs['notification'] == 'Yes')
398 {
399 $this->course_members->updateNotification($id_data['usr_id'],true);
400 }
401 if($a_attribs['passed'] == 'Yes')
402 {
403 $this->course_members->updatePassed($id_data['usr_id'],true);
404 }
405 $this->course_members->updateBlocked($id_data['usr_id'],false);
406 }
407 }
408 elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isAdmin($id_data['usr_id']))
409 // if action set and detach and is admin of course
410 {
411 $this->course_members->delete($id_data['usr_id']);
412 }
413
414 }
415
416
424 private function handleTutor ($a_attribs, $id_data) {
425 if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
426 // if action not set, or attach
427 {
428 if (!array_key_exists($id_data['usr_id'], $this->course_members_array))
429 // add only if member is not assigned yet
430 {
431 $this->course_members->add($id_data['usr_id'],IL_CRS_TUTOR);
432 if($a_attribs['notification'] == 'Yes')
433 {
434 $this->course_members->updateNotification($id_data['usr_id'],true);
435 }
436 if($a_attribs['passed'] == 'Yes')
437 {
438 $this->course_members->updatePassed($id_data['usr_id'],true);
439 }
440 $this->course_members_array[$id_data['usr_id']] = "added";
441 }
442 else
443 {
444 if($a_attribs['notification'] == 'Yes')
445 {
446 $this->course_members->updateNotification($id_data['usr_id'],true);
447 }
448 if($a_attribs['passed'] == 'Yes')
449 {
450 $this->course_members->updatePassed($id_data['usr_id'],true);
451 }
452 $this->course_members->updateBlocked($id_data['usr_id'],false);
453 }
454 }
455 elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isTutor($id_data['usr_id']))
456 // if action set and detach and is tutor of course
457 {
458 $this->course_members->delete($id_data['usr_id']);
459 }
460
461 }
462
463
464
471 private function handleSubscriber ($a_attribs, $id_data)
472 {
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->MDUpdateListener('General');
539 $this->course_obj->update();
540 $this->adv_md_handler->save();
541 break;
542
543 case 'Settings':
544 $this->in_settings = false;
545 break;
546
547 case 'Availability':
548 $this->in_availability = false;
549 break;
550
551 case 'Registration':
552 $this->in_registration = false;
553 break;
554
555
556 case 'Start':
557 if($this->in_availability)
558 {
559 $this->course_obj->setActivationStart(trim($this->cdata));
560 }
561 if($this->in_registration)
562 {
563 $this->course_obj->setSubscriptionStart(trim($this->cdata));
564 }
565 if($this->in_period)
566 {
567 if((int)$this->cdata)
568 {
569 $this->course_obj->setCourseStart(new ilDate((int)$this->cdata, IL_CAL_UNIX));
570 }
571 }
572 break;
573
574 case 'End':
575 if($this->in_availability)
576 {
577 $this->course_obj->setActivationEnd(trim($this->cdata));
578 }
579 if($this->in_registration)
580 {
581 $this->course_obj->setSubscriptionEnd(trim($this->cdata));
582 }
583 if($this->in_period)
584 {
585 if((int)$this->cdata)
586 {
587 $this->course_obj->setCourseEnd(new ilDate((int)$this->cdata, IL_CAL_UNIX));
588 }
589 }
590 break;
591
592 case 'Syllabus':
593 $this->course_obj->setSyllabus(trim($this->cdata));
594 break;
595
596
597 case 'ImportantInformation':
598 $this->course_obj->setImportantInformation(trim($this->cdata));
599 break;
600
601 case 'ViewMode':
602 $this->course_obj->setViewMode(trim($this->cdata));
603 break;
604
605 case 'Name':
606 $this->course_obj->setContactName(trim($this->cdata));
607 break;
608
609 case 'Responsibility':
610 $this->course_obj->setContactResponsibility(trim($this->cdata));
611 break;
612
613 case 'Phone':
614 $this->course_obj->setContactPhone(trim($this->cdata));
615 break;
616
617 case 'Email':
618 $this->course_obj->setContactEmail(trim($this->cdata));
619 break;
620
621 case 'Consultation':
622 $this->course_obj->setContactConsultation(trim($this->cdata));
623 break;
624
625 case 'Password':
626 $this->course_obj->setSubscriptionPassword(trim($this->cdata));
627 break;
628
629 case 'MetaData':
630 $this->in_meta_data = false;
631 parent::handlerEndTag($a_xml_parser,$a_name);
632 break;
633
634 case 'ContainerSetting':
635 if($this->current_container_setting)
636 {
638 $this->course_obj->getId(),
639 $this->current_container_setting,
640 $this->cdata);
641 }
642 break;
643
644 case 'Period':
645 $this->in_period = false;
646 break;
647
648 case 'WaitingListAutoFill':
649 $this->course_obj->setWaitingListAutoFill($this->cdata);
650 break;
651
652 case 'CancellationEnd':
653 if((int)$this->cdata)
654 {
655 $this->course_obj->setCancellationEnd(new ilDate((int)$this->cdata, IL_CAL_UNIX));
656 }
657 break;
658
659 case 'MinMembers':
660 if((int)$this->cdata)
661 {
662 $this->course_obj->setSubscriptionMinMembers((int)$this->cdata);
663 }
664 break;
665 }
666 $this->cdata = '';
667
668 return;
669 }
670
677 function handlerCharacterData($a_xml_parser,$a_data)
678 {
679 // call meta data handler
680 if($this->in_meta_data)
681 {
682 parent::handlerCharacterData($a_xml_parser,$a_data);
683 }
684 if($a_data != "\n")
685 {
686 // Replace multiple tabs with one space
687 $a_data = preg_replace("/\t+/"," ",$a_data);
688
689 $this->cdata .= $a_data;
690 }
691 }
692
693 // PRIVATE
694 function __parseId($a_id)
695 {
696 global $ilias;
697
698 $fields = explode('_',$a_id);
699
700 if(!is_array($fields) or
701 $fields[0] != 'il' or
702 !is_numeric($fields[1]) or
703 $fields[2] != 'usr' or
704 !is_numeric($fields[3]))
705 {
706 return false;
707 }
708 if($id = ilObjUser::_getImportedUserId($a_id))
709 {
710 return array('imported' => true,
711 'local' => false,
712 'usr_id' => $id);
713 }
714 if(($fields[1] == $ilias->getSetting('inst_id',0)) and strlen(ilObjUser::_lookupLogin($fields[3])))
715 {
716 return array('imported' => false,
717 'local' => true,
718 'usr_id' => $fields[3]);
719 }
720 return false;
721 }
722
723}
724?>
An exception for terminatinating execution or to throw for unit testing.
const IL_CRS_SUBSCRIPTION_LIMITED
const IL_CRS_ACTIVATION_OFFLINE
const IL_CRS_ACTIVATION_UNLIMITED
const IL_CRS_SUBSCRIPTION_PASSWORD
const IL_CRS_SUBSCRIPTION_CONFIRMATION
const IL_CRS_SUBSCRIPTION_UNLIMITED
const IL_CRS_ACTIVATION_LIMITED
const IL_CRS_SUBSCRIPTION_DEACTIVATED
const IL_CRS_SUBSCRIPTION_DIRECT
const IL_CAL_UNIX
const IL_CRS_ADMIN
Base class for course and group participants.
const IL_CRS_MEMBER
const IL_CRS_TUTOR
static getInstanceByObjId($a_obj_id)
Get singleton instance.
static _importContainerSortingSettings($attibs, $obj_id)
sorting import for all container objects
static _writeContainerSetting($a_id, $a_keyword, $a_value)
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
handleWaitingList($a_attribs, $id_data)
attach or detach members from waitinglist
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
__construct($a_course_obj, $a_xml_file='')
Constructor.
handleSubscriber($a_attribs, $id_data)
attach or detach members from subscribers
handleTutor($a_attribs, $id_data)
attach or detach admin from course member
setHandlers($a_xml_parser)
set event handlers
handleAdmin($a_attribs, $id_data)
attach or detach admin from course member
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
handleMember($a_attribs, $id_data)
attach or detach user/member/admin from course member
Class for single dates.
static _getImportedUserId($i2_id)
static _lookupLogin($a_user_id)
lookup login
static _writeImportId($a_obj_id, $a_import_id)
write import id to db (static)
Controller class for sax element handlers.
Interface definition for sax subset parsers.