ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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  public $lng;
46  public $md_obj = null; // current meta data object
47 
49 
53  private $log = null;
54 
64  public function __construct($a_course_obj, $a_xml_file = '')
65  {
66  global $DIC;
67 
68  $lng = $DIC['lng'];
69 
70  parent::__construct($a_xml_file);
71 
72  $this->sax_controller = new ilSaxController();
73 
74  $this->log = $DIC->logger()->crs();
75 
76  $this->course_obj = $a_course_obj;
77  $this->course_members = ilCourseParticipants::_getInstanceByObjId($this->course_obj->getId());
78  $this->course_waiting_list = new ilCourseWaitingList($this->course_obj->getId());
79  // flip the array so we can use array_key_exists
80  $this->course_members_array = array_flip($this->course_members->getParticipants());
81 
82  $this->md_obj = new ilMD($this->course_obj->getId(), 0, 'crs');
83  $this->setMDObject($this->md_obj);
84 
85  $this->lng = $lng;
86  }
87 
94  public function setHandlers($a_xml_parser)
95  {
96  $this->sax_controller->setHandlers($a_xml_parser);
97  $this->sax_controller->setDefaultElementHandler($this);
98 
99  include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValueParser.php');
100  $this->sax_controller->setElementHandler(
101  $this->adv_md_handler = new ilAdvancedMDValueParser($this->course_obj->getId()),
102  'AdvancedMetaData'
103  );
104  }
105 
106 
107 
108 
116  public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
117  {
118  if ($this->in_meta_data) {
119  parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
120  return;
121  }
122 
123  switch ($a_name) {
124  case 'Course':
125 
126  if (strlen($a_attribs['importId'])) {
127  $this->log->write("CourseXMLParser: importId = " . $a_attribs['importId']);
128  $this->course_obj->setImportId($a_attribs['importId']);
129  ilObject::_writeImportId($this->course_obj->getId(), $a_attribs['importId']);
130  }
131  if (strlen($a_attribs['showMembers'])) {
132  $this->course_obj->setShowMembers(
133  $a_attribs['showMembers'] == 'Yes' ? true : false
134  );
135  }
136  break;
137 
138  case 'Admin':
139  if ($id_data = $this->__parseId($a_attribs['id'])) {
140  if ($id_data['local'] or $id_data['imported']) {
141  $this->handleAdmin($a_attribs, $id_data);
142  }
143  }
144  break;
145 
146  case 'Tutor':
147  if ($id_data = $this->__parseId($a_attribs['id'])) {
148  if ($id_data['local'] or $id_data['imported']) {
149  $this->handleTutor($a_attribs, $id_data);
150  }
151  }
152  break;
153 
154  case 'Member':
155  if ($id_data = $this->__parseId($a_attribs['id'])) {
156  if ($id_data['local'] or $id_data['imported']) {
157  $this->handleMember($a_attribs, $id_data);
158  }
159  }
160  break;
161 
162  case 'Subscriber':
163  if ($id_data = $this->__parseId($a_attribs['id'])) {
164  if ($id_data['local'] or $id_data['imported']) {
165  $this->handleSubscriber($a_attribs, $id_data);
166  }
167  }
168  break;
169 
170  case 'WaitingList':
171  if ($id_data = $this->__parseId($a_attribs['id'])) {
172  if ($id_data['local'] or $id_data['imported']) {
173  $this->handleWaitingList($a_attribs, $id_data);
174  }
175  }
176  break;
177 
178  case 'Owner':
179  if ($id_data = $this->__parseId($a_attribs['id'])) {
180  if ($id_data['local'] or $id_data['imported']) {
181  $this->course_obj->setOwner($id_data['usr_id']);
182  $this->course_obj->updateOwner();
183  }
184  }
185  break;
186 
187 
188  case 'Settings':
189  $this->in_settings = true;
190  break;
191  case 'Availability':
192  $this->in_availability = true;
193  break;
194 
195  case 'NotAvailable':
196  if ($this->in_availability) {
197  $this->course_obj->setOfflineStatus(true);
198  } elseif ($this->in_registration) {
199  $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_DEACTIVATED);
200  }
201 
202  break;
203 
204  case 'Unlimited':
205  if ($this->in_availability) {
206  $this->course_obj->setOfflineStatus(false);
207  } elseif ($this->in_registration) {
208  $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_UNLIMITED);
209  }
210 
211  break;
212  case 'TemporarilyAvailable':
213  if ($this->in_availability) {
214  $this->course_obj->setOfflineStatus(false);
215  } elseif ($this->in_registration) {
216  $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_LIMITED);
217  }
218  break;
219 
220  case 'Start':
221  break;
222 
223  case 'End':
224  break;
225 
226  case 'Syllabus':
227  break;
228 
229  case 'TargetGroup':
230  break;
231 
232  case 'Contact':
233  break;
234 
235  case 'Name':
236  case 'Responsibility':
237  case 'Phone':
238  case 'Email':
239  case 'Consultation':
240  break;
241 
242  case 'Registration':
243  $this->in_registration = true;
244 
245  switch ($a_attribs['registrationType']) {
246  case 'Confirmation':
247  $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_CONFIRMATION);
248  break;
249 
250  case 'Direct':
251  $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_DIRECT);
252  break;
253 
254  case 'Password':
255  $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_PASSWORD);
256  break;
257  }
258 
259  $this->course_obj->setSubscriptionMaxMembers((int) $a_attribs['maxMembers']);
260  $this->course_obj->enableSubscriptionMembershipLimitation($this->course_obj->getSubscriptionMaxMembers() > 0);
261  $this->course_obj->setSubscriptionNotify($a_attribs['notification'] == 'Yes' ? true : false);
262  $this->course_obj->enableWaitingList($a_attribs['waitingList'] == 'Yes' ? true : false);
263  break;
264 
265  case 'Sort':
266  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
267  ilContainerSortingSettings::_importContainerSortingSettings($a_attribs, $this->course_obj->getId());
268 
269  //#17837
270  $this->course_obj->setOrderType(
271  ilContainerSortingSettings::getInstanceByObjId($this->course_obj->getId())->getSortMode()
272  );
273  break;
274 
275  case 'Disabled':
276  $this->course_obj->getSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_DEACTIVATED);
277  break;
278 
279  case "MetaData":
280  $this->in_meta_data = true;
281  parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
282  break;
283 
284  case 'ContainerSetting':
285  $this->current_container_setting = $a_attribs['id'];
286  break;
287 
288  case 'Period':
289  $this->in_period = true;
290  $this->in_period_with_time = $a_attribs['withTime'];
291  break;
292 
293  case 'WaitingListAutoFill':
294  case 'CancellationEnd':
295  case 'MinMembers':
296  break;
297 
298  case 'WelcomeMail':
299  if (array_key_exists('status', $a_attribs)) {
300  $this->course_obj->setAutoNotification((bool) $a_attribs['status']);
301  }
302  break;
303  }
304  }
305 
314  private function handleMember($a_attribs, $id_data)
315  {
316  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach') {
317  // if action not set, or set and attach
318  if (!array_key_exists($id_data['usr_id'], $this->course_members_array)) {
319  // add only if member is not yet assigned as tutor or admin
320  $this->course_members->add($id_data['usr_id'], IL_CRS_MEMBER);
321  if ($a_attribs['blocked'] == 'Yes') {
322  $this->course_members->updateBlocked($id_data['usr_id'], true);
323  }
324  if ($a_attribs['passed'] == 'Yes') {
325  $this->course_members->updatePassed($id_data['usr_id'], true);
326  }
327  $this->course_members_array[$id_data['usr_id']] = "added";
328  } else {
329  // the member does exist. Now update status etc. only
330  if ($a_attribs['blocked'] == 'Yes') {
331  $this->course_members->updateBlocked($id_data['usr_id'], true);
332  }
333  if ($a_attribs['passed'] == 'Yes') {
334  $this->course_members->updatePassed($id_data['usr_id'], true);
335  }
336  }
337  } elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isMember($id_data['usr_id'])) {
338  // if action set and detach and is member of course
339  $this->course_members->delete($id_data['usr_id']);
340  }
341  }
342 
343 
351  private function handleAdmin($a_attribs, $id_data)
352  {
353  global $DIC;
354 
355  $rbacadmin = $DIC['rbacadmin'];
356 
357  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach') {
358  // if action not set, or attach
359  if (!array_key_exists($id_data['usr_id'], $this->course_members_array)) {
360  // add only if member is not assigned yet
361  $this->course_members->add($id_data['usr_id'], IL_CRS_ADMIN);
362  if ($a_attribs['notification'] == 'Yes') {
363  $this->course_members->updateNotification($id_data['usr_id'], true);
364  }
365  if ($a_attribs['passed'] == 'Yes') {
366  $this->course_members->updatePassed($id_data['usr_id'], true);
367  }
368  if (isset($a_attribs['contact']) && $a_attribs['contact'] == 'Yes') {
369  // default for new course admin/tutors is "no contact"
370  $this->course_members->updateContact($id_data['usr_id'], true);
371  }
372  $this->course_members_array[$id_data['usr_id']] = "added";
373  } else {
374  // update
375  if ($a_attribs['notification'] == 'Yes') {
376  $this->course_members->updateNotification($id_data['usr_id'], true);
377  }
378  if ($a_attribs['passed'] == 'Yes') {
379  $this->course_members->updatePassed($id_data['usr_id'], true);
380  }
381  if (isset($a_attribs['contact']) && $a_attribs['contact'] == 'Yes') {
382  $this->course_members->updateContact($id_data['usr_id'], true);
383  } elseif (isset($a_attribs['contact']) && $a_attribs['contact'] == 'No') {
384  $this->course_members->updateContact($id_data['usr_id'], false);
385  }
386  $this->course_members->updateBlocked($id_data['usr_id'], false);
387  }
388  } elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isAdmin($id_data['usr_id'])) {
389  // if action set and detach and is admin of course
390  $this->course_members->delete($id_data['usr_id']);
391  }
392  }
393 
394 
402  private function handleTutor($a_attribs, $id_data)
403  {
404  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach') {
405  // if action not set, or attach
406  if (!array_key_exists($id_data['usr_id'], $this->course_members_array)) {
407  // add only if member is not assigned yet
408  $this->course_members->add($id_data['usr_id'], IL_CRS_TUTOR);
409  if ($a_attribs['notification'] == 'Yes') {
410  $this->course_members->updateNotification($id_data['usr_id'], true);
411  }
412  if ($a_attribs['passed'] == 'Yes') {
413  $this->course_members->updatePassed($id_data['usr_id'], true);
414  }
415  if (isset($a_attribs['contact']) && $a_attribs['contact'] == 'Yes') {
416  // default for new course admin/tutors is "no contact"
417  $this->course_members->updateContact($id_data['usr_id'], true);
418  }
419  $this->course_members_array[$id_data['usr_id']] = "added";
420  } else {
421  if ($a_attribs['notification'] == 'Yes') {
422  $this->course_members->updateNotification($id_data['usr_id'], true);
423  }
424  if ($a_attribs['passed'] == 'Yes') {
425  $this->course_members->updatePassed($id_data['usr_id'], true);
426  }
427  if (isset($a_attribs['contact']) && $a_attribs['contact'] == 'Yes') {
428  $this->course_members->updateContact($id_data['usr_id'], true);
429  } elseif (isset($a_attribs['contact']) && $a_attribs['contact'] == 'No') {
430  $this->course_members->updateContact($id_data['usr_id'], false);
431  }
432  $this->course_members->updateBlocked($id_data['usr_id'], false);
433  }
434  } elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isTutor($id_data['usr_id'])) {
435  // if action set and detach and is tutor of course
436  $this->course_members->delete($id_data['usr_id']);
437  }
438  }
439 
440 
441 
448  private function handleSubscriber($a_attribs, $id_data)
449  {
450  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach') {
451  // if action not set, or attach
452  if (!$this->course_members->isSubscriber($id_data['usr_id'])) {
453  // add only if not exist
454  $this->course_members->addSubscriber($id_data['usr_id']);
455  }
456  $this->course_members->updateSubscriptionTime($id_data['usr_id'], $a_attribs['subscriptionTime']);
457  } elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isSubscriber($id_data['usr_id'])) {
458  // if action set and detach and is subscriber
459  $this->course_members->deleteSubscriber($id_data["usr_id"]);
460  }
461  }
462 
469  private function handleWaitingList($a_attribs, $id_data)
470  {
471  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach') {
472  // if action not set, or attach
473  if (!$this->course_waiting_list->isOnList($id_data['usr_id'])) {
474  // add only if not exists
475  $this->course_waiting_list->addToList($id_data['usr_id']);
476  }
477  $this->course_waiting_list->updateSubscriptionTime($id_data['usr_id'], $a_attribs['subscriptionTime']);
478  } elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_waiting_list->isOnList($id_data['usr_id'])) {
479  // if action set and detach and is on list
480  $this->course_waiting_list->removeFromList($id_data['usr_id']);
481  }
482  }
483 
484 
491  public function handlerEndTag($a_xml_parser, $a_name)
492  {
493  if ($this->in_meta_data) {
494  parent::handlerEndTag($a_xml_parser, $a_name);
495  }
496 
497  switch ($a_name) {
498  case 'Course':
499 
500  $this->log->write('CourseXMLParser: import_id = ' . $this->course_obj->getImportId());
501  $this->course_obj->MDUpdateListener('General');
502  $this->course_obj->update();
503  $this->adv_md_handler->save();
504  break;
505 
506  case 'Settings':
507  $this->in_settings = false;
508  break;
509 
510  case 'Availability':
511  $this->in_availability = false;
512  break;
513 
514  case 'Registration':
515  $this->in_registration = false;
516  break;
517 
518 
519  case 'Start':
520  if ($this->in_availability) {
521  $this->course_obj->setActivationStart(trim($this->cdata));
522  }
523  if ($this->in_registration) {
524  $this->course_obj->setSubscriptionStart(trim($this->cdata));
525  }
526  if ($this->in_period) {
527  if ((int) $this->cdata) {
528  if ($this->in_period_with_time) {
529  $this->period_start = new \ilDateTime((int) $this->cdata, IL_CAL_UNIX);
530  } else {
531  $this->period_start = new \ilDate((int) $this->cdata, IL_CAL_UNIX);
532  }
533  }
534  }
535  break;
536 
537  case 'End':
538  if ($this->in_availability) {
539  $this->course_obj->setActivationEnd(trim($this->cdata));
540  }
541  if ($this->in_registration) {
542  $this->course_obj->setSubscriptionEnd(trim($this->cdata));
543  }
544  if ($this->in_period) {
545  if ((int) $this->cdata) {
546  if ($this->in_period_with_time) {
547  $this->period_end = new \ilDateTime((int) $this->cdata, IL_CAL_UNIX);
548  }
549  else {
550  $this->period_end = new \ilDate((int) $this->cdata, IL_CAL_UNIX);
551  }
552  }
553  }
554  break;
555 
556  case 'Syllabus':
557  $this->course_obj->setSyllabus(trim($this->cdata));
558  break;
559 
560  case 'TargetGroup':
561  $this->course_obj->setTargetGroup(trim($this->cdata));
562  break;
563 
564  case 'ImportantInformation':
565  $this->course_obj->setImportantInformation(trim($this->cdata));
566  break;
567 
568  case 'ViewMode':
569  $this->course_obj->setViewMode(trim($this->cdata));
570  break;
571 
572  case 'Name':
573  $this->course_obj->setContactName(trim($this->cdata));
574  break;
575 
576  case 'Responsibility':
577  $this->course_obj->setContactResponsibility(trim($this->cdata));
578  break;
579 
580  case 'Phone':
581  $this->course_obj->setContactPhone(trim($this->cdata));
582  break;
583 
584  case 'Email':
585  $this->course_obj->setContactEmail(trim($this->cdata));
586  break;
587 
588  case 'Consultation':
589  $this->course_obj->setContactConsultation(trim($this->cdata));
590  break;
591 
592  case 'Password':
593  $this->course_obj->setSubscriptionPassword(trim($this->cdata));
594  break;
595 
596  case 'MetaData':
597  $this->in_meta_data = false;
598  parent::handlerEndTag($a_xml_parser, $a_name);
599  break;
600 
601  case 'ContainerSetting':
602  if ($this->current_container_setting) {
604  $this->course_obj->getId(),
606  $this->cdata
607  );
608  }
609  break;
610 
611  case 'Period':
612  $this->in_period = false;
613  try {
614  $this->course_obj->setCoursePeriod($this->period_start, $this->period_end);
615  } catch (Exception $e) {
616  $this->log->warning('invalid course period given');
617  }
618  break;
619 
620  case 'WaitingListAutoFill':
621  $this->course_obj->setWaitingListAutoFill($this->cdata);
622  break;
623 
624  case 'CancellationEnd':
625  if ((int) $this->cdata) {
626  $this->course_obj->setCancellationEnd(new ilDate((int) $this->cdata, IL_CAL_UNIX));
627  }
628  break;
629 
630  case 'MinMembers':
631  if ((int) $this->cdata) {
632  $this->course_obj->setSubscriptionMinMembers((int) $this->cdata);
633  }
634  break;
635 
636  case 'ViewMode':
637  $this->course_obj->setViewMode((int) $this->cdata);
638  break;
639 
640  case 'TimingMode':
641  $this->course_obj->setTimingMode((int) $this->cdata);
642  break;
643  }
644  $this->cdata = '';
645 
646  return;
647  }
648 
655  public function handlerCharacterData($a_xml_parser, $a_data)
656  {
657  // call meta data handler
658  if ($this->in_meta_data) {
659  parent::handlerCharacterData($a_xml_parser, $a_data);
660  }
661  if ($a_data != "\n") {
662  // Replace multiple tabs with one space
663  $a_data = preg_replace("/\t+/", " ", $a_data);
664 
665  $this->cdata .= $a_data;
666  }
667  }
668 
669  // PRIVATE
670  public function __parseId($a_id)
671  {
672  global $DIC;
673 
674  $ilias = $DIC['ilias'];
675 
676  $fields = explode('_', $a_id);
677 
678  if (!is_array($fields) or
679  $fields[0] != 'il' or
680  !is_numeric($fields[1]) or
681  $fields[2] != 'usr' or
682  !is_numeric($fields[3])) {
683  return false;
684  }
685  if ($id = ilObjUser::_getImportedUserId($a_id)) {
686  return array('imported' => true,
687  'local' => false,
688  'usr_id' => $id);
689  }
690  if (($fields[1] == $ilias->getSetting('inst_id', 0)) and strlen(ilObjUser::_lookupLogin($fields[3]))) {
691  return array('imported' => false,
692  'local' => true,
693  'usr_id' => $fields[3]);
694  }
695  return false;
696  }
697 }
static _lookupLogin($a_user_id)
lookup login
__construct($a_course_obj, $a_xml_file='')
Constructor.
const IL_CRS_SUBSCRIPTION_LIMITED
static _importContainerSortingSettings($attibs, $obj_id)
sorting import for all container objects
handleMember($a_attribs, $id_data)
attach or detach user/member/admin from course member
static _getInstanceByObjId($a_obj_id)
Get singleton instance.
setHandlers($a_xml_parser)
set event handlers
handleAdmin($a_attribs, $id_data)
attach or detach admin from course member
const IL_CRS_TUTOR
const IL_CRS_SUBSCRIPTION_CONFIRMATION
const IL_CAL_UNIX
handleWaitingList($a_attribs, $id_data)
attach or detach members from waitinglist
static _getImportedUserId($i2_id)
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
const IL_CRS_MEMBER
handlerEndTag($a_xml_parser, $a_name)
handler for end of element
const IL_CRS_SUBSCRIPTION_PASSWORD
Class for single dates.
const IL_CRS_SUBSCRIPTION_UNLIMITED
handleTutor($a_attribs, $id_data)
attach or detach admin from course member
const IL_CRS_ADMIN
Base class for course and group participants.
Interface definition for sax subset parsers.
Controller class for sax element handlers.
__construct(Container $dic, ilPlugin $plugin)
static _writeImportId($a_obj_id, $a_import_id)
write import id to db (static)
$DIC
Definition: xapitoken.php:46
static _writeContainerSetting($a_id, $a_keyword, $a_value)
const IL_CRS_SUBSCRIPTION_DIRECT
static getInstanceByObjId($a_obj_id)
Get singleton instance.
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
handleSubscriber($a_attribs, $id_data)
attach or detach members from subscribers
const IL_CRS_SUBSCRIPTION_DEACTIVATED