• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Modules/Course/classes/class.ilCourseXMLParser.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 
00025 include_once("Services/MetaData/classes/class.ilMDSaxParser.php");
00026 include_once("Services/MetaData/classes/class.ilMD.php");
00027 include_once('Services/Utilities/interfaces/interface.ilSaxSubsetParser.php');
00028 include_once('Services/Utilities/classes/class.ilSaxController.php');
00029 
00030 
00040 include_once 'Modules/Course/classes/class.ilCourseParticipants.php';
00041 include_once 'Modules/Course/classes/class.ilCourseWaitingList.php';
00042 
00043 class ilCourseXMLParser extends ilMDSaxParser implements ilSaxSubsetParser
00044 {
00045         var $lng;
00046         var $md_obj = null;                     // current meta data object
00047 
00057         function ilCourseXMLParser($a_course_obj, $a_xml_file = '')
00058         {
00059                 global $lng,$ilLog;
00060 
00061                 parent::ilMDSaxParser($a_xml_file);
00062 
00063                 $this->sax_controller = new ilSaxController();
00064 
00065                 $this->log =& $ilLog;
00066 
00067                 $this->course_obj =& $a_course_obj;
00068                 $this->course_members = ilCourseParticipants::_getInstanceByObjId($this->course_obj->getId());
00069                 $this->course_waiting_list = new ilCourseWaitingList($this->course_obj->getId());
00070                 // flip the array so we can use array_key_exists
00071                 $this->course_members_array =  array_flip($this->course_members->getParticipants());
00072 
00073                 $this->md_obj = new ilMD($this->course_obj->getId(),0,'crs');
00074 
00075                 $this->setMDObject($this->md_obj);
00076 
00077                 $this->lng =& $lng;
00078         }
00079 
00086         function setHandlers($a_xml_parser)
00087         {
00088                 $this->sax_controller->setHandlers($a_xml_parser);
00089                 $this->sax_controller->setDefaultElementHandler($this);
00090                 
00091                 include_once('Services/AdvancedMetaData/classes/class.ilAdvancedMDValueParser.php');
00092                 $this->sax_controller->setElementHandler(
00093                         $this->adv_md_handler = new ilAdvancedMDValueParser($this->course_obj->getId()),
00094                         'AdvancedMetaData');
00095         }
00096 
00097 
00098 
00099 
00107         function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
00108         {
00109                 if($this->in_meta_data)
00110                 {
00111                         parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
00112 
00113                         return;
00114                 }
00115 
00116                 switch($a_name)
00117                 {
00118                         case 'Course':
00119 
00120                                 if(strlen($a_attribs['importId']))
00121                                 {
00122                                         $this->log->write("CourseXMLParser: importId = ".$a_attribs['importId']);
00123                                         $this->course_obj->setImportId($a_attribs['importId']);
00124                                         ilObject::_writeImportId($this->course_obj->getId(),$a_attribs['importId']);
00125                                 }
00126                                 break;
00127 
00128                         case 'Admin':
00129                                 if($id_data = $this->__parseId($a_attribs['id']))
00130                                 {
00131                                         if($id_data['local'] or $id_data['imported'])
00132                                         {
00133                                                 $this->handleAdmin($a_attribs, $id_data);
00134                                         }
00135                                 }
00136                                 break;
00137 
00138                         case 'Tutor':
00139                                 if($id_data = $this->__parseId($a_attribs['id']))
00140                                 {
00141                                         if($id_data['local'] or $id_data['imported'])
00142                                         {
00143                                                 $this->handleTutor($a_attribs, $id_data);
00144 
00145                                         }
00146                                 }
00147                                 break;
00148 
00149                         case 'Member':
00150                                 if($id_data = $this->__parseId($a_attribs['id']))
00151                                 {
00152                                         if($id_data['local'] or $id_data['imported'])
00153                                         {
00154                                                 $this->handleMember($a_attribs, $id_data);
00155                                         }
00156                                 }
00157                                 break;
00158 
00159                         case 'Subscriber':
00160                                 if($id_data = $this->__parseId($a_attribs['id']))
00161                                 {
00162                                         if($id_data['local'] or $id_data['imported'])
00163                                         {
00164                                                 $this->handleSubscriber($a_attribs, $id_data);
00165                                         }
00166                                 }
00167                                 break;
00168 
00169                         case 'WaitingList':
00170                                 if($id_data = $this->__parseId($a_attribs['id']))
00171                                 {
00172                                         if($id_data['local'] or $id_data['imported'])
00173                                         {
00174                                                 $this->handleWaitingList($a_attribs, $id_data);
00175                                         }
00176                                 }
00177                                 break;
00178 
00179 
00180                         case 'Settings':
00181                                 $this->in_settings = true;
00182                                 break;
00183                         case 'Availability':
00184                                 $this->in_availability = true;
00185                                 break;
00186 
00187                         case 'NotAvailable':
00188                                 if($this->in_availability)
00189                                 {
00190                                         $this->course_obj->setActivationType(IL_CRS_ACTIVATION_OFFLINE);
00191                                 }
00192                                 elseif($this->in_registration)
00193                                 {
00194                                         $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_DEACTIVATED);
00195                                 }
00196 
00197                                 break;
00198 
00199                         case 'Unlimited':
00200                                 if($this->in_availability)
00201                                 {
00202                                         $this->course_obj->setActivationType(IL_CRS_ACTIVATION_UNLIMITED);
00203                                 }
00204                                 elseif($this->in_registration)
00205                                 {
00206                                         $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_UNLIMITED);
00207                                 }
00208 
00209                                 break;
00210                         case 'TemporarilyAvailable':
00211                                 if($this->in_availability)
00212                                 {
00213                                         $this->course_obj->setActivationType(IL_CRS_ACTIVATION_LIMITED);
00214                                 }
00215                                 elseif($this->in_registration)
00216                                 {
00217                                         $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_LIMITED);
00218                                 }
00219                                 break;
00220 
00221                         case 'Start':
00222                                 break;
00223 
00224                         case 'End':
00225                                 break;
00226 
00227                         case 'Syllabus':
00228                                 break;
00229 
00230                         case 'Contact':
00231                                 break;
00232 
00233                         case 'Name':
00234                         case 'Responsibility':
00235                         case 'Phone':
00236                         case 'Email':
00237                         case 'Consultation':
00238                                 break;
00239 
00240                         case 'Registration':
00241                                 $this->in_registration = true;
00242 
00243                                 switch($a_attribs['registrationType'])
00244                                 {
00245                                         case 'Confirmation':
00246                                                 $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_CONFIRMATION);
00247                                                 break;
00248 
00249                                         case 'Direct':
00250                                                 $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_DIRECT);
00251                                                 break;
00252 
00253                                         case 'Password':
00254                                                 $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_PASSWORD);
00255                                                 break;
00256                                 }
00257                                 $this->course_obj->setSubscriptionMaxMembers((int) $a_attribs['maxMembers']);
00258                                 $this->course_obj->setSubscriptionNotify($a_attribs['notification'] == 'Yes' ? true : false);
00259                                 $this->course_obj->enableWaitingList($a_attribs['waitingList'] == 'Yes' ? true : false);
00260                                 break;
00261 
00262                         case 'Sort':
00263                                 switch($a_attribs['type'])
00264                                 {
00265                                         case 'Manual':
00266                                                 $this->course_obj->setOrderType(IL_CRS_SORT_MANUAL);
00267                                                 break;
00268 
00269                                         case 'Title':
00270                                                 $this->course_obj->setOrderType(IL_CRS_SORT_TITLE);
00271                                                 break;
00272 
00273                                         case 'Activation':
00274                                                 $this->course_obj->setOrderType(IL_CRS_SORT_ACTIVATION);
00275                                                 break;
00276                                 }
00277                                 break;
00278 
00279 
00280                         case 'Archive':
00281                                 $this->in_archive = true;
00282                                 switch($a_attribs['Access'])
00283                                 {
00284                                         case 'Disabled':
00285                                                 $this->course_obj->setArchiveType(IL_CRS_ARCHIVE_NONE);
00286                                                 break;
00287 
00288                                         case 'Read':
00289                                                 $this->course_obj->setArchiveType(IL_CRS_ARCHIVE_NONE);
00290                                                 #$this->course_obj->setViewMode(IL_CRS_VIEW_ARCHIVE);
00291                                                 break;
00292 
00293                                         case 'Download':
00294                                                 #$this->course_obj->setViewMode(IL_CRS_VIEW_ARCHIVE);
00295                                                 $this->course_obj->setArchiveType(IL_CRS_ARCHIVE_DOWNLOAD);
00296                                                 break;
00297                                 }
00298                                 break;
00299 
00300                         case 'Disabled':
00301                                 $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_DEACTIVATED);
00302                                 break;
00303 
00304                         case "MetaData":
00305                                 $this->in_meta_data = true;
00306                                 parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
00307                                 break;
00308 
00309                 }
00310         }
00311 
00320         private function handleMember ($a_attribs, $id_data) 
00321         {
00322                 if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
00323                         // if action not set, or set and attach
00324                 {
00325                         if (!array_key_exists($id_data['usr_id'], $this->course_members_array))
00326                         // add only if member is not yet assigned as tutor or admin
00327                         {
00328                                 $this->course_members->add($id_data['usr_id'],IL_CRS_MEMBER);
00329                                 if($a_attribs['blocked'] == 'Yes')
00330                                 {
00331                                         $this->course_members->updateBlocked($id_data['usr_id'],true);
00332                                 }
00333                                 if($a_attribs['passed'] == 'Yes')
00334                                 {
00335                                         $this->course_members->updatePassed($id_data['usr_id'],true);
00336                                 }
00337                                 $this->course_members_array[$id_data['usr_id']] = "added";
00338                         } 
00339                         else
00340                         // the member does exist. Now update status etc. only
00341                         {
00342                                 if($a_attribs['blocked'] == 'Yes')
00343                                 {
00344                                         $this->course_members->updateBlocked($id_data['usr_id'],true);
00345                                 }
00346                                 if($a_attribs['passed'] == 'Yes')
00347                                 {
00348                                         $this->course_members->updatePassed($id_data['usr_id'],true);
00349                                 }
00350                         }
00351                 }
00352                 elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isMember($id_data['usr_id']))
00353                 // if action set and detach and is member of course
00354                 {
00355                         $this->course_members->delete($id_data['usr_id']);
00356                 }
00357 
00358         }
00359 
00360 
00368         private function handleAdmin ($a_attribs, $id_data) 
00369         {
00370                 global $rbacadmin;
00371         
00372                 if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
00373                         // if action not set, or attach
00374                 {
00375                         if (!array_key_exists($id_data['usr_id'], $this->course_members_array))
00376                         // add only if member is not assigned yet
00377                         {
00378                                 $this->course_members->add($id_data['usr_id'],IL_CRS_ADMIN);
00379                                 if($a_attribs['notification'] == 'Yes')
00380                                 {
00381                                         $this->course_members->updateNotification($id_data['usr_id'],true);
00382                                 }
00383                                 if($a_attribs['passed'] == 'Yes')
00384                                 {
00385                                         $this->course_members->updatePassed($id_data['usr_id'],true);
00386                                 }
00387                                 $this->course_members_array[$id_data['usr_id']] = "added";
00388                         }
00389                         else
00390                         // update
00391                         {
00392                                 if($a_attribs['notification'] == 'Yes')
00393                                 {
00394                                         $this->course_members->updateNotification($id_data['usr_id'],true);
00395                                 }
00396                                 if($a_attribs['passed'] == 'Yes')
00397                                 {
00398                                         $this->course_members->updatePassed($id_data['usr_id'],true);
00399                                 }
00400                                 $this->course_members->updateBlocked($id_data['usr_id'],false);
00401                         }
00402                 }
00403                 elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isAdmin($id_data['usr_id']))
00404                 // if action set and detach and is admin of course
00405                 {
00406                         $this->course_members->delete($id_data['usr_id']);
00407                 }
00408 
00409         }
00410 
00411 
00419         private function handleTutor ($a_attribs, $id_data) {
00420                 if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
00421                         // if action not set, or attach
00422                 {
00423                         if (!array_key_exists($id_data['usr_id'], $this->course_members_array))
00424                         // add only if member is not assigned yet
00425                         {
00426                                 $this->course_members->add($id_data['usr_id'],IL_CRS_TUTOR);
00427                                 if($a_attribs['notification'] == 'Yes')
00428                                 {
00429                                         $this->course_members->updateNotification($id_data['usr_id'],true);
00430                                 }
00431                                 if($a_attribs['passed'] == 'Yes')
00432                                 {
00433                                         $this->course_members->updatePassed($id_data['usr_id'],true);
00434                                 }
00435                                 $this->course_members_array[$id_data['usr_id']] = "added";
00436                         }
00437                         else
00438                         {
00439                                 if($a_attribs['notification'] == 'Yes')
00440                                 {
00441                                         $this->course_members->updateNotification($id_data['usr_id'],true);
00442                                 }
00443                                 if($a_attribs['passed'] == 'Yes')
00444                                 {
00445                                         $this->course_members->updatePassed($id_data['usr_id'],true);
00446                                 }
00447                                 $this->course_members->updateBlocked($id_data['usr_id'],false);
00448                         }
00449                 }
00450                 elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isTutor($id_data['usr_id']))
00451                 // if action set and detach and is tutor of course
00452                 {
00453                         $this->course_members->delete($id_data['usr_id']);
00454                 }
00455 
00456         }
00457 
00458 
00459 
00466         private function handleSubscriber ($a_attribs, $id_data) {
00467                 if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
00468                         // if action not set, or attach
00469                 {
00470                         if (!$this->course_members->isSubscriber($id_data['usr_id']))
00471                         // add only if not exist
00472                         {
00473                                 $this->course_members->addSubscriber($id_data['usr_id']);
00474                         }
00475                         $this->course_members->updateSubscriptionTime($id_data['usr_id'],$a_attribs['subscriptionTime']);
00476 
00477                 }
00478                 elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_members->isSubscriber($id_data['usr_id']))
00479                 // if action set and detach and is subscriber
00480                 {
00481                         $this->course_members->deleteSubscriber($id_data["usr_id"]);
00482                 }
00483 
00484         }
00485 
00492         private function handleWaitingList ($a_attribs, $id_data) 
00493         {
00494                 if (!isset($a_attribs['action']) || $a_attribs['action'] == 'Attach')
00495                         // if action not set, or attach
00496                 {
00497                         if (!$this->course_waiting_list->isOnList($id_data['usr_id']))
00498                         // add only if not exists
00499                         {
00500                                 $this->course_waiting_list->addToList($id_data['usr_id']);
00501                         }
00502                         $this->course_waiting_list->updateSubscriptionTime($id_data['usr_id'],$a_attribs['subscriptionTime']);
00503 
00504                 }
00505                 elseif (isset($a_attribs['action']) && $a_attribs['action'] == 'Detach' && $this->course_waiting_list->isOnList($id_data['usr_id']))
00506                 // if action set and detach and is on list
00507                 {
00508                         $this->course_waiting_list->removeFromList($id_data['usr_id']);
00509                 }
00510 
00511         }
00512 
00513 
00520         function handlerEndTag($a_xml_parser,$a_name)
00521         {
00522                 if($this->in_meta_data)
00523                 {
00524                         parent::handlerEndTag($a_xml_parser,$a_name);
00525                 }
00526 
00527                 switch($a_name)
00528                 {
00529                         case 'Course':
00530 
00531                                 $this->log->write('CourseXMLParser: import_id = '.$this->course_obj->getImportId());
00532                                 $this->course_obj->updateSettings();
00533                                 $this->adv_md_handler->save();
00534                                 break;
00535 
00536                         case 'Settings':
00537                                 $this->in_settings = false;
00538                                 break;
00539 
00540                         case 'Availability':
00541                                 $this->in_availability = false;
00542                                 break;
00543 
00544                         case 'Registration':
00545                                 $this->in_registration = false;
00546                                 break;
00547 
00548                         case 'Archive':
00549                                 $this->in_archive = false;
00550                                 break;
00551 
00552                         case 'Start':
00553                                 if($this->in_availability)
00554                                 {
00555                                         $this->course_obj->setActivationStart(trim($this->cdata));
00556                                 }
00557                                 if($this->in_registration)
00558                                 {
00559                                         $this->course_obj->setSubscriptionStart(trim($this->cdata));
00560                                 }
00561                                 if($this->in_archive)
00562                                 {
00563                                         $this->course_obj->setArchiveStart(trim($this->cdata));
00564                                 }
00565                                 break;
00566 
00567                         case 'End':
00568                                 if($this->in_availability)
00569                                 {
00570                                         $this->course_obj->setActivationEnd(trim($this->cdata));
00571                                 }
00572                                 if($this->in_registration)
00573                                 {
00574                                         $this->course_obj->setSubscriptionEnd(trim($this->cdata));
00575                                 }
00576                                 if($this->in_archive)
00577                                 {
00578                                         $this->course_obj->setArchiveEnd(trim($this->cdata));
00579                                 }
00580                                 break;
00581 
00582                         case 'Syllabus':
00583                                 $this->course_obj->setSyllabus(trim($this->cdata));
00584                                 break;
00585 
00586 
00587                         case 'ImportantInformation':
00588                                 $this->course_obj->setImportantInformation(trim($this->cdata));
00589                                 break;
00590 
00591                         case 'Name':
00592                                 $this->course_obj->setContactName(trim($this->cdata));
00593                                 break;
00594 
00595                         case 'Responsibility':
00596                                 $this->course_obj->setContactResponsibility(trim($this->cdata));
00597                                 break;
00598 
00599                         case 'Phone':
00600                                 $this->course_obj->setContactPhone(trim($this->cdata));
00601                                 break;
00602 
00603                         case 'Email':
00604                                 $this->course_obj->setContactEmail(trim($this->cdata));
00605                                 break;
00606 
00607                         case 'Consultation':
00608                                 $this->course_obj->setContactConsultation(trim($this->cdata));
00609                                 break;
00610 
00611                         case 'Password':
00612                                 $this->course_obj->setSubscriptionPassword(trim($this->cdata));
00613                                 break;
00614 
00615                         case 'MetaData':
00616                                 $this->in_meta_data = false;
00617                                 parent::handlerEndTag($a_xml_parser,$a_name);
00618                                 break;
00619                 }
00620                 $this->cdata = '';
00621 
00622                 return;
00623         }
00624 
00631         function handlerCharacterData($a_xml_parser,$a_data)
00632         {
00633                 // call meta data handler
00634                 if($this->in_meta_data)
00635                 {
00636                         parent::handlerCharacterData($a_xml_parser,$a_data);
00637                 }
00638                 if($a_data != "\n")
00639                 {
00640                         // Replace multiple tabs with one space
00641                         $a_data = preg_replace("/\t+/"," ",$a_data);
00642 
00643                         $this->cdata .= $a_data;
00644                 }
00645         }
00646 
00647         // PRIVATE
00648         function __parseId($a_id)
00649         {
00650                 global $ilias;
00651 
00652                 $fields = explode('_',$a_id);
00653 
00654                 if(!is_array($fields) or
00655                    $fields[0] != 'il' or
00656                    !is_numeric($fields[1]) or
00657                    $fields[2] != 'usr' or
00658                    !is_numeric($fields[3]))
00659                 {
00660                         return false;
00661                 }
00662                 if($id = ilObjUser::_getImportedUserId($a_id))
00663                 {
00664                         return array('imported' => true,
00665                                                  'local' => false,
00666                                                  'usr_id' => $id);
00667                 }
00668                 if(($fields[1] == $ilias->getSetting('inst_id',0)) and strlen(ilObjUser::_lookupLogin($fields[3])))
00669                 {
00670                         return array('imported' => false,
00671                                                  'local' => true,
00672                                                  'usr_id' => $fields[3]);
00673                 }
00674                 return false;
00675         }
00676 
00677 }
00678 ?>

Generated on Fri Dec 13 2013 17:56:49 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1