📄 exercise_import.inc.php
字号:
} else { array_push ($backlog_message, get_lang('ERROR in:<b>'.$questionFile.'</b> Question format unknown') ); }}/** * Function used by the SAX xml parser when the parser meets a opening tag * * @param unknown_type $parser xml parser created with "xml_parser_create()" * @param unknown_type $name name of the element * @param unknown_type $attributes */function startElement($parser, $name, $attributes){ global $element_pile; global $exercise_info; global $current_question_ident; global $current_answer_id; global $current_match_set; global $currentAssociableChoice; global $current_question_item_body; global $record_item_body; global $non_HTML_tag_to_avoid; global $current_inlinechoice_id; global $cardinality; global $questionTempDir; array_push($element_pile,$name); $current_element = end($element_pile); if (sizeof($element_pile)>=2) $parent_element = $element_pile[sizeof($element_pile)-2]; else $parent_element = ""; if (sizeof($element_pile)>=3) $grant_parent_element = $element_pile[sizeof($element_pile)-3]; else $grant_parent_element =""; if ($record_item_body) { if ((!in_array($current_element,$non_HTML_tag_to_avoid))) { $current_question_item_body .= "<".$name; foreach ($attributes as $attribute_name => $attribute_value) { $current_question_item_body .= " ".$attribute_name."=\"".$attribute_value."\""; } $current_question_item_body .= ">"; } else { //in case of FIB question, we replace the IMS-QTI tag b y the correct answer between "[" "]", //we first save with claroline tags ,then when the answer will be parsed, the claroline tags will be replaced if ($current_element=='INLINECHOICEINTERACTION') { $current_question_item_body .="**claroline_start**".$attributes['RESPONSEIDENTIFIER']."**claroline_end**"; } if ($current_element=='TEXTENTRYINTERACTION') { $correct_answer_value = $exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id]; $current_question_item_body .= "[".$correct_answer_value."]"; } if ($current_element=='BR') { $current_question_item_body .= "<BR/>"; } } } switch ($current_element) { case 'ASSESSMENTITEM' : { //retrieve current question $current_question_ident = $attributes['IDENTIFIER']; $exercise_info['question'][$current_question_ident] = array(); $exercise_info['question'][$current_question_ident]['answer'] = array(); $exercise_info['question'][$current_question_ident]['correct_answers'] = array(); $exercise_info['question'][$current_question_ident]['title'] = $attributes['TITLE']; $exercise_info['question'][$current_question_ident]['tempdir'] = $questionTempDir; } break; case 'SECTION' : { //retrieve exercise name $exercise_info['name'] = $attributes['TITLE']; } break; case 'RESPONSEDECLARATION' : { //retrieve question type if ( "multiple" == $attributes['CARDINALITY']) { $exercise_info['question'][$current_question_ident]['type'] = 'MCMA'; $cardinality = 'multiple'; } if ( "single" == $attributes['CARDINALITY']) { $exercise_info['question'][$current_question_ident]['type'] = 'MCUA'; $cardinality = 'single'; } //needed for FIB $current_answer_id = $attributes['IDENTIFIER']; } break; case 'INLINECHOICEINTERACTION' : { $exercise_info['question'][$current_question_ident]['type'] = 'FIB'; $exercise_info['question'][$current_question_ident]['subtype'] = 'LISTBOX_FILL'; $current_answer_id = $attributes['RESPONSEIDENTIFIER']; } break; case 'INLINECHOICE' : { $current_inlinechoice_id = $attributes['IDENTIFIER']; } break; case 'TEXTENTRYINTERACTION' : { $exercise_info['question'][$current_question_ident]['type'] = 'FIB'; $exercise_info['question'][$current_question_ident]['subtype'] = 'TEXTFIELD_FILL'; $exercise_info['question'][$current_question_ident]['response_text'] = $current_question_item_body; //replace claroline tags } break; case 'MATCHINTERACTION' : { $exercise_info['question'][$current_question_ident]['type'] = 'MATCHING'; } break; case 'SIMPLEMATCHSET' : { if (!isset($current_match_set)) { $current_match_set = 1; } else { $current_match_set++; } $exercise_info['question'][$current_question_ident]['answer'][$current_match_set] = array(); } break; case 'SIMPLEASSOCIABLECHOICE' : { $currentAssociableChoice = $attributes['IDENTIFIER']; } break; //retrieve answers id for MCUA and MCMA questions case 'SIMPLECHOICE': { $current_answer_id = $attributes['IDENTIFIER']; if (!isset($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id])) { $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id] = array(); } } break; case 'MAPENTRY': { if ($parent_element == "MAPPING") { $answer_id = $attributes['MAPKEY']; if (!isset($exercise_info['question'][$current_question_ident]['weighting'])) { $exercise_info['question'][$current_question_ident]['weighting'] = array(); } $exercise_info['question'][$current_question_ident]['weighting'][$answer_id] = $attributes['MAPPEDVALUE']; } } break; case 'MAPPING': { if (isset($attributes['DEFAULTVALUE'])) { $exercise_info['question'][$current_question_ident]['default_weighting'] = $attributes['DEFAULTVALUE']; } } case 'ITEMBODY': { $record_item_body = true; $current_question_item_body = ''; } break; case 'IMG' : { $exercise_info['question'][$current_question_ident]['attached_file_url'] = $attributes['SRC']; } break; }}/** * Function used by the SAX xml parser when the parser meets a closing tag * * @param $parser xml parser created with "xml_parser_create()" * @param $name name of the element */function endElement($parser,$name){ global $element_pile; global $exercise_info; global $current_question_ident; global $record_item_body; global $current_question_item_body; global $non_HTML_tag_to_avoid; global $cardinality; $current_element = end($element_pile); //treat the record of the full content of itembody tag : if ($record_item_body && (!in_array($current_element,$non_HTML_tag_to_avoid))) { $current_question_item_body .= "</".$name.">"; } switch ($name) { case 'ITEMBODY': { $record_item_body = false; if ($exercise_info['question'][$current_question_ident]['type']=='FIB') { $exercise_info['question'][$current_question_ident]['response_text'] = $current_question_item_body; } else { $exercise_info['question'][$current_question_ident]['statement'] = $current_question_item_body; } } break; } array_pop($element_pile);}function elementData($parser,$data){ global $element_pile; global $exercise_info; global $current_question_ident; global $current_answer_id; global $current_match_set; global $currentAssociableChoice; global $current_question_item_body; global $record_item_body; global $non_HTML_tag_to_avoid; global $current_inlinechoice_id; global $cardinality; $current_element = end($element_pile); if (sizeof($element_pile)>=2) $parent_element = $element_pile[sizeof($element_pile)-2]; else $parent_element = ""; if (sizeof($element_pile)>=3) $grant_parent_element = $element_pile[sizeof($element_pile)-3]; else $grant_parent_element = ""; //treat the record of the full content of itembody tag (needed for question statment and/or FIB text: if ($record_item_body && (!in_array($current_element,$non_HTML_tag_to_avoid))) { $current_question_item_body .= $data; } switch ($current_element) { case 'SIMPLECHOICE': { if (!isset($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'])) { $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'] = trim($data); } else { $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['value'] .= ' '.trim($data); } } break; case 'FEEDBACKINLINE' : { if (!isset($exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['feedback'])) { $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['feedback'] = trim($data); } else { $exercise_info['question'][$current_question_ident]['answer'][$current_answer_id]['feedback'] .= ' '.trim($data); } } break; case 'SIMPLEASSOCIABLECHOICE' : { $exercise_info['question'][$current_question_ident]['answer'][$current_match_set][$currentAssociableChoice] = trim($data); } break; case 'VALUE': { if ($parent_element=="CORRECTRESPONSE") { if ($cardinality=="single") { $exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id] = $data; } else { $exercise_info['question'][$current_question_ident]['correct_answers'][] = $data; } } } break; case 'ITEMBODY' : { $current_question_item_body .= $data; } break; case 'INLINECHOICE' : { // if this is the right answer, then we must replace the claroline tags in the FIB text bye the answer between "[" and "]" : $answer_identifier = $exercise_info['question'][$current_question_ident]['correct_answers'][$current_answer_id]; if ($current_inlinechoice_id == $answer_identifier) { $current_question_item_body = str_replace("**claroline_start**".$current_answer_id."**claroline_end**", "[".$data."]", $current_question_item_body); } else // save wrong answers in an array { if(!isset($exercise_info['question'][$current_question_ident]['wrong_answers'])) { $exercise_info['question'][$current_question_ident]['wrong_answers'] = array(); } $exercise_info['question'][$current_question_ident]['wrong_answers'][] = $data; } } break; }}?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -