Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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;
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 if($this->in_availability)
00192 {
00193 $this->course_obj->setActivationType(IL_CRS_ACTIVATION_OFFLINE);
00194 }
00195 elseif($this->in_registration)
00196 {
00197 $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_DEACTIVATED);
00198 }
00199
00200 break;
00201
00202 case 'Unlimited':
00203 if($this->in_availability)
00204 {
00205 $this->course_obj->setActivationType(IL_CRS_ACTIVATION_UNLIMITED);
00206 }
00207 elseif($this->in_registration)
00208 {
00209 $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_UNLIMITED);
00210 }
00211
00212 break;
00213 case 'TemporarilyAvailable':
00214 if($this->in_availability)
00215 {
00216 $this->course_obj->setActivationType(IL_CRS_ACTIVATION_LIMITED);
00217 }
00218 elseif($this->in_registration)
00219 {
00220 $this->course_obj->setSubscriptionLimitationType(IL_CRS_SUBSCRIPTION_LIMITED);
00221 }
00222 break;
00223
00224 case 'Start':
00225 break;
00226
00227 case 'End':
00228 break;
00229
00230 case 'Syllabus':
00231 break;
00232
00233 case 'Contact':
00234 break;
00235
00236 case 'Name':
00237 case 'Responsibility':
00238 case 'Phone':
00239 case 'Email':
00240 case 'Consultation':
00241 break;
00242
00243 case 'Registration':
00244 $this->in_registration = true;
00245
00246 switch($a_attribs['registrationType'])
00247 {
00248 case 'Confirmation':
00249 $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_CONFIRMATION);
00250 break;
00251
00252 case 'Direct':
00253 $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_DIRECT);
00254 break;
00255
00256 case 'Password':
00257 $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_PASSWORD);
00258 break;
00259 }
00260 $this->course_obj->setSubscriptionMaxMembers((int) $a_attribs['maxMembers']);
00261 $this->course_obj->setSubscriptionNotify($a_attribs['notification'] == 'Yes' ? true : false);
00262 $this->course_obj->enableWaitingList($a_attribs['waitingList'] == 'Yes' ? true : false);
00263 break;
00264
00265 case 'Sort':
00266 switch($a_attribs['type'])
00267 {
00268 case 'Manual':
00269 $this->course_obj->setOrderType(IL_CRS_SORT_MANUAL);
00270 break;
00271
00272 case 'Title':
00273 $this->course_obj->setOrderType(IL_CRS_SORT_TITLE);
00274 break;
00275
00276 case 'Activation':
00277 $this->course_obj->setOrderType(IL_CRS_SORT_ACTIVATION);
00278 break;
00279 }
00280 break;
00281
00282
00283 case 'Archive':
00284 $this->in_archive = true;
00285 switch($a_attribs['Access'])
00286 {
00287 case 'Disabled':
00288 $this->course_obj->setArchiveType(IL_CRS_ARCHIVE_NONE);
00289 break;
00290
00291 case 'Read':
00292 $this->course_obj->setArchiveType(IL_CRS_ARCHIVE_NONE);
00293 #$this->course_obj->setViewMode(IL_CRS_VIEW_ARCHIVE);
00294 break;
00295
00296 case 'Download':
00297 #$this->course_obj->setViewMode(IL_CRS_VIEW_ARCHIVE);
00298 $this->course_obj->setArchiveType(IL_CRS_ARCHIVE_DOWNLOAD);
00299 break;
00300 }
00301 break;
00302
00303 case 'Disabled':
00304 $this->course_obj->setSubscriptionType(IL_CRS_SUBSCRIPTION_DEACTIVATED);
00305 break;
00306
00307 case "MetaData":
00308 $this->in_meta_data = true;
00309 parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
00310 break;
00311
00312 }
00313 }
00314
00315
00316
00323 function handlerEndTag($a_xml_parser,$a_name)
00324 {
00325 if($this->in_meta_data)
00326 {
00327 parent::handlerEndTag($a_xml_parser,$a_name);
00328 }
00329
00330 switch($a_name)
00331 {
00332 case 'Course':
00333
00334 $this->log->write('CourseXMLParser: import_id = '.$this->course_obj->getImportId());
00335 $this->course_obj->updateSettings();
00336 break;
00337
00338 case 'Settings':
00339 $this->in_settings = false;
00340 break;
00341
00342 case 'Availability':
00343 $this->in_availability = false;
00344 break;
00345
00346 case 'Registration':
00347 $this->in_registration = false;
00348 break;
00349
00350 case 'Archive':
00351 $this->in_archive = false;
00352 break;
00353
00354 case 'Start':
00355 if($this->in_availability)
00356 {
00357 $this->course_obj->setActivationStart(trim($this->cdata));
00358 }
00359 if($this->in_registration)
00360 {
00361 $this->course_obj->setSubscriptionStart(trim($this->cdata));
00362 }
00363 if($this->in_archive)
00364 {
00365 $this->course_obj->setArchiveStart(trim($this->cdata));
00366 }
00367 break;
00368
00369 case 'End':
00370 if($this->in_availability)
00371 {
00372 $this->course_obj->setActivationEnd(trim($this->cdata));
00373 }
00374 if($this->in_registration)
00375 {
00376 $this->course_obj->setSubscriptionEnd(trim($this->cdata));
00377 }
00378 if($this->in_archive)
00379 {
00380 $this->course_obj->setArchiveEnd(trim($this->cdata));
00381 }
00382 break;
00383
00384 case 'Syllabus':
00385 $this->course_obj->setSyllabus(trim($this->cdata));
00386 break;
00387
00388 case 'Name':
00389 $this->course_obj->setContactName(trim($this->cdata));
00390 break;
00391
00392 case 'Responsibility':
00393 $this->course_obj->setContactResponsibility(trim($this->cdata));
00394 break;
00395
00396 case 'Phone':
00397 $this->course_obj->setContactPhone(trim($this->cdata));
00398 break;
00399
00400 case 'Email':
00401 $this->course_obj->setContactEmail(trim($this->cdata));
00402 break;
00403
00404 case 'Consultation':
00405 $this->course_obj->setContactConsultation(trim($this->cdata));
00406 break;
00407
00408 case 'Password':
00409 $this->course_obj->setSubscriptionPassword(trim($this->cdata));
00410 break;
00411
00412 case 'MetaData':
00413 $this->in_meta_data = false;
00414 parent::handlerEndTag($a_xml_parser,$a_name);
00415 break;
00416 }
00417 $this->cdata = '';
00418
00419 return;
00420 }
00421
00428 function handlerCharacterData($a_xml_parser,$a_data)
00429 {
00430
00431 if($this->in_meta_data)
00432 {
00433 parent::handlerCharacterData($a_xml_parser,$a_data);
00434 }
00435 if($a_data != "\n")
00436 {
00437
00438 $a_data = preg_replace("/\t+/"," ",$a_data);
00439
00440 $this->cdata .= $a_data;
00441 }
00442
00443
00444 }
00445
00446
00447 function __parseId($a_id)
00448 {
00449 global $ilias;
00450
00451 $fields = explode('_',$a_id);
00452
00453 if(!is_array($fields) or
00454 $fields[0] != 'il' or
00455 !is_numeric($fields[1]) or
00456 $fields[2] != 'usr' or
00457 !is_numeric($fields[3]))
00458 {
00459 return false;
00460 }
00461 if($id = ilObjUser::_getImportedUserId($a_id))
00462 {
00463 return array('imported' => true,
00464 'local' => false,
00465 'usr_id' => $id);
00466 }
00467 if(($fields[1] == $ilias->getSetting('inst_id',0)) and strlen(ilObjUser::_lookupLogin($fields[3])))
00468 {
00469 return array('imported' => false,
00470 'local' => true,
00471 'usr_id' => $fields[3]);
00472 }
00473 return false;
00474 }
00475
00476 }
00477 ?>