ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
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  public 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 
101 
109  public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
110  {
111  if ($this->in_meta_data) {
112  parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
113  return;
114  }
115 
116  switch ($a_name) {
117  case 'Course':
118 
119  if (strlen($a_attribs['importId'])) {
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  $this->course_obj->setShowMembers(
126  $a_attribs['showMembers'] == 'Yes' ? true : false
127  );
128  }
129  break;
130 
131  case 'Admin':
132  if ($id_data = $this->__parseId($a_attribs['id'])) {
133  if ($id_data['local'] or $id_data['imported']) {
134  $this->handleAdmin($a_attribs, $id_data);
135  }
136  }
137  break;
138 
139  case 'Tutor':
140  if ($id_data = $this->__parseId($a_attribs['id'])) {
141  if ($id_data['local'] or $id_data['imported']) {
142  $this->handleTutor($a_attribs, $id_data);
143  }
144  }
145  break;
146 
147  case 'Member':
148  if ($id_data = $this->__parseId($a_attribs['id'])) {
149  if ($id_data['local'] or $id_data['imported']) {
150  $this->handleMember($a_attribs, $id_data);
151  }
152  }
153  break;
154 
155  case 'Subscriber':
156  if ($id_data = $this->__parseId($a_attribs['id'])) {
157  if ($id_data['local'] or $id_data['imported']) {
158  $this->handleSubscriber($a_attribs, $id_data);
159  }
160  }
161  break;
162 
163  case 'WaitingList':
164  if ($id_data = $this->__parseId($a_attribs['id'])) {
165  if ($id_data['local'] or $id_data['imported']) {
166  $this->handleWaitingList($a_attribs, $id_data);
167  }
168  }
169  break;
170 
171  case 'Owner':
172  if ($id_data = $this->__parseId($a_attribs['id'])) {
173  if ($id_data['local'] or $id_data['imported']) {
174  $this->course_obj->setOwner($id_data['usr_id']);
175  $this->course_obj->updateOwner();
176  }
177  }
178  break;
179 
180 
181  case 'Settings':
182  $this->in_settings = true;
183  break;
184  case 'Availability':
185  $this->in_availability = true;
186  break;
187 
188  case 'NotAvailable':
189  if ($this->in_availability) {
190  $this->course_obj->setActivationType(IL_CRS_ACTIVATION_OFFLINE);
191  } elseif ($this->in_registration) {
192  $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_DEACTIVATED);
193  }
194 
195  break;
196 
197  case 'Unlimited':
198  if ($this->in_availability) {
199  $this->course_obj->setOfflineStatus(false);
200  $this->course_obj->setActivationType(IL_CRS_ACTIVATION_UNLIMITED);
201  } elseif ($this->in_registration) {
202  $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_UNLIMITED);
203  }
204 
205  break;
206  case 'TemporarilyAvailable':
207  if ($this->in_availability) {
208  $this->course_obj->setOfflineStatus(false);
209  $this->course_obj->setActivationType(IL_CRS_ACTIVATION_LIMITED);
210  } elseif ($this->in_registration) {
211  $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_LIMITED);
212  }
213  break;
214 
215  case 'Start':
216  break;
217 
218  case 'End':
219  break;
220 
221  case 'Syllabus':
222  break;
223 
224  case 'Contact':
225  break;
226 
227  case 'Name':
228  case 'Responsibility':
229  case 'Phone':
230  case 'Email':
231  case 'Consultation':
232  break;
233 
234  case 'Registration':
235  $this->in_registration = true;
236 
237  switch ($a_attribs['registrationType']) {
238  case 'Confirmation':
239  $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_CONFIRMATION);
240  break;
241 
242  case 'Direct':
243  $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_DIRECT);
244  break;
245 
246  case 'Password':
247  $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_PASSWORD);
248  break;
249  }
250 
251  $this->course_obj->setSubscriptionMaxMembers((int) $a_attribs['maxMembers']);
252  $this->course_obj->enableSubscriptionMembershipLimitation($this->course_obj->getSubscriptionMaxMembers() > 0);
253  $this->course_obj->setSubscriptionNotify($a_attribs['notification'] == 'Yes' ? true : false);
254  $this->course_obj->enableWaitingList($a_attribs['waitingList'] == 'Yes' ? true : false);
255  break;
256 
257  case 'Sort':
258  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
259  ilContainerSortingSettings::_importContainerSortingSettings($a_attribs, $this->course_obj->getId());
260 
261  //#17837
262  $this->course_obj->setOrderType(
263  ilContainerSortingSettings::getInstanceByObjId($this->course_obj->getId())->getSortMode()
264  );
265  break;
266 
267  case 'Disabled':
268  $this->course_obj->getSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_DEACTIVATED);
269  break;
270 
271  case "MetaData":
272  $this->in_meta_data = true;
273  parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
274  break;
275 
276  case 'ContainerSetting':
277  $this->current_container_setting = $a_attribs['id'];
278  break;
279 
280  case 'Period':
281  $this->in_period = true;
282  break;
283 
284  case 'WaitingListAutoFill':
285  case 'CancellationEnd':
286  case 'MinMembers':
287  break;
288  }
289  }
290 
299  private function handleMember($a_attribs, $id_data)
300  {
301  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach') {
302  // if action not set, or set and attach
303  if (!array_key_exists($id_data['usr_id'], $this->course_members_array)) {
304  // add only if member is not yet assigned as tutor or admin
305  $this->course_members->add($id_data['usr_id'], IL_CRS_MEMBER);
306  if ($a_attribs['blocked'] == 'Yes') {
307  $this->course_members->updateBlocked($id_data['usr_id'], true);
308  }
309  if ($a_attribs['passed'] == 'Yes') {
310  $this->course_members->updatePassed($id_data['usr_id'], true);
311  }
312  $this->course_members_array[$id_data['usr_id']] = "added";
313  } else {
314  // the member does exist. Now update status etc. only
315  if ($a_attribs['blocked'] == 'Yes') {
316  $this->course_members->updateBlocked($id_data['usr_id'], true);
317  }
318  if ($a_attribs['passed'] == 'Yes') {
319  $this->course_members->updatePassed($id_data['usr_id'], true);
320  }
321  }
322  } elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isMember($id_data['usr_id'])) {
323  // if action set and detach and is member of course
324  $this->course_members->delete($id_data['usr_id']);
325  }
326  }
327 
328 
336  private function handleAdmin($a_attribs, $id_data)
337  {
338  global $rbacadmin;
339 
340  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach') {
341  // if action not set, or attach
342  if (!array_key_exists($id_data['usr_id'], $this->course_members_array)) {
343  // add only if member is not assigned yet
344  $this->course_members->add($id_data['usr_id'], IL_CRS_ADMIN);
345  if ($a_attribs['notification'] == 'Yes') {
346  $this->course_members->updateNotification($id_data['usr_id'], true);
347  }
348  if ($a_attribs['passed'] == 'Yes') {
349  $this->course_members->updatePassed($id_data['usr_id'], true);
350  }
351  $this->course_members_array[$id_data['usr_id']] = "added";
352  } else {
353  // update
354  if ($a_attribs['notification'] == 'Yes') {
355  $this->course_members->updateNotification($id_data['usr_id'], true);
356  }
357  if ($a_attribs['passed'] == 'Yes') {
358  $this->course_members->updatePassed($id_data['usr_id'], true);
359  }
360  $this->course_members->updateBlocked($id_data['usr_id'], false);
361  }
362  } elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isAdmin($id_data['usr_id'])) {
363  // if action set and detach and is admin of course
364  $this->course_members->delete($id_data['usr_id']);
365  }
366  }
367 
368 
376  private function handleTutor($a_attribs, $id_data)
377  {
378  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach') {
379  // if action not set, or attach
380  if (!array_key_exists($id_data['usr_id'], $this->course_members_array)) {
381  // add only if member is not assigned yet
382  $this->course_members->add($id_data['usr_id'], IL_CRS_TUTOR);
383  if ($a_attribs['notification'] == 'Yes') {
384  $this->course_members->updateNotification($id_data['usr_id'], true);
385  }
386  if ($a_attribs['passed'] == 'Yes') {
387  $this->course_members->updatePassed($id_data['usr_id'], true);
388  }
389  $this->course_members_array[$id_data['usr_id']] = "added";
390  } else {
391  if ($a_attribs['notification'] == 'Yes') {
392  $this->course_members->updateNotification($id_data['usr_id'], true);
393  }
394  if ($a_attribs['passed'] == 'Yes') {
395  $this->course_members->updatePassed($id_data['usr_id'], true);
396  }
397  $this->course_members->updateBlocked($id_data['usr_id'], false);
398  }
399  } elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isTutor($id_data['usr_id'])) {
400  // if action set and detach and is tutor of course
401  $this->course_members->delete($id_data['usr_id']);
402  }
403  }
404 
405 
406 
413  private function handleSubscriber($a_attribs, $id_data)
414  {
415  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach') {
416  // if action not set, or attach
417  if (!$this->course_members->isSubscriber($id_data['usr_id'])) {
418  // add only if not exist
419  $this->course_members->addSubscriber($id_data['usr_id']);
420  }
421  $this->course_members->updateSubscriptionTime($id_data['usr_id'], $a_attribs['subscriptionTime']);
422  } elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isSubscriber($id_data['usr_id'])) {
423  // if action set and detach and is subscriber
424  $this->course_members->deleteSubscriber($id_data["usr_id"]);
425  }
426  }
427 
434  private function handleWaitingList($a_attribs, $id_data)
435  {
436  if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach') {
437  // if action not set, or attach
438  if (!$this->course_waiting_list->isOnList($id_data['usr_id'])) {
439  // add only if not exists
440  $this->course_waiting_list->addToList($id_data['usr_id']);
441  }
442  $this->course_waiting_list->updateSubscriptionTime($id_data['usr_id'], $a_attribs['subscriptionTime']);
443  } elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_waiting_list->isOnList($id_data['usr_id'])) {
444  // if action set and detach and is on list
445  $this->course_waiting_list->removeFromList($id_data['usr_id']);
446  }
447  }
448 
449 
456  public function handlerEndTag($a_xml_parser, $a_name)
457  {
458  if ($this->in_meta_data) {
459  parent::handlerEndTag($a_xml_parser, $a_name);
460  }
461 
462  switch ($a_name) {
463  case 'Course':
464 
465  $this->log->write('CourseXMLParser: import_id = ' . $this->course_obj->getImportId());
466  $this->course_obj->MDUpdateListener('General');
467  $this->course_obj->update();
468  $this->adv_md_handler->save();
469  break;
470 
471  case 'Settings':
472  $this->in_settings = false;
473  break;
474 
475  case 'Availability':
476  $this->in_availability = false;
477  break;
478 
479  case 'Registration':
480  $this->in_registration = false;
481  break;
482 
483 
484  case 'Start':
485  if ($this->in_availability) {
486  $this->course_obj->setActivationStart(trim($this->cdata));
487  }
488  if ($this->in_registration) {
489  $this->course_obj->setSubscriptionStart(trim($this->cdata));
490  }
491  if ($this->in_period) {
492  if ((int) $this->cdata) {
493  $this->course_obj->setCourseStart(new ilDate((int) $this->cdata, IL_CAL_UNIX));
494  }
495  }
496  break;
497 
498  case 'End':
499  if ($this->in_availability) {
500  $this->course_obj->setActivationEnd(trim($this->cdata));
501  }
502  if ($this->in_registration) {
503  $this->course_obj->setSubscriptionEnd(trim($this->cdata));
504  }
505  if ($this->in_period) {
506  if ((int) $this->cdata) {
507  $this->course_obj->setCourseEnd(new ilDate((int) $this->cdata, IL_CAL_UNIX));
508  }
509  }
510  break;
511 
512  case 'Syllabus':
513  $this->course_obj->setSyllabus(trim($this->cdata));
514  break;
515 
516 
517  case 'ImportantInformation':
518  $this->course_obj->setImportantInformation(trim($this->cdata));
519  break;
520 
521  case 'ViewMode':
522  $this->course_obj->setViewMode(trim($this->cdata));
523  break;
524 
525  case 'Name':
526  $this->course_obj->setContactName(trim($this->cdata));
527  break;
528 
529  case 'Responsibility':
530  $this->course_obj->setContactResponsibility(trim($this->cdata));
531  break;
532 
533  case 'Phone':
534  $this->course_obj->setContactPhone(trim($this->cdata));
535  break;
536 
537  case 'Email':
538  $this->course_obj->setContactEmail(trim($this->cdata));
539  break;
540 
541  case 'Consultation':
542  $this->course_obj->setContactConsultation(trim($this->cdata));
543  break;
544 
545  case 'Password':
546  $this->course_obj->setSubscriptionPassword(trim($this->cdata));
547  break;
548 
549  case 'MetaData':
550  $this->in_meta_data = false;
551  parent::handlerEndTag($a_xml_parser, $a_name);
552  break;
553 
554  case 'ContainerSetting':
555  if ($this->current_container_setting) {
557  $this->course_obj->getId(),
559  $this->cdata
560  );
561  }
562  break;
563 
564  case 'Period':
565  $this->in_period = false;
566  break;
567 
568  case 'WaitingListAutoFill':
569  $this->course_obj->setWaitingListAutoFill($this->cdata);
570  break;
571 
572  case 'CancellationEnd':
573  if ((int) $this->cdata) {
574  $this->course_obj->setCancellationEnd(new ilDate((int) $this->cdata, IL_CAL_UNIX));
575  }
576  break;
577 
578  case 'MinMembers':
579  if ((int) $this->cdata) {
580  $this->course_obj->setSubscriptionMinMembers((int) $this->cdata);
581  }
582  break;
583  }
584  $this->cdata = '';
585 
586  return;
587  }
588 
595  public function handlerCharacterData($a_xml_parser, $a_data)
596  {
597  // call meta data handler
598  if ($this->in_meta_data) {
599  parent::handlerCharacterData($a_xml_parser, $a_data);
600  }
601  if ($a_data != "\n") {
602  // Replace multiple tabs with one space
603  $a_data = preg_replace("/\t+/", " ", $a_data);
604 
605  $this->cdata .= $a_data;
606  }
607  }
608 
609  // PRIVATE
610  public function __parseId($a_id)
611  {
612  global $ilias;
613 
614  $fields = explode('_', $a_id);
615 
616  if (!is_array($fields) or
617  $fields[0] != 'il' or
618  !is_numeric($fields[1]) or
619  $fields[2] != 'usr' or
620  !is_numeric($fields[3])) {
621  return false;
622  }
623  if ($id = ilObjUser::_getImportedUserId($a_id)) {
624  return array('imported' => true,
625  'local' => false,
626  'usr_id' => $id);
627  }
628  if (($fields[1] == $ilias->getSetting('inst_id', 0)) and strlen(ilObjUser::_lookupLogin($fields[3]))) {
629  return array('imported' => false,
630  'local' => true,
631  'usr_id' => $fields[3]);
632  }
633  return false;
634  }
635 }
static _lookupLogin($a_user_id)
lookup login
const IL_CRS_ACTIVATION_LIMITED
__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.
if(!array_key_exists('StateId', $_REQUEST)) $id
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_ACTIVATION_OFFLINE
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.
Create styles array
The data for the language used.
Interface definition for sax subset parsers.
Controller class for sax element handlers.
static _writeImportId($a_obj_id, $a_import_id)
write import id to db (static)
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
const IL_CRS_ACTIVATION_UNLIMITED