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

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('classes/class.ilObjUser.php');
00028 
00039 include_once 'course/classes/class.ilCourseMembers.php';
00040 include_once 'course/classes/class.ilCourseWaitingList.php';
00041 
00042 class ilCourseXMLParser extends ilMDSaxParser
00043 {
00044         var $lng;
00045         var $md_obj = null;                     // current meta data object
00046 
00056         function ilCourseXMLParser(&$a_course_obj, $a_xml_file = '')
00057         {
00058                 global $lng,$ilLog;
00059 
00060                 parent::ilMDSaxParser($a_xml_file);
00061 
00062                 $this->log =& $ilLog;
00063                 
00064                 $this->course_obj =& $a_course_obj;
00065                 $this->course_members = new ilCourseMembers($this->course_obj);
00066                 $this->course_waiting_list = new ilCourseWaitingList($this->course_obj->getId());
00067 
00068                 $this->md_obj = new ilMD($this->course_obj->getId(),0,'crs');
00069                 
00070                 $this->setMDObject($this->md_obj);
00071 
00072                 $this->lng =& $lng;
00073         }
00074 
00081         function setHandlers($a_xml_parser)
00082         {
00083                 xml_set_object($a_xml_parser,$this);
00084                 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
00085                 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
00086         }
00087 
00088         
00089 
00090 
00098         function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
00099         {
00100                 if($this->in_meta_data)
00101                 {
00102                         parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
00103 
00104                         return;
00105                 }
00106 
00107                 switch($a_name)
00108                 {
00109                         case 'Course':
00110 
00111                                 if(strlen($a_attribs['importId']))
00112                                 {
00113                                         $this->log->write("CourseXMLParser: importId = ".$a_attribs['importId']);
00114                                         $this->course_obj->setImportId($a_attribs['importId']);
00115                                         ilObject::_writeImportId($this->course_obj->getId(),$a_attribs['importId']);
00116                                 }
00117                                 break;
00118 
00119                         case 'Admin':
00120                                 if($id_data = $this->__parseId($a_attribs['id']))
00121                                 {
00122                                         if($id_data['local'] or $id_data['imported'])
00123                                         {
00124                                                 $this->course_members->add(new ilObjUser($id_data['usr_id']),
00125                                                                                                    $this->course_members->ROLE_ADMIN,
00126                                                                                                    $a_attribs['notification'] == 'Yes' ? 1 : 0,
00127                                                                                                    $a_attribs['passed'] == 'Yes' ? 1 : 0);
00128                                         }
00129                                 }
00130                                 break;
00131 
00132                         case 'Tutor':
00133                                 if($id_data = $this->__parseId($a_attribs['id']))
00134                                 {
00135                                         if($id_data['local'] or $id_data['imported'])
00136                                         {
00137                                                 $this->course_members->add(new ilObjUser($id_data['usr_id']),
00138                                                                                                    $this->course_members->ROLE_TUTOR,
00139                                                                                                    $a_attribs['notification'] == 'Yes' ? 1 : 0,
00140                                                                                                    $a_attribs['passed'] == 'Yes' ? 1 : 0);
00141                                         }
00142                                 }
00143                                 break;
00144 
00145                         case 'Member':
00146                                 if($id_data = $this->__parseId($a_attribs['id']))
00147                                 {
00148                                         if($id_data['local'] or $id_data['imported'])
00149                                         {
00150                                                 $this->course_members->add(new ilObjUser($id_data['usr_id']),
00151                                                                                                    $this->course_members->ROLE_MEMBER,
00152                                                                                                    $a_attribs['blocked'] == 'Yes' ? 
00153                                                                                                    $this->course_members->STATUS_BLOCKED : 
00154                                                                                                    $this->course_members->STATUS_UNBLOCKED,
00155                                                                                                    $a_attribs['passed'] == 'Yes' ? 1 : 0);
00156                                         }
00157                                 }
00158                                 break;
00159 
00160                         case 'Subscriber':
00161                                 if($id_data = $this->__parseId($a_attribs['id']))
00162                                 {
00163                                         if($id_data['local'] or $id_data['imported'])
00164                                         {
00165                                                 $this->course_members->addSubscriber($id_data['usr_id']);
00166                                                 $this->course_members->updateSubscriptionTime($id_data['usr_id'],$a_attribs['subscriptionTime']);
00167                                         }
00168                                 }
00169                                 break;
00170 
00171                         case 'WaitingList':
00172                                 if($id_data = $this->__parseId($a_attribs['id']))
00173                                 {
00174                                         if($id_data['local'] or $id_data['imported'])
00175                                         {
00176                                                 $this->course_waiting_list->addToList($id_data['usr_id']);
00177                                                 $this->course_waiting_list->updateSubscriptionTime($id_data['usr_id'],$a_attribs['subscriptionTime']);
00178                                         }
00179                                 }
00180                                 break;
00181                                 
00182 
00183                         case 'Settings':
00184                                 $this->in_settings = true;
00185                                 break;
00186                         case 'Availability':
00187                                 $this->in_availability = true;
00188                                 break;
00189 
00190                         case 'NotAvailable':
00191                                 $this->course_obj->setOfflineStatus(true);
00192                                 break;
00193 
00194                         case 'Unlimited':
00195                                 if($this->in_availability)
00196                                 {
00197                                         $this->course_obj->setActivationUnlimitedStatus(true);
00198                                         $this->course_obj->setOfflineStatus(false);
00199                                 }
00200                                 break;
00201                         case 'TemporarilyAvailable':
00202                                 if($this->in_availability)
00203                                 {
00204                                         $this->course_obj->setActivationUnlimitedStatus(false);
00205                                         $this->course_obj->setOfflineStatus(false);
00206                                 }
00207                                 break;
00208 
00209                         case 'Start':
00210                                 break;
00211                                 
00212                         case 'End':
00213                                 break;
00214 
00215                         case 'Syllabus':
00216                                 break;
00217 
00218                         case 'Contact':
00219                                 break;
00220 
00221                         case 'Name':
00222                         case 'Responsibility':
00223                         case 'Phone':
00224                         case 'Email':
00225                         case 'Consultation':
00226                                 break;
00227 
00228                         case 'Registration':
00229                                 $this->in_registration = true;
00230                                 
00231                                 switch($a_attribs['registrationType'])
00232                                 {
00233                                         case 'Confirmation':
00234                                                 $this->course_obj->setSubscriptionType($this->course_obj->SUBSCRIPTION_CONFIRMATION);
00235                                                 break;
00236 
00237                                         case 'Direct':
00238                                                 $this->course_obj->setSubscriptionType($this->course_obj->SUBSCRIPTION_DIRECT);
00239                                                 break;
00240                                                 
00241                                         case 'Password':
00242                                                 $this->course_obj->setSubscriptionType($this->course_obj->SUBSCRIPTION_PASSWORD);
00243                                                 break;
00244                                 }
00245                                 $this->course_obj->setSubscriptionMaxMembers((int) $a_attribs['maxMembers']);
00246                                 $this->course_obj->setSubscriptionNotify($a_attribs['notification'] == 'Yes' ? true : false);
00247                                 $this->course_obj->enableWaitingList($a_attribs['waitingList'] == 'Yes' ? true : false);
00248                                 break;
00249 
00250                         case 'Sort':
00251                                 switch($a_attribs['type'])
00252                                 {
00253                                         case 'Manual':
00254                                                 $this->course_obj->setOrderType($this->course_obj->SORT_MANUAL);
00255                                                 break;
00256 
00257                                         case 'Title':
00258                                                 $this->course_obj->setOrderType($this->course_obj->SORT_TITLE);
00259                                                 break;
00260 
00261                                         case 'Activation':
00262                                                 $this->course_obj->setOrderType($this->course_obj->SORT_ACTIVATION);
00263                                                 break;
00264                                 }
00265                                 break;
00266 
00267 
00268                         case 'Archive':
00269                                 $this->in_archive = true;
00270                                 switch($a_attribs['Access'])
00271                                 {
00272                                         case 'Disabled':
00273                                                 $this->course_obj->setArchiveType($this->course_obj->ARCHIVE_DISABLED);
00274                                                 break;
00275 
00276                                         case 'Read':
00277                                                 $this->course_obj->setArchiveType($this->course_obj->ARCHIVE_READ);
00278                                                 break;
00279 
00280                                         case 'Download':
00281                                                 $this->course_obj->setArchiveType($this->course_obj->ARCHIVE_DOWNLOAD);
00282                                                 break;
00283                                 }
00284                                 break;
00285 
00286                         case 'Disabled':
00287                                 $this->course_obj->setSubscriptionType($this->course_obj->SUBSCRIPTION_DEACTIVATED);
00288                                 break;
00289                                 
00290                         case "MetaData":
00291                                 $this->in_meta_data = true;
00292                                 parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
00293                                 break;
00294 
00295                 }
00296         }
00297 
00298 
00299 
00306         function handlerEndTag($a_xml_parser,$a_name)
00307         {
00308                 if($this->in_meta_data)
00309                 {
00310                         parent::handlerEndTag($a_xml_parser,$a_name);
00311                 }
00312 
00313                 switch($a_name)
00314                 {
00315                         case 'Course':
00316 
00317                                 $this->log->write('CourseXMLParser: import_id = '.$this->course_obj->getImportId());
00318                                 $this->course_obj->updateSettings();
00319                                 break;
00320 
00321                         case 'Settings':
00322                                 $this->in_settings = false;
00323                                 break;
00324 
00325                         case 'Availability':
00326                                 $this->in_availability = false;
00327                                 break;
00328 
00329                         case 'Registration':
00330                                 $this->in_registration = false;
00331                                 break;
00332 
00333                         case 'Archive':
00334                                 $this->in_archive = false;
00335                                 break;
00336 
00337                         case 'Start':
00338                                 if($this->in_availability)
00339                                 {
00340                                         $this->course_obj->setActivationStart(trim($this->cdata));
00341                                 }
00342                                 if($this->in_registration)
00343                                 {
00344                                         $this->course_obj->setSubscriptionStart(trim($this->cdata));
00345                                 }
00346                                 if($this->in_archive)
00347                                 {
00348                                         $this->course_obj->setArchiveStart(trim($this->cdata));
00349                                 }
00350                                 break;
00351 
00352                         case 'End':
00353                                 if($this->in_availability)
00354                                 {
00355                                         $this->course_obj->setActivationEnd(trim($this->cdata));
00356                                 }
00357                                 if($this->in_registration)
00358                                 {
00359                                         $this->course_obj->setSubscriptionEnd(trim($this->cdata));
00360                                 }
00361                                 if($this->in_archive)
00362                                 {
00363                                         $this->course_obj->setArchiveEnd(trim($this->cdata));
00364                                 }
00365                                 break;
00366 
00367                         case 'Syllabus':
00368                                 $this->course_obj->setSyllabus(trim($this->cdata));
00369                                 break;
00370 
00371                         case 'Name':
00372                                 $this->course_obj->setContactName(trim($this->cdata));
00373                                 break;
00374 
00375                         case 'Responsibility':
00376                                 $this->course_obj->setContactResponsibility(trim($this->cdata));
00377                                 break;
00378 
00379                         case 'Phone':
00380                                 $this->course_obj->setContactPhone(trim($this->cdata));
00381                                 break;
00382 
00383                         case 'Email':
00384                                 $this->course_obj->setContactEmail(trim($this->cdata));
00385                                 break;
00386 
00387                         case 'Consultation':
00388                                 $this->course_obj->setContactConsultation(trim($this->cdata));
00389                                 break;
00390 
00391                         case 'Password':
00392                                 $this->course_obj->setSubscriptionPassword(trim($this->cdata));
00393                                 break;
00394 
00395                         case 'MetaData':
00396                                 $this->in_meta_data = false;
00397                                 parent::handlerEndTag($a_xml_parser,$a_name);
00398                                 break;
00399                 }
00400                 $this->cdata = '';
00401 
00402                 return;
00403         }
00404 
00411         function handlerCharacterData($a_xml_parser,$a_data)
00412         {
00413                 // call meta data handler
00414                 if($this->in_meta_data)
00415                 {
00416                         parent::handlerCharacterData($a_xml_parser,$a_data);
00417                 }
00418                 if($a_data != "\n")
00419                 {
00420                         // Replace multiple tabs with one space
00421                         $a_data = preg_replace("/\t+/"," ",$a_data);
00422 
00423                         $this->cdata .= $a_data;
00424                 }
00425 
00426 
00427         }
00428 
00429         // PRIVATE
00430         function __parseId($a_id)
00431         {
00432                 global $ilias;
00433 
00434                 $fields = explode('_',$a_id);
00435 
00436                 if(!is_array($fields) or
00437                    $fields[0] != 'il' or
00438                    !is_numeric($fields[1]) or
00439                    $fields[2] != 'usr' or
00440                    !is_numeric($fields[3]))
00441                 {
00442                         return false;
00443                 }
00444                 if($id = ilObjUser::_getImportedUserId($a_id))
00445                 {
00446                         return array('imported' => true,
00447                                                  'local' => false,
00448                                                  'usr_id' => $id);
00449                 }
00450                 if(($fields[1] == $ilias->getSetting('inst_id',0)) and strlen(ilObjUser::_lookupLogin($fields[3])))
00451                 {
00452                         return array('imported' => false,
00453                                                  'local' => true,
00454                                                  'usr_id' => $fields[3]);
00455                 }
00456                 return false;
00457         }
00458 
00459 }
00460 ?>

Generated on Fri Dec 13 2013 11:57:58 for ILIAS Release_3_6_x_branch .rev 46809 by  doxygen 1.7.1