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 include_once("./classes/class.ilSaxParser.php");
00025
00026 define ("IL_MO_PARSE_QTI", 1);
00027 define ("IL_MO_VERIFY_QTI", 2);
00028
00038 class ilQTIParser extends ilSaxParser
00039 {
00040 var $lng;
00041 var $hasRootElement;
00042 var $path;
00043 var $items;
00044 var $item;
00045 var $depth;
00046 var $qti_element;
00047 var $in_presentation;
00048 var $in_response;
00049 var $render_type;
00050 var $response_label;
00051 var $material;
00052 var $matimage;
00053 var $response;
00054 var $resprocessing;
00055 var $outcomes;
00056 var $decvar;
00057 var $respcondition;
00058 var $setvar;
00059 var $displayfeedback;
00060 var $itemfeedback;
00061 var $flow_mat;
00062 var $flow;
00063 var $presentation;
00064 var $mattext;
00065 var $sametag;
00066 var $characterbuffer;
00067 var $conditionvar;
00068 var $parser_mode;
00069 var $import_idents;
00070 var $qpl_id;
00071 var $tst_id;
00072 var $tst_object;
00073 var $do_nothing;
00074 var $gap_index;
00075 var $assessments;
00076 var $assessment;
00077 var $assessmentcontrol;
00078 var $objectives;
00079 var $in_assessment = FALSE;
00080 var $section;
00081 var $import_mapping;
00082 var $question_counter = 1;
00083 var $in_itemmetadata;
00084 var $in_objectives = FALSE;
00085
00086 var $founditems = array();
00087 var $verifyroot = false;
00088 var $verifyqticomment = 0;
00089 var $verifymetadatafield = 0;
00090 var $verifyfieldlabel = 0;
00091 var $verifyfieldlabeltext = "";
00092 var $verifyfieldentry = 0;
00093 var $verifyfieldentrytext = "";
00094
00102
00103 function ilQTIParser($a_xml_file, $a_mode = IL_MO_PARSE_QTI, $a_qpl_id = 0, $a_import_idents = "")
00104 {
00105 global $lng;
00106
00107 $this->setParserMode($a_mode);
00108
00109 parent::ilSaxParser($a_xml_file);
00110
00111 $this->qpl_id = $a_qpl_id;
00112 $this->import_idents = array();
00113 if (is_array($a_import_idents))
00114 {
00115 $this->import_idents =& $a_import_idents;
00116 }
00117
00118 $this->lng =& $lng;
00119 $this->hasRootElement = FALSE;
00120 $this->import_mapping = array();
00121 $this->assessments = array();
00122 $this->assessment = NULL;
00123 $this->section = NULL;
00124 $this->path = array();
00125 $this->items = array();
00126 $this->item = NULL;
00127 $this->depth = array();
00128 $this->do_nothing = FALSE;
00129 $this->qti_element = "";
00130 $this->in_presentation = FALSE;
00131 $this->in_objectives = FALSE;
00132 $this->in_reponse = FALSE;
00133 $this->render_type = NULL;
00134 $this->render_hotspot = NULL;
00135 $this->response_label = NULL;
00136 $this->material = NULL;
00137 $this->response = NULL;
00138 $this->assessmentcontrol = NULL;
00139 $this->objectives = NULL;
00140 $this->matimage = NULL;
00141 $this->resprocessing = NULL;
00142 $this->outcomes = NULL;
00143 $this->decvar = NULL;
00144 $this->respcondition = NULL;
00145 $this->setvar = NULL;
00146 $this->displayfeedback = NULL;
00147 $this->itemfeedback = NULL;
00148 $this->flow_mat = array();
00149 $this->question_counter = 1;
00150 $this->flow = 0;
00151 $this->gap_index = 0;
00152 $this->presentation = NULL;
00153 $this->mattext = NULL;
00154 $this->matapplet = NULL;
00155 $this->sametag = FALSE;
00156 $this->in_assessment = FALSE;
00157 $this->characterbuffer = "";
00158 $this->metadata = array("label" => "", "entry" => "");
00159 }
00160
00161 function setTestObject(&$a_tst_object)
00162 {
00163 $this->tst_object =& $a_tst_object;
00164 if (is_object($a_tst_object))
00165 {
00166 $this->tst_id = $this->tst_object->getId();
00167 }
00168 }
00169
00170 function setParserMode($a_mode = IL_MO_PARSE_QTI)
00171 {
00172 $this->parser_mode = $a_mode;
00173 $this->founditems = array();
00174 $this->verifyroot = false;
00175 $this->verifyqticomment = 0;
00176 $this->verifymetadatafield = 0;
00177 $this->verifyfieldlabel = 0;
00178 $this->verifyfieldentry = 0;
00179 $this->verifyfieldlabeltext = "";
00180 $this->verifyfieldentrytext = "";
00181 $this->question_counter = 1;
00182 }
00183
00189 function setHandlers($a_xml_parser)
00190 {
00191 xml_set_object($a_xml_parser,$this);
00192 xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
00193 xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
00194 }
00195
00196 function startParsing()
00197 {
00198 $this->question_counter = 1;
00199 parent::startParsing();
00200 return FALSE;
00201 }
00202
00203 function getParent($a_xml_parser)
00204 {
00205 if ($this->depth[$a_xml_parser] > 0)
00206 {
00207 return $this->path[$this->depth[$a_xml_parser]-1];
00208 }
00209 else
00210 {
00211 return "";
00212 }
00213 }
00214
00218 function handlerBeginTag($a_xml_parser,$a_name,$a_attribs)
00219 {
00220 switch ($this->parser_mode)
00221 {
00222 case IL_MO_PARSE_QTI:
00223 $this->handlerParseBeginTag($a_xml_parser, $a_name, $a_attribs);
00224 break;
00225 case IL_MO_VERIFY_QTI:
00226 $this->handlerVerifyBeginTag($a_xml_parser, $a_name, $a_attribs);
00227 break;
00228 }
00229 }
00230
00234 function handlerParseBeginTag($a_xml_parser,$a_name,$a_attribs)
00235 {
00236 if ($this->do_nothing) return;
00237 $this->sametag = FALSE;
00238 $this->characterbuffer = "";
00239 $this->depth[$a_xml_parser]++;
00240 $this->path[$this->depth[$a_xml_parser]] = strtolower($a_name);
00241 $this->qti_element = $a_name;
00242
00243 switch (strtolower($a_name))
00244 {
00245 case "assessment":
00246 include_once ("./assessment/classes/QTI/class.ilQTIAssessment.php");
00247 $this->assessment =& $this->assessments[array_push($this->assessments, new ilQTIAssessment())-1];
00248 $this->in_assessment = TRUE;
00249 if (is_array($a_attribs))
00250 {
00251 foreach ($a_attribs as $attribute => $value)
00252 {
00253 switch (strtolower($attribute))
00254 {
00255 case "title":
00256 $this->assessment->setTitle($value);
00257 break;
00258 case "ident":
00259 $this->assessment->setIdent($value);
00260 break;
00261 }
00262 }
00263 }
00264 break;
00265 case "assessmentcontrol":
00266 include_once ("./assessment/classes/QTI/class.ilQTIAssessmentcontrol.php");
00267 $this->assessmentcontrol = new ilQTIAssessmentcontrol();
00268 if (is_array($a_attribs))
00269 {
00270 foreach ($a_attribs as $attribute => $value)
00271 {
00272 switch (strtolower($attribute))
00273 {
00274 case "solutionswitch":
00275 $this->assessmentcontrol->setSolutionswitch($value);
00276 break;
00277 case "hintswitch":
00278 $this->assessmentcontrol->setHintswitch($value);
00279 break;
00280 case "feedbackswitch":
00281 $this->assessmentcontrol->setFeedbackswitch($value);
00282 break;
00283 }
00284 }
00285 }
00286 break;
00287 case "objectives":
00288 include_once ("./assessment/classes/QTI/class.ilQTIObjectives.php");
00289 $this->objectives = new ilQTIObjectives();
00290 $this->in_objectives = TRUE;
00291 break;
00292 case "section":
00293 include_once ("./assessment/classes/QTI/class.ilQTISection.php");
00294 $this->section = new ilQTISection();
00295 break;
00296 case "itemmetadata":
00297 $this->in_itemmetadata = TRUE;
00298 break;
00299 case "qtimetadatafield":
00300 $this->metadata = array("label" => "", "entry" => "");
00301 break;
00302 case "flow":
00303 include_once ("./assessment/classes/QTI/class.ilQTIFlow.php");
00304 $this->flow++;
00305 break;
00306 case "flow_mat":
00307 include_once ("./assessment/classes/QTI/class.ilQTIFlowMat.php");
00308 array_push($this->flow_mat, new ilQTIFlowMat());
00309 break;
00310 case "itemfeedback":
00311 include_once ("./assessment/classes/QTI/class.ilQTIItemfeedback.php");
00312 $this->itemfeedback = new ilQTIItemfeedback();
00313 break;
00314 case "displayfeedback":
00315 include_once ("./assessment/classes/QTI/class.ilQTIDisplayfeedback.php");
00316 $this->displayfeedback = new ilQTIDisplayfeedback();
00317 break;
00318 case "setvar":
00319 include_once ("./assessment/classes/QTI/class.ilQTISetvar.php");
00320 $this->setvar = new ilQTISetvar();
00321 if (is_array($a_attribs))
00322 {
00323 foreach ($a_attribs as $attribute => $value)
00324 {
00325 switch (strtolower($attribute))
00326 {
00327 case "action":
00328 $this->setvar->setAction($value);
00329 break;
00330 case "varname":
00331 $this->setvar->setVarname($value);
00332 break;
00333 }
00334 }
00335 }
00336 break;
00337 case "conditionvar":
00338 include_once ("./assessment/classes/QTI/class.ilQTIConditionvar.php");
00339 $this->conditionvar = new ilQTIConditionvar();
00340 break;
00341 case "not":
00342 if ($this->conditionvar != NULL)
00343 {
00344 $this->conditionvar->addNot();
00345 }
00346 break;
00347 case "and":
00348 if ($this->conditionvar != NULL)
00349 {
00350 $this->conditionvar->addAnd();
00351 }
00352 break;
00353 case "or":
00354 if ($this->conditionvar != NULL)
00355 {
00356 $this->conditionvar->addOr();
00357 }
00358 break;
00359 case "varequal":
00360 include_once("./assessment/classes/QTI/class.ilQTIResponseVar.php");
00361 $this->responsevar = new ilQTIResponseVar(RESPONSEVAR_EQUAL);
00362 if (is_array($a_attribs))
00363 {
00364 foreach ($a_attribs as $attribute => $value)
00365 {
00366 switch (strtolower($attribute))
00367 {
00368 case "case":
00369 $this->responsevar->setCase($value);
00370 break;
00371 case "respident":
00372 $this->responsevar->setRespident($value);
00373 break;
00374 case "index":
00375 $this->responsevar->setIndex($value);
00376 break;
00377 }
00378 }
00379 }
00380 break;
00381 case "varlt":
00382 include_once("./assessment/classes/QTI/class.ilQTIResponseVar.php");
00383 $this->responsevar = new ilQTIResponseVar(RESPONSEVAR_LT);
00384 if (is_array($a_attribs))
00385 {
00386 foreach ($a_attribs as $attribute => $value)
00387 {
00388 switch (strtolower($attribute))
00389 {
00390 case "respident":
00391 $this->responsevar->setRespident($value);
00392 break;
00393 case "index":
00394 $this->responsevar->setIndex($value);
00395 break;
00396 }
00397 }
00398 }
00399 break;
00400 case "varlte":
00401 include_once("./assessment/classes/QTI/class.ilQTIResponseVar.php");
00402 $this->responsevar = new ilQTIResponseVar(RESPONSEVAR_LTE);
00403 if (is_array($a_attribs))
00404 {
00405 foreach ($a_attribs as $attribute => $value)
00406 {
00407 switch (strtolower($attribute))
00408 {
00409 case "respident":
00410 $this->responsevar->setRespident($value);
00411 break;
00412 case "index":
00413 $this->responsevar->setIndex($value);
00414 break;
00415 }
00416 }
00417 }
00418 break;
00419 case "vargt":
00420 include_once("./assessment/classes/QTI/class.ilQTIResponseVar.php");
00421 $this->responsevar = new ilQTIResponseVar(RESPONSEVAR_GT);
00422 if (is_array($a_attribs))
00423 {
00424 foreach ($a_attribs as $attribute => $value)
00425 {
00426 switch (strtolower($attribute))
00427 {
00428 case "respident":
00429 $this->responsevar->setRespident($value);
00430 break;
00431 case "index":
00432 $this->responsevar->setIndex($value);
00433 break;
00434 }
00435 }
00436 }
00437 break;
00438 case "vargte":
00439 include_once("./assessment/classes/QTI/class.ilQTIResponseVar.php");
00440 $this->responsevar = new ilQTIResponseVar(RESPONSEVAR_GTE);
00441 if (is_array($a_attribs))
00442 {
00443 foreach ($a_attribs as $attribute => $value)
00444 {
00445 switch (strtolower($attribute))
00446 {
00447 case "respident":
00448 $this->responsevar->setRespident($value);
00449 break;
00450 case "index":
00451 $this->responsevar->setIndex($value);
00452 break;
00453 }
00454 }
00455 }
00456 break;
00457 case "varsubset":
00458 include_once("./assessment/classes/QTI/class.ilQTIResponseVar.php");
00459 $this->responsevar = new ilQTIResponseVar(RESPONSEVAR_SUBSET);
00460 if (is_array($a_attribs))
00461 {
00462 foreach ($a_attribs as $attribute => $value)
00463 {
00464 switch (strtolower($attribute))
00465 {
00466 case "respident":
00467 $this->responsevar->setRespident($value);
00468 break;
00469 case "setmatch":
00470 $this->responsevar->setSetmatch($value);
00471 break;
00472 case "index":
00473 $this->responsevar->setIndex($value);
00474 break;
00475 }
00476 }
00477 }
00478 break;
00479 case "varinside":
00480 include_once("./assessment/classes/QTI/class.ilQTIResponseVar.php");
00481 $this->responsevar = new ilQTIResponseVar(RESPONSEVAR_INSIDE);
00482 if (is_array($a_attribs))
00483 {
00484 foreach ($a_attribs as $attribute => $value)
00485 {
00486 switch (strtolower($attribute))
00487 {
00488 case "respident":
00489 $this->responsevar->setRespident($value);
00490 break;
00491 case "areatype":
00492 $this->responsevar->setAreatype($value);
00493 break;
00494 case "index":
00495 $this->responsevar->setIndex($value);
00496 break;
00497 }
00498 }
00499 }
00500 break;
00501 case "varsubstring":
00502 include_once("./assessment/classes/QTI/class.ilQTIResponseVar.php");
00503 $this->responsevar = new ilQTIResponseVar(RESPONSEVAR_SUBSTRING);
00504 if (is_array($a_attribs))
00505 {
00506 foreach ($a_attribs as $attribute => $value)
00507 {
00508 switch (strtolower($attribute))
00509 {
00510 case "case":
00511 $this->responsevar->setCase($value);
00512 break;
00513 case "respident":
00514 $this->responsevar->setRespident($value);
00515 break;
00516 case "index":
00517 $this->responsevar->setIndex($value);
00518 break;
00519 }
00520 }
00521 }
00522 break;
00523 case "respcondition":
00524 include_once("./assessment/classes/QTI/class.ilQTIRespcondition.php");
00525 $this->respcondition = new ilQTIRespcondition();
00526 if (is_array($a_attribs))
00527 {
00528 foreach ($a_attribs as $attribute => $value)
00529 {
00530 switch (strtolower($attribute))
00531 {
00532 case "continue":
00533 $this->respcondition->setContinue($value);
00534 break;
00535 case "title":
00536 $this->respcondition->setTitle($value);
00537 break;
00538 }
00539 }
00540 }
00541 break;
00542 case "outcomes":
00543 include_once("./assessment/classes/QTI/class.ilQTIOutcomes.php");
00544 $this->outcomes = new ilQTIOutcomes();
00545 break;
00546 case "decvar":
00547 include_once("./assessment/classes/QTI/class.ilQTIDecvar.php");
00548 $this->decvar = new ilQTIDecvar();
00549 if (is_array($a_attribs))
00550 {
00551 foreach ($a_attribs as $attribute => $value)
00552 {
00553 switch (strtolower($attribute))
00554 {
00555 case "varname":
00556 $this->decvar->setVarname($value);
00557 break;
00558 case "vartype":
00559 $this->decvar->setVartype($value);
00560 break;
00561 case "defaultval":
00562 $this->decvar->setDefaultval($value);
00563 break;
00564 case "minvalue":
00565 $this->decvar->setMinvalue($value);
00566 break;
00567 case "maxvalue":
00568 $this->decvar->setMaxvalue($value);
00569 break;
00570 case "members":
00571 $this->decvar->setMembers($value);
00572 break;
00573 case "cutvalue":
00574 $this->decvar->setCutvalue($value);
00575 break;
00576 }
00577 }
00578 }
00579 break;
00580 case "matimage":
00581 include_once("./assessment/classes/QTI/class.ilQTIMatimage.php");
00582 $this->matimage = new ilQTIMatimage();
00583 if (is_array($a_attribs))
00584 {
00585 foreach ($a_attribs as $attribute => $value)
00586 {
00587 switch (strtolower($attribute))
00588 {
00589 case "imagtype":
00590 $this->matimage->setImagetype($value);
00591 break;
00592 case "label":
00593 $this->matimage->setLabel($value);
00594 break;
00595 case "height":
00596 $this->matimage->setHeight($value);
00597 break;
00598 case "width":
00599 $this->matimage->setWidth($value);
00600 break;
00601 case "uri":
00602 $this->matimage->setUri($value);
00603 break;
00604 case "embedded":
00605 $this->matimage->setEmbedded($value);
00606 break;
00607 case "x0":
00608 $this->matimage->setX0($value);
00609 break;
00610 case "y0":
00611 $this->matimage->setY0($value);
00612 break;
00613 case "entityref":
00614 $this->matimage->setEntityref($value);
00615 break;
00616 }
00617 }
00618 }
00619 break;
00620 case "material":
00621 include_once("./assessment/classes/QTI/class.ilQTIMaterial.php");
00622 $this->material = new ilQTIMaterial();
00623 $this->material->setFlow($this->flow);
00624 if (is_array($a_attribs))
00625 {
00626 foreach ($a_attribs as $attribute => $value)
00627 {
00628 switch (strtolower($attribute))
00629 {
00630 case "label":
00631 $this->material->setLabel($value);
00632 break;
00633 }
00634 }
00635 }
00636 break;
00637 case "mattext":
00638 include_once ("./assessment/classes/QTI/class.ilQTIMattext.php");
00639 $this->mattext = new ilQTIMattext();
00640 if (is_array($a_attribs))
00641 {
00642 foreach ($a_attribs as $attribute => $value)
00643 {
00644 switch (strtolower($attribute))
00645 {
00646 case "texttype":
00647 $this->mattext->setTexttype($value);
00648 break;
00649 case "label":
00650 $this->mattext->setLabel($value);
00651 break;
00652 case "charset":
00653 $this->mattext->setCharset($value);
00654 break;
00655 case "uri":
00656 $this->mattext->setUri($value);
00657 break;
00658 case "xml:space":
00659 $this->mattext->setXmlspace($value);
00660 break;
00661 case "xml:lang":
00662 $this->mattext->setXmllang($value);
00663 break;
00664 case "entityref":
00665 $this->mattext->setEntityref($value);
00666 break;
00667 case "height":
00668 $this->mattext->setHeight($value);
00669 break;
00670 case "width":
00671 $this->mattext->setWidth($value);
00672 break;
00673 case "x0":
00674 $this->mattext->setX0($value);
00675 break;
00676 case "y0":
00677 $this->mattext->setY0($value);
00678 break;
00679 }
00680 }
00681 }
00682 break;
00683 case "matapplet":
00684 include_once ("./assessment/classes/QTI/class.ilQTIMatapplet.php");
00685 $this->matapplet = New ilQTIMatapplet();
00686 if (is_array($a_attribs))
00687 {
00688 foreach ($a_attribs as $attribute => $value)
00689 {
00690 switch (strtolower($attribute))
00691 {
00692 case "label":
00693 $this->matapplet->setLabel($value);
00694 break;
00695 case "uri":
00696 $this->matapplet->setUri($value);
00697 break;
00698 case "y0":
00699 $this->matapplet->setY0($value);
00700 break;
00701 case "height":
00702 $this->matapplet->setHeight($value);
00703 break;
00704 case "width":
00705 $this->matapplet->setWidth($value);
00706 break;
00707 case "x0":
00708 $this->matapplet->setX0($value);
00709 break;
00710 case "embedded":
00711 $this->matapplet->setEmbedded($value);
00712 break;
00713 case "entityref":
00714 $this->matapplet->setEntityref($value);
00715 break;
00716 }
00717 }
00718 }
00719 break;
00720 case "questestinterop":
00721 $this->hasRootElement = TRUE;
00722 break;
00723 case "qticomment":
00724 break;
00725 case "objectbank":
00726
00727 break;
00728 case "section":
00729 if ($this->assessment != NULL)
00730 {
00731 $this->assessment->addSection($this->section);
00732 }
00733 $this->section = NULL;
00734 break;
00735 case "presentation":
00736 $this->in_presentation = TRUE;
00737 include_once ("./assessment/classes/QTI/class.ilQTIPresentation.php");
00738 $this->presentation = new ilQTIPresentation();
00739 break;
00740 case "response_label":
00741 if ($this->render_type != NULL)
00742 {
00743 include_once("./assessment/classes/QTI/class.ilQTIResponseLabel.php");
00744 $this->response_label = new ilQTIResponseLabel();
00745 foreach ($a_attribs as $attribute => $value)
00746 {
00747 switch (strtolower($attribute))
00748 {
00749 case "rshuffle":
00750 $this->response_label->setRshuffle($value);
00751 break;
00752 case "rarea":
00753 $this->response_label->setRarea($value);
00754 break;
00755 case "rrange":
00756 $this->response_label->setRrange($value);
00757 break;
00758 case "labelrefid":
00759 $this->response_label->setLabelrefid($value);
00760 break;
00761 case "ident":
00762 $this->response_label->setIdent($value);
00763 break;
00764 case "match_group":
00765 $this->response_label->setMatchGroup($value);
00766 break;
00767 case "match_max":
00768 $this->response_label->setMatchMax($value);
00769 break;
00770 }
00771 }
00772 }
00773 break;
00774 case "render_choice":
00775 if ($this->in_response)
00776 {
00777 include_once("./assessment/classes/QTI/class.ilQTIRenderChoice.php");
00778 $this->render_type = new ilQTIRenderChoice();
00779 foreach ($a_attribs as $attribute => $value)
00780 {
00781 switch (strtolower($attribute))
00782 {
00783 case "shuffle":
00784 $this->render_type->setShuffle($value);
00785 break;
00786 }
00787 }
00788 }
00789 break;
00790 case "render_hotspot":
00791 if ($this->in_response)
00792 {
00793 include_once("./assessment/classes/QTI/class.ilQTIRenderHotspot.php");
00794 $this->render_type = new ilQTIRenderHotspot();
00795 foreach ($a_attribs as $attribute => $value)
00796 {
00797 switch (strtolower($attribute))
00798 {
00799 case "showdraw":
00800 $this->render_type->setShuffle($value);
00801 break;
00802 case "minnumber":
00803 $this->render_type->setMinnumber($value);
00804 break;
00805 case "maxnumber":
00806 $this->render_type->setMaxnumber($value);
00807 break;
00808 }
00809 }
00810 }
00811 break;
00812 case "render_fib":
00813 if ($this->in_response)
00814 {
00815 include_once("./assessment/classes/QTI/class.ilQTIRenderFib.php");
00816 $this->render_type = new ilQTIRenderFib();
00817 foreach ($a_attribs as $attribute => $value)
00818 {
00819 switch (strtolower($attribute))
00820 {
00821 case "encoding":
00822 $this->render_type->setEncoding($value);
00823 break;
00824 case "fibtype":
00825 $this->render_type->setFibtype($value);
00826 break;
00827 case "rows":
00828 $this->render_type->setRows($value);
00829 break;
00830 case "maxchars":
00831 $this->render_type->setMaxchars($value);
00832 break;
00833 case "prompt":
00834 $this->render_type->setPrompt($value);
00835 break;
00836 case "columns":
00837 $this->render_type->setColumns($value);
00838 break;
00839 case "charset":
00840 $this->render_type->setCharset($value);
00841 break;
00842 case "maxnumber":
00843 $this->render_type->setMaxnumber($value);
00844 break;
00845 case "minnumber":
00846 $this->render_type->setMinnumber($value);
00847 break;
00848 }
00849 }
00850 }
00851 break;
00852 case "response_lid":
00853
00854
00855
00856
00857 case "response_xy":
00858
00859 case "response_str":
00860
00861 case "response_num":
00862 case "response_grp":
00863
00864
00865 include_once "./assessment/classes/QTI/class.ilQTIResponse.php";
00866 switch (strtolower($a_name))
00867 {
00868 case "response_lid":
00869 $response_type = RT_RESPONSE_LID;
00870 break;
00871 case "response_xy":
00872 $response_type = RT_RESPONSE_XY;
00873 break;
00874 case "response_str":
00875 $response_type = RT_RESPONSE_STR;
00876 break;
00877 case "response_num":
00878 $response_type = RT_RESPONSE_NUM;
00879 break;
00880 case "response_grp":
00881 $response_type = RT_RESPONSE_GRP;
00882 break;
00883 }
00884 $this->in_response = TRUE;
00885 $this->response = new ilQTIResponse($response_type);
00886 $this->response->setFlow($this->flow);
00887 if (is_array($a_attribs))
00888 {
00889 foreach ($a_attribs as $attribute => $value)
00890 {
00891 switch (strtolower($attribute))
00892 {
00893 case "ident":
00894 $this->response->setIdent($value);
00895 break;
00896 case "rtiming":
00897 $this->response->setRTiming($value);
00898 break;
00899 case "rcardinality":
00900 $this->response->setRCardinality($value);
00901 break;
00902 case "numtype":
00903 $this->response->setNumtype($value);
00904 break;
00905 }
00906 }
00907 }
00908 break;
00909 case "item":
00910 include_once("./assessment/classes/QTI/class.ilQTIItem.php");
00911 $this->gap_index = 0;
00912 $this->item =& $this->items[array_push($this->items, new ilQTIItem())-1];
00913 if (is_array($a_attribs))
00914 {
00915 foreach ($a_attribs as $attribute => $value)
00916 {
00917 switch (strtolower($attribute))
00918 {
00919 case "ident":
00920 $this->item->setIdent($value);
00921 if (count($this->import_idents) > 0)
00922 {
00923 if (!in_array($value, $this->import_idents))
00924 {
00925 $this->do_nothing = TRUE;
00926 }
00927 }
00928 break;
00929 case "title":
00930 $this->item->setTitle($value);
00931 break;
00932 }
00933 }
00934 }
00935 break;
00936 case "resprocessing":
00937 include_once("./assessment/classes/QTI/class.ilQTIResprocessing.php");
00938 $this->resprocessing = new ilQTIResprocessing();
00939 if (is_array($a_attribs))
00940 {
00941 foreach ($a_attribs as $attribute => $value)
00942 {
00943 switch (strtolower($attribute))
00944 {
00945 case "scoremodel":
00946 $this->resprocessing->setScoremodel($value);
00947 break;
00948 }
00949 }
00950 }
00951 break;
00952 }
00953 }
00954
00958 function handlerEndTag($a_xml_parser,$a_name)
00959 {
00960 switch ($this->parser_mode)
00961 {
00962 case IL_MO_PARSE_QTI:
00963 $this->handlerParseEndTag($a_xml_parser, $a_name);
00964 break;
00965 case IL_MO_VERIFY_QTI:
00966 $this->handlerVerifyEndTag($a_xml_parser, $a_name);
00967 break;
00968 }
00969 }
00970
00974 function handlerParseEndTag($a_xml_parser,$a_name)
00975 {
00976 if (($this->do_nothing) && (strcmp(strtolower($a_name), "item") != 0)) return;
00977 switch (strtolower($a_name))
00978 {
00979 case "assessment":
00980 if (is_object($this->tst_object))
00981 {
00982 $this->tst_object->fromXML($this->assessment);
00983 }
00984 $this->in_assessment = FALSE;
00985 break;
00986 case "assessmentcontrol":
00987 $this->assessment->addAssessmentcontrol($this->assessmentcontrol);
00988 $this->assessmentcontrol = NULL;
00989 break;
00990 case "objectives":
00991 if (strcmp(strtolower($this->getParent($a_xml_parser)), "assessment") == 0)
00992 {
00993 $this->assessment->addObjectives($this->objectives);
00994 }
00995 $this->in_objectives = FALSE;
00996 break;
00997 case "itemmetadata":
00998 $this->in_itemmetadata = FALSE;
00999 break;
01000 case "qtimetadatafield":
01001
01002 switch ($this->metadata["label"])
01003 {
01004 case "ILIAS_VERSION":
01005 break;
01006 case "QUESTIONTYPE":
01007 if ($this->item != NULL)
01008 {
01009 $this->item->setQuestiontype($this->metadata["entry"]);
01010 }
01011 break;
01012 case "AUTHOR":
01013 if ($this->item != NULL)
01014 {
01015 $this->item->setAuthor($this->metadata["entry"]);
01016 }
01017 default:
01018 if ($this->item != NULL)
01019 {
01020 $this->item->addMetadata($this->metadata);
01021 }
01022 break;
01023 }
01024 if ($this->in_assessment)
01025 {
01026 $this->assessment->addQtiMetadata($this->metadata);
01027 }
01028 $this->metadata = array("label" => "", "entry" => "");
01029 break;
01030 case "flow":
01031 $this->flow--;
01032 break;
01033 case "flow_mat":
01034 if (count($this->flow_mat))
01035 {
01036 $flow_mat = array_pop($this->flow_mat);
01037 if (count($this->flow_mat))
01038 {
01039 $this->flow_mat[count($this->flow_mat)-1]->addFlow_mat($flow_mat);
01040 }
01041 else if ($this->itemfeedback != NULL)
01042 {
01043 $this->itemfeedback->addFlow_mat($flow_mat);
01044 }
01045 else if ($this->response_label != NULL)
01046 {
01047 $this->response_label->addFlow_mat($flow_mat);
01048 }
01049 }
01050 break;
01051 case "itemfeedback":
01052 if ($this->item != NULL)
01053 {
01054 if ($this->itemfeedback != NULL)
01055 {
01056 $this->item->addItemfeedback($this->itemfeedback);
01057 }
01058 }
01059 $this->itemfeedback = NULL;
01060 break;
01061 case "displayfeedback":
01062 if ($this->respcondition != NULL)
01063 {
01064 if ($this->displayfeedback != NULL)
01065 {
01066 $this->respcondition->addDisplayfeedback($this->displayfeedback);
01067 }
01068 }
01069 $this->displayfeedback = NULL;
01070 break;
01071 case "setvar":
01072 if ($this->respcondition != NULL)
01073 {
01074 if ($this->setvar != NULL)
01075 {
01076 $this->respcondition->addSetvar($this->setvar);
01077 }
01078 }
01079 $this->setvar = NULL;
01080 break;
01081 case "conditionvar":
01082 if ($this->respcondition != NULL)
01083 {
01084 $this->respcondition->setConditionvar($this->conditionvar);
01085 }
01086 $this->conditionvar = NULL;
01087 break;
01088 case "varequal":
01089 case "varlt":
01090 case "varlte":
01091 case "vargt":
01092 case "vargte":
01093 case "varsubset":
01094 case "varinside":
01095 case "varsubstring":
01096 if ($this->conditionvar != NULL)
01097 {
01098 if ($this->responsevar != NULL)
01099 {
01100 $this->conditionvar->addResponseVar($this->responsevar);
01101 }
01102 }
01103 $this->responsevar = NULL;
01104 break;
01105 case "respcondition":
01106 if ($this->resprocessing != NULL)
01107 {
01108 $this->resprocessing->addRespcondition($this->respcondition);
01109 }
01110 $this->respcondition = NULL;
01111 break;
01112 case "outcomes":
01113 if ($this->resprocessing != NULL)
01114 {
01115 $this->resprocessing->setOutcomes($this->outcomes);
01116 }
01117 $this->outcomes = NULL;
01118 break;
01119 case "decvar":
01120 if ($this->outcomes != NULL)
01121 {
01122 $this->outcomes->addDecvar($this->decvar);
01123 }
01124 $this->decvar = NULL;
01125 break;
01126 case "presentation":
01127 $this->in_presentation = FALSE;
01128 if ($this->presentation != NULL)
01129 {
01130 if ($this->item != NULL)
01131 {
01132 $this->item->setPresentation($this->presentation);
01133 }
01134 }
01135 $this->presentation = NULL;
01136 break;
01137 case "response_label":
01138 if ($this->render_type != NULL)
01139 {
01140 $this->render_type->addResponseLabel($this->response_label);
01141 $this->response_label = NULL;
01142 }
01143 break;
01144 case "render_choice":
01145 case "render_hotspot":
01146 case "render_fib":
01147 if ($this->in_response)
01148 {
01149 if ($this->response != NULL)
01150 {
01151 if ($this->render_type != NULL)
01152 {
01153 $this->response->setRenderType($this->render_type);
01154 $this->render_type = NULL;
01155 }
01156 }
01157 }
01158 break;
01159 case "response_lid":
01160 case "response_xy":
01161 case "response_str":
01162 case "response_num":
01163 case "response_grp":
01164 $this->gap_index++;
01165 if ($this->presentation != NULL)
01166 {
01167 if ($this->response != NULL)
01168 {
01169 $this->presentation->addResponse($this->response);
01170 if ($this->item != NULL)
01171 {
01172 $this->item->addPresentationitem($this->response);
01173 }
01174 }
01175 }
01176 $this->response = NULL;
01177 $this->in_response = FALSE;
01178 break;
01179 case "item":
01180 if ($this->do_nothing)
01181 {
01182 $this->do_nothing = FALSE;
01183 return;
01184 }
01185 if (strlen($this->item->getQuestionType()))
01186 {
01187
01188 }
01189 else
01190 {
01191
01192 }
01193 global $ilDB;
01194 global $ilUser;
01195
01196
01197
01198
01199
01200
01201 $qt = $this->item->determineQuestionType();
01202 $presentation = $this->item->getPresentation();
01203 if (file_exists("./assessment/classes/class.$qt.php"))
01204 {
01205 include_once "./assessment/classes/class.$qt.php";
01206 $question = new $qt();
01207 $question->fromXML($this->item, $this->qpl_id, $this->tst_id, $this->tst_object, $this->question_counter, $this->import_mapping);
01208 }
01209 break;
01210 case "material":
01211 if ($this->material)
01212 {
01213 if (strcmp($this->material->getLabel(), "suggested_solution") == 0)
01214 {
01215 $mat = $this->material->getMaterial(0);
01216 $this->item->addSuggestedSolution($mat["material"], $this->gap_index);
01217 }
01218 if ($this->in_objectives)
01219 {
01220 $this->objectives->addMaterial($this->material);
01221 }
01222 else if (($this->render_type != NULL) && (strcmp(strtolower($this->getParent($a_xml_parser)), "render_hotspot") == 0))
01223 {
01224 $this->render_type->addMaterial($this->material);
01225 }
01226 else if (count($this->flow_mat) && (strcmp(strtolower($this->getParent($a_xml_parser)), "flow_mat") == 0))
01227 {
01228 $this->flow_mat[count($this->flow_mat)-1]->addMaterial($this->material);
01229 }
01230 else if ($this->itemfeedback != NULL)
01231 {
01232 $this->itemfeedback->addMaterial($this->material);
01233 }
01234 else if ($this->response_label != NULL)
01235 {
01236 $this->response_label->addMaterial($this->material);
01237 }
01238 else if ($this->response != NULL)
01239 {
01240 if ($this->response->hasRendering())
01241 {
01242 $this->response->setMaterial2($this->material);
01243 }
01244 else
01245 {
01246 $this->response->setMaterial1($this->material);
01247 }
01248 }
01249 elseif (($this->in_presentation) && (!$this->in_response))
01250 {
01251 if (!is_object($this->item->getQuestiontext()))
01252 {
01253 $this->item->setQuestiontext($this->material);
01254 }
01255 $this->presentation->addMaterial($this->material);
01256 }
01257 else if ($this->presentation != NULL)
01258 {
01259 $this->presentation->addMaterial($this->material);
01260 if ($this->item != NULL)
01261 {
01262 $this->item->addPresentationitem($this->material);
01263 }
01264 }
01265 }
01266 $this->material = NULL;
01267 break;
01268 case "matimage";
01269 if ($this->material != NULL)
01270 {
01271 if ($this->matimage != NULL)
01272 {
01273 $this->material->addMatimage($this->matimage);
01274 }
01275 }
01276 $this->matimage = NULL;
01277 break;
01278 case "resprocessing":
01279 if ($this->item != NULL)
01280 {
01281 $this->item->addResprocessing($this->resprocessing);
01282 }
01283 $this->resprocessing = NULL;
01284 break;
01285 case "mattext":
01286 if ($this->material != NULL)
01287 {
01288 $this->material->addMattext($this->mattext);
01289 }
01290 $this->mattext = NULL;
01291 break;
01292 case "matapplet":
01293 if ($this->material != NULL)
01294 {
01295 $this->material->addMatapplet($this->matapplet);
01296 }
01297 $this->matapplet = NULL;
01298 break;
01299 }
01300 $this->depth[$a_xml_parser]--;
01301 }
01302
01306 function handlerCharacterData($a_xml_parser,$a_data)
01307 {
01308 switch ($this->parser_mode)
01309 {
01310 case IL_MO_PARSE_QTI:
01311 $this->handlerParseCharacterData($a_xml_parser, $a_data);
01312 break;
01313 case IL_MO_VERIFY_QTI:
01314 $this->handlerVerifyCharacterData($a_xml_parser, $a_data);
01315 break;
01316 }
01317 }
01318
01322 function handlerParseCharacterData($a_xml_parser,$a_data)
01323 {
01324 if ($this->do_nothing) return;
01325 $this->characterbuffer .= $a_data;
01326 $a_data = $this->characterbuffer;
01327 switch ($this->qti_element)
01328 {
01329 case "fieldlabel":
01330 $this->metadata["label"] = $a_data;
01331 break;
01332 case "fieldentry":
01333 $this->metadata["entry"] = $a_data;
01334 break;
01335 case "response_label":
01336 if ($this->response_label != NULL)
01337 {
01338 $this->response_label->setContent($a_data);
01339 }
01340 break;
01341 case "setvar":
01342 if ($this->setvar != NULL)
01343 {
01344 $this->setvar->setContent($a_data);
01345 }
01346 break;
01347 case "displayfeedback":
01348 if ($this->displayfeedback != NULL)
01349 {
01350 $this->displayfeedback->setContent($a_data);
01351 }
01352 break;
01353 case "varequal":
01354 case "varlt":
01355 case "varlte":
01356 case "vargt":
01357 case "vargte":
01358 case "varsubset":
01359 case "varinside":
01360 case "varsubstring":
01361 if ($this->responsevar != NULL)
01362 {
01363 $this->responsevar->setContent($a_data);
01364 }
01365 break;
01366 case "decvar":
01367 if (strlen($a_data))
01368 {
01369 if ($this->decvar != NULL)
01370 {
01371 $this->decvar->setContent($a_data);
01372 }
01373 }
01374 break;
01375 case "mattext":
01376 if ($this->mattext != NULL)
01377 {
01378 $this->mattext->setContent($a_data);
01379 }
01380 break;
01381 case "matapplet":
01382 if ($this->matapplet != NULL)
01383 {
01384 $this->matapplet->setContent($a_data);
01385 }
01386 break;
01387 case "matimage":
01388 if ($this->matimage != NULL)
01389 {
01390 $this->matimage->setContent($a_data);
01391 }
01392 break;
01393 case "duration":
01394 switch ($this->getParent($a_xml_parser))
01395 {
01396 case "assessment":
01397
01398 break;
01399 case "section":
01400
01401 break;
01402 case "item":
01403 $this->item->setDuration($a_data);
01404 break;
01405 }
01406 break;
01407 case "qticomment":
01408 switch ($this->getParent($a_xml_parser))
01409 {
01410 case "item":
01411 $this->item->setComment($a_data);
01412 break;
01413 case "assessment":
01414 $this->assessment->setComment($a_data);
01415 break;
01416 default:
01417 break;
01418 }
01419 break;
01420 }
01421 $this->sametag = TRUE;
01422 }
01423
01427 function handlerVerifyBeginTag($a_xml_parser,$a_name,$a_attribs)
01428 {
01429 switch (strtolower($a_name))
01430 {
01431 case "questestinterop":
01432 $this->verifyroot = true;
01433 break;
01434 case "qtimetadatafield":
01435 $this->verifymetadatafield = 1;
01436 break;
01437 case "fieldlabel":
01438 $this->verifyfieldlabeltext = "";
01439 if ($this->verifymetadatafield == 1) $this->verifyfieldlabel = 1;
01440 break;
01441 case "fieldentry":
01442 $this->verifyfieldentrytext = "";
01443 if ($this->verifymetadatafield == 1) $this->verifyfieldentry = 1;
01444 break;
01445 case "item":
01446 $title = "";
01447 if (is_array($a_attribs))
01448 {
01449 foreach ($a_attribs as $attribute => $value)
01450 {
01451 switch (strtolower($attribute))
01452 {
01453 case "title":
01454 $title = $value;
01455 break;
01456 }
01457 }
01458 }
01459 array_push($this->founditems, array("title" => "$title", "type" => "", "ident" => $a_attribs["ident"]));
01460 break;
01461 case "response_lid":
01462 if (strlen($this->founditems[count($this->founditems)-1]["type"]) == 0)
01463 {
01464
01465 if (is_array($a_attribs))
01466 {
01467 foreach ($a_attribs as $attribute => $value)
01468 {
01469 switch (strtolower($attribute))
01470 {
01471 case "rcardinality":
01472 include_once "./assessment/classes/QTI/class.ilQTIItem.php";
01473 switch (strtolower($value))
01474 {
01475 case "single":
01476 $this->founditems[count($this->founditems)-1]["type"] = QT_MULTIPLE_CHOICE_SR;
01477 break;
01478 case "multiple":
01479 $this->founditems[count($this->founditems)-1]["type"] = QT_MULTIPLE_CHOICE_MR;
01480 break;
01481 case "ordered":
01482 $this->founditems[count($this->founditems)-1]["type"] = QT_ORDERING;
01483 break;
01484 }
01485 break;
01486 }
01487 }
01488 }
01489 }
01490 break;
01491 case "response_str":
01492 if (strlen($this->founditems[count($this->founditems)-1]["type"]) == 0)
01493 {
01494
01495 if (is_array($a_attribs))
01496 {
01497 foreach ($a_attribs as $attribute => $value)
01498 {
01499 switch (strtolower($attribute))
01500 {
01501 case "rcardinality":
01502 include_once "./assessment/classes/QTI/class.ilQTIItem.php";
01503 switch (strtolower($value))
01504 {
01505 case "single":
01506 $this->founditems[count($this->founditems)-1]["type"] = QT_CLOZE;
01507 break;
01508 case "ordered":
01509 $this->founditems[count($this->founditems)-1]["type"] = QT_TEXT;
01510 break;
01511 }
01512 break;
01513 }
01514 }
01515 }
01516 }
01517 break;
01518 case "response_xy":
01519 if (strlen($this->founditems[count($this->founditems)-1]["type"]) == 0)
01520 {
01521 $this->founditems[count($this->founditems)-1]["type"] = QT_IMAGEMAP;
01522 }
01523 break;
01524 case "response_num":
01525 if (strlen($this->founditems[count($this->founditems)-1]["type"]) == 0)
01526 {
01527 $this->founditems[count($this->founditems)-1]["type"] = QT_NUMERIC;
01528 }
01529 break;
01530 case "response_grp":
01531 if (strlen($this->founditems[count($this->founditems)-1]["type"]) == 0)
01532 {
01533 $this->founditems[count($this->founditems)-1]["type"] = QT_MATCHING;
01534 }
01535 break;
01536 case "qticomment":
01537
01538 $this->verifyqticomment = 1;
01539 break;
01540 case "presentation":
01541 if (is_array($a_attribs))
01542 {
01543 foreach ($a_attribs as $attribute => $value)
01544 {
01545 switch (strtolower($attribute))
01546 {
01547 case "label":
01548 $this->founditems[count($this->founditems)-1]["title"] = $value;
01549 break;
01550 }
01551 }
01552 }
01553 break;
01554 }
01555 }
01556
01560 function handlerVerifyEndTag($a_xml_parser,$a_name)
01561 {
01562 switch (strtolower($a_name))
01563 {
01564 case "qticomment":
01565
01566 $this->verifyqticomment = 0;
01567 break;
01568 case "qtimetadatafield":
01569 $this->verifymetadatafield = 0;
01570 if (strcmp($this->verifyfieldlabeltext, "QUESTIONTYPE") == 0)
01571 {
01572 $this->founditems[count($this->founditems)-1]["type"] = $this->verifyfieldentrytext;
01573 }
01574 break;
01575 case "fieldlabel":
01576 $this->verifyfieldlabel = 0;
01577 break;
01578 case "fieldentry":
01579 $this->verifyfieldentry = 0;
01580 break;
01581 }
01582 }
01583
01587 function handlerVerifyCharacterData($a_xml_parser,$a_data)
01588 {
01589 if ($this->verifyqticomment == 1)
01590 {
01591 if (preg_match("/Questiontype\=(.*)/", $a_data, $matches))
01592 {
01593 if (count($this->founditems))
01594 {
01595 $this->founditems[count($this->founditems)-1]["type"] = $matches[1];
01596 }
01597 }
01598 }
01599 else if ($this->verifyfieldlabel == 1)
01600 {
01601 $this->verifyfieldlabeltext = $a_data;
01602 }
01603 else if ($this->verifyfieldentry == 1)
01604 {
01605 $this->verifyfieldentrytext = $a_data;
01606 }
01607 }
01608
01609 function &getFoundItems()
01610 {
01611 return $this->founditems;
01612 }
01613
01618 function getImportMapping()
01619 {
01620 if (!is_array($this->import_mapping))
01621 {
01622 return array();
01623 }
01624 else
01625 {
01626 return $this->import_mapping;
01627 }
01628 }
01629
01630 }
01631 ?>