}\r
\r
function clean_temp_dir($dir='') {\r
- // this needs to be reworked\r
- \r
- \r
- // for now we will just say everything happened okay note that a mess may be piling up in $CFG->dataroot/temp/bbquiz_import\r
+ // for now we will just say everything happened okay note \r
+ // that a mess may be piling up in $CFG->dataroot/temp/bbquiz_import\r
return true;\r
\r
if ($dir == '') {\r
$xml = xmlize($text, 0);\r
\r
$raw_questions = $xml['questestinterop']['#']['assessment'][0]['#']['section'][0]['#']['item'];\r
- //echo "Line 213: Raw Questions <br>";\r
- //print_object($raw_questions);\r
$questions = array();\r
\r
foreach($raw_questions as $quest) {\r
$question = $this->create_raw_question($quest);\r
- \r
- switch($question->qtype) {\r
+\r
+ switch($question->qtype) {\r
case "Matching":\r
$this->process_matching($question, $questions);\r
break;\r
}\r
\r
}\r
- //echo "readquestions:";\r
- //print_object ($questions);\r
return $questions;\r
}\r
\r
// the object created is NOT a moodle question object\r
function create_raw_question($quest) {\r
\r
- $question = $this->defaultquestion();\r
+ $question = $this->defaultquestion();\r
$question->qtype = $quest['#']['itemmetadata'][0]['#']['bbmd_questiontype'][0]['#'];\r
$presentation->blocks = $quest['#']['presentation'][0]['#']['flow'][0]['#']['flow'];\r
- \r
- foreach($presentation->blocks as $pblock) {\r
+\r
+ foreach($presentation->blocks as $pblock) {\r
\r
$block = NULL;\r
$block->type = $pblock['@']['class'];\r
- \r
+\r
switch($block->type) {\r
case 'QUESTION_BLOCK':\r
$sub_blocks = $pblock['#']['flow'];\r
foreach($sub_blocks as $sblock) {\r
- //echo "Calling process_block from line 263<br>";\r
+ //echo "Calling process_block from line 263<br>";\r
$this->process_block($sblock, $block); \r
}\r
break;\r
- \r
+\r
case 'RESPONSE_BLOCK':\r
$choices = NULL;\r
switch($question->qtype) {\r
$bb_subquestions = $pblock['#']['flow'];\r
$sub_questions = array();\r
foreach($bb_subquestions as $bb_subquestion) {\r
- $sub_question = NULL;\r
+ $sub_question = NULL;\r
$sub_question->ident = $bb_subquestion['#']['response_lid'][0]['@']['ident'];\r
- //echo "Calling process_block from line 277<br>";\r
$this->process_block($bb_subquestion['#']['flow'][0], $sub_question);\r
$bb_choices = $bb_subquestion['#']['response_lid'][0]['#']['render_choice'][0]['#']['flow_label'][0]['#']['response_label'];\r
$choices = array();\r
$bb_choices = $pblock['#']['response_lid'][0]['#']['render_choice'][0]['#']['flow_label'];\r
$choices = array();\r
$this->process_choices($bb_choices, $choices);\r
- $block->choices = $choices;\r
- \r
- break;\r
+ $block->choices = $choices;\r
+ break;\r
case 'Essay':\r
// Doesn't apply since the user responds with text input\r
break;\r
case 'Multiple Choice':\r
$mc_choices = $pblock['#']['response_lid'][0]['#']['render_choice'][0]['#']['flow_label'];\r
- \r
- foreach($mc_choices as $mc_choice) {\r
+ foreach($mc_choices as $mc_choice) {\r
$choices = NULL;\r
- \r
- \r
- \r
- //echo "Calling process_block from line 307<br>";\r
- $choices = $this->process_block($mc_choice, $choices);\r
- $block->choices[] = $choices; \r
+ $choices = $this->process_block($mc_choice, $choices);\r
+ $block->choices[] = $choices; \r
}\r
break;\r
case 'Fill in the Blank':\r
$matching_answerset = $pblock['#']['flow'];\r
$answerset = array();\r
foreach($matching_answerset as $answer) {\r
- //echo "Calling process_block from line 235<br>";\r
$this->process_block($answer, $bb_answer);\r
$answerset[] = $bb_answer;\r
}\r
// determine response processing \r
// there is a section called 'outcomes' that I don't know what to do with\r
$resprocessing = $quest['#']['resprocessing'];\r
- \r
- $respconditions = $resprocessing[0]['#']['respcondition'];\r
- //echo "Line 347: respconditions<br>";\r
- //print_object ($respconditions);\r
- \r
- $reponses = array();\r
+ $respconditions = $resprocessing[0]['#']['respcondition'];\r
+ $reponses = array();\r
if ($question->qtype == 'Matching') {\r
$this->process_matching_responses($respconditions, $responses);\r
}\r
$this->process_responses($respconditions, $responses);\r
}\r
$question->responses = $responses;\r
- \r
$feedbackset = $quest['#']['itemfeedback'];\r
- \r
- $feedbacks = array();\r
- \r
- //echo "Line 362: Calling Process Feedback:<br>";\r
- $this->process_feedback($feedbackset, $feedbacks);\r
+ $feedbacks = array();\r
+ $this->process_feedback($feedbackset, $feedbacks);\r
$question->feedback = $feedbacks;\r
- \r
- //echo "Line 358: ";\r
- //print_object($question);\r
return $question;\r
}\r
\r
function process_block($cur_block, &$block) {\r
- \r
+ global $course, $CFG;\r
+\r
$cur_type = $cur_block['@']['class'];\r
- \r
- global $course, $CFG;\r
switch($cur_type) {\r
case 'FORMATTED_TEXT_BLOCK':\r
$block->text = $this->strip_applet_tags_get_mathml($cur_block['#']['material'][0]['#']['mat_extension'][0]['#']['mat_formattedtext'][0]['#']); \r
- //echo "Line 378: " . $block->text . '<br>';\r
- break;\r
+ break;\r
case 'FILE_BLOCK':\r
//revisit this to make sure it is working correctly\r
- \r
- // Commented out ['matapplication']..., etc. because I noticed that when I imported a new Blackboard 6 file\r
- // and printed out the block, the tree did not extend past ['material'][0]['#'] - CT 8/3/06\r
+ // Commented out ['matapplication']..., etc. because I \r
+ // noticed that when I imported a new Blackboard 6 file\r
+ // and printed out the block, the tree did not extend past ['material'][0]['#'] - CT 8/3/06\r
$block->file = $cur_block['#']['material'][0]['#'];//['matapplication'][0]['@']['uri'];\r
if ($block->file != '') {\r
// if we have a file copy it to the course dir and adjust its name to be visible over the web.\r
}\r
break;\r
case 'Block':\r
- \r
- if (isset($cur_block['#']['material'][0]['#']['mattext'][0]['#'])) {\r
- $block->text = $cur_block['#']['material'][0]['#']['mattext'][0]['#'];\r
- \r
- //echo "line 379 - isset:" . isset($block->text);\r
- //echo "Type: " . $cur_type . " Is Object:" . is_object($block) . "<br>\r\n";\r
+ if (isset($cur_block['#']['material'][0]['#']['mattext'][0]['#'])) {\r
+ $block->text = $cur_block['#']['material'][0]['#']['mattext'][0]['#'];\r
}\r
else if (isset($cur_block['#']['material'][0]['#']['mat_extension'][0]['#']['mat_formattedtext'][0]['#'])) {\r
$block->text = $cur_block['#']['material'][0]['#']['mat_extension'][0]['#']['mat_formattedtext'][0]['#'];\r
if(!isset($block->ident)) {\r
if(isset($sub_blocks['@']['ident'])) {\r
$block->ident = $sub_blocks['@']['ident'];\r
- //echo "Line 409: <br>";\r
- //print_object($cur_block);\r
}\r
}\r
foreach($sub_blocks['#']['flow_mat'] as $sub_block) {\r
- //echo "Calling process_block from line 404<br>";\r
- //$block = null; // Reset $block to NULL because process_block is expecting an object\r
- // for the second argument and not a string, which is what is was set as\r
- // originally\r
- \r
$this->process_block($sub_block, $block); \r
}\r
}\r
}\r
foreach ($sub_blocks as $sblock) {\r
// this will recursively grab the sub blocks which should be of one of the other types\r
- //echo "Calling process_block from line 419<br>";\r
$this->process_block($sblock, $block);\r
}\r
}\r
}\r
break; \r
} \r
- //echo "Line 446: " . $block->text . '<br>';\r
- return $block;\r
+ return $block;\r
}\r
\r
function process_choices($bb_choices, &$choices) {\r
- \r
- foreach($bb_choices as $choice) {\r
- if (isset($choice['@']['ident'])) {\r
+ foreach($bb_choices as $choice) {\r
+ if (isset($choice['@']['ident'])) {\r
$cur_choice = $choice['@']['ident'];\r
}\r
- else { //for multiple answer\r
+ else { //for multiple answer\r
$cur_choice = $choice['#']['response_label'][0];//['@']['ident'];\r
- //echo "['#']['response_label'][0]['@']['ident']<br>\r\n";\r
}\r
- if (isset($choice['#']['flow_mat'][0])) { //for multiple answer\r
+ if (isset($choice['#']['flow_mat'][0])) { //for multiple answer\r
$cur_block = $choice['#']['flow_mat'][0];\r
- $cur_choice = null; // Reset $cur_choice to NULL because process_block is expecting an object\r
- // for the second argument and not a string, which is what is was set as\r
- // originally - CT 8/7/06\r
- //echo "Calling process_block from line 448<br>";\r
- $this->process_block($cur_block, $cur_choice);\r
+ // Reset $cur_choice to NULL because process_block is expecting an object\r
+ // for the second argument and not a string, which is what is was set as\r
+ // originally - CT 8/7/06\r
+ $cur_choice = null; \r
+ $this->process_block($cur_block, $cur_choice);\r
}\r
elseif (isset($choice['#']['response_label'])) {\r
- $cur_choice = null; // Reset $cur_choice to NULL because process_block is expecting an object\r
- // for the second argument and not a string, which is what is was set as\r
- // originally - CT 8/7/06\r
- //echo "Calling process_block from line 452<br>";\r
+ // Reset $cur_choice to NULL because process_block is expecting an object\r
+ // for the second argument and not a string, which is what is was set as\r
+ // originally - CT 8/7/06\r
+ $cur_choice = null; \r
$this->process_block($choice, $cur_choice);\r
}\r
$choices[] = $cur_choice;\r
}\r
\r
function process_matching_responses($bb_responses, &$responses) {\r
- //echo "Line 486: Matching!<br>";\r
- //print_object($bb_responses);\r
foreach($bb_responses as $bb_response) {\r
$response = NULL;\r
if (isset($bb_response['#']['conditionvar'][0]['#']['varequal'])) {\r
}\r
\r
function process_responses($bb_responses, &$responses) {\r
- \r
- foreach($bb_responses as $bb_response) {\r
- $response = null; //Added this line to instantiate $response.\r
- // Without instantiating the $response variable, the same object\r
- // gets added to the array\r
- //echo "Line 504: bb_response<br>";\r
- //print_object ($bb_response);\r
- \r
- if (isset($bb_response['@']['title'])) {\r
+ foreach($bb_responses as $bb_response) {\r
+ //Added this line to instantiate $response.\r
+ // Without instantiating the $response variable, the same object\r
+ // gets added to the array\r
+ $response = null;\r
+ if (isset($bb_response['@']['title'])) {\r
$response->title = $bb_response['@']['title']; \r
}\r
else {\r
$response->fraction = 1;\r
break;\r
default:\r
- // I have only seen this being 0 or unset there are probably fractional values of SCORE.max, but I'm not sure what they look like\r
+ // I have only seen this being 0 or unset \r
+ // there are probably fractional values of SCORE.max, but I'm not sure what they look like\r
$response->fraction = 0;\r
break;\r
}\r
$response->fraction = 0;\r
}\r
\r
- \r
- \r
$responses[] = $response;\r
- //echo "Line 554: $responses<br>";\r
- //print_object ($responses);\r
}\r
}\r
\r
function process_feedback($feedbackset, &$feedbacks) {\r
- //echo "Line 551: In Process Feedback<br>";\r
- //echo "Line 552: feedbacks<br>";\r
- //print_object($feedbacks);\r
foreach($feedbackset as $bb_feedback) {\r
- $feedback = null; // Added line $feedback=null so that $feedback does not get reused in the loop\r
- // and added the the $feedbacks[] array multiple times\r
- $feedback->ident = $bb_feedback['@']['ident'];\r
- //echo "Line 558: " . $feedback->ident . "<br>\r\n";\r
+ // Added line $feedback=null so that $feedback does not get reused in the loop\r
+ // and added the the $feedbacks[] array multiple times\r
+ $feedback = null; \r
+ $feedback->ident = $bb_feedback['@']['ident'];\r
if (isset($bb_feedback['#']['flow_mat'][0])) {\r
- //echo "Calling process_block from line 531<br>";\r
$this->process_block($bb_feedback['#']['flow_mat'][0], $feedback);\r
- \r
}\r
elseif (isset($bb_feedback['#']['solution'][0]['#']['solutionmaterial'][0]['#']['flow_mat'][0])) {\r
- //echo "Calling process_block from line 535<br>";\r
$this->process_block($bb_feedback['#']['solution'][0]['#']['solutionmaterial'][0]['#']['flow_mat'][0], $feedback);\r
}\r
$feedbacks[] = $feedback;\r
- \r
- //echo "Line 568: feedbacks<br>";\r
- //print_object($feedbacks);\r
}\r
- //echo "Line 571: feedbacks<br>";\r
- //print_object($feedbacks);\r
- \r
}\r
\r
//----------------------------------------\r
\r
$question->qtype = TRUEFALSE;\r
$question->defaultgrade = 1;\r
- $question->single = 1; // Only one answer is allowed\r
- $question->image = ""; // No images with this format\r
- $question->questiontext = addslashes($quest->QUESTION_BLOCK->text);\r
+ $question->single = 1; // Only one answer is allowed\r
+ $question->image = ""; // No images with this format\r
+ $question->questiontext = addslashes($quest->QUESTION_BLOCK->text);\r
// put name in question object\r
$question->name = $question->questiontext;\r
\r
// Process Fill in the Blank\r
//----------------------------------------\r
function process_fblank($quest, &$questions) {\r
- \r
- //echo "Line 633: Quest<br>";\r
- //print_object($quest);\r
- \r
- $question = $this->defaultquestion();\r
+ $question = $this->defaultquestion();\r
$question->qtype = SHORTANSWER;\r
$question->defaultgrade = 1;\r
$question->single = 1;\r
$feedback = array();\r
foreach($quest->feedback as $fback) {\r
if (isset($fback->ident)) {\r
- if ($fback->ident == 'correct' || $fback->ident == 'incorrect')\r
- {\r
- $feedback[$fback->ident] = $fback->text;\r
- }\r
+ if ($fback->ident == 'correct' || $fback->ident == 'incorrect') {\r
+ $feedback[$fback->ident] = $fback->text;\r
+ }\r
}\r
}\r
\r
foreach($quest->responses as $response) {\r
if(isset($response->title)) {\r
- \r
- if (isset($response->ident[0]['varequal'][0]['#']))\r
- {\r
- //for BB Fill in the Blank, only interested in correct answers\r
- if ($response->feedback = 'correct')\r
- {\r
- $answers[] = addslashes($response->ident[0]['varequal'][0]['#']);\r
- $fractions[] = 1;\r
- if (isset($feedback['correct'])) \r
- {\r
- $feedbacks[] = addslashes($feedback['correct']);\r
- }\r
- else\r
- {\r
- $feedbacks[] = '';\r
- }\r
- }\r
- }\r
+ if (isset($response->ident[0]['varequal'][0]['#'])) {\r
+ //for BB Fill in the Blank, only interested in correct answers\r
+ if ($response->feedback = 'correct') {\r
+ $answers[] = addslashes($response->ident[0]['varequal'][0]['#']);\r
+ $fractions[] = 1;\r
+ if (isset($feedback['correct'])) {\r
+ $feedbacks[] = addslashes($feedback['correct']);\r
+ }\r
+ else {\r
+ $feedbacks[] = '';\r
+ }\r
+ }\r
+ }\r
\r
}\r
}\r
- \r
- //Adding catchall to so that students can see feedback for incorrect answers when they enter something the \r
- //instructor did not enter\r
- \r
- $answers[] = '*';\r
- $fractions[] = 0;\r
- if (isset($feedback['incorrect'])) \r
- {\r
- $feedbacks[] = addslashes($feedback['incorrect']);\r
- }\r
- else\r
- {\r
- $feedbacks[] = '';\r
- }\r
+\r
+ //Adding catchall to so that students can see feedback for incorrect answers when they enter something the \r
+ //instructor did not enter\r
+ $answers[] = '*';\r
+ $fractions[] = 0;\r
+ if (isset($feedback['incorrect'])) {\r
+ $feedbacks[] = addslashes($feedback['incorrect']);\r
+ }\r
+ else {\r
+ $feedbacks[] = '';\r
+ }\r
\r
$question->answer = $answers;\r
$question->fraction = $fractions;\r
- $question->feedback = $feedbacks; // Changed to assign $feedbacks to $question->feedback instead of\r
- // $feedback - CT 8/10/06\r
-// $question->feedback = $feedback;\r
+ $question->feedback = $feedbacks; // Changed to assign $feedbacks to $question->feedback instead of\r
\r
if (!empty($question)) {\r
$questions[] = $question;\r
// Process Multiple Choice Questions\r
//----------------------------------------\r
function process_mc($quest, &$questions) {\r
- //echo "Line 667: Quest<br>";\r
- //print_object($quest);\r
- \r
- $question = $this->defaultquestion();\r
+ $question = $this->defaultquestion();\r
$question->qtype = MULTICHOICE;\r
$question->defaultgrade = 1;\r
$question->single = 1;\r
foreach($quest->feedback as $fback) {\r
$feedback[$fback->ident] = addslashes($fback->text);\r
}\r
- \r
- //echo "Line 683: feedback<br>";\r
- //print_object($feedback);\r
\r
foreach($quest->responses as $response) {\r
- \r
if (isset($response->title)) {\r
if ($response->title == 'correct') {\r
// only one answer possible for this qtype so first index is correct answer\r
- $correct = $response->ident[0]['varequal'][0]['#']; // added [0]['varequal'][0]['#'] to $response->ident - CT 8/9/06\r
+ $correct = $response->ident[0]['varequal'][0]['#'];\r
}\r
}\r
else {\r
}\r
}\r
}\r
- \r
- //echo "Line 706: Correct:" . $correct . "<br>";\r
\r
$i = 0;\r
foreach($quest->RESPONSE_BLOCK->choices as $response) {\r
- \r
- $question->answer[$i] = addslashes($response->text);\r
+ $question->answer[$i] = addslashes($response->text);\r
if ($correct == $response->ident) {\r
$question->fraction[$i] = 1;\r
// this is a bit of a hack to catch the feedback... first we see if a 'correct' feedback exists\r
// Process Multiple Choice Questions With Multiple Answers\r
//----------------------------------------\r
function process_ma($quest, &$questions) {\r
-\r
- //echo "Line 763: Quest<br>";\r
- //print_object($quest);\r
- \r
- $question = $this->defaultquestion(); // copied this from process_mc\r
- // noticed it was missing - CT 8/8/06\r
+ $question = $this->defaultquestion(); // copied this from process_mc\r
$question->questiontext = addslashes($quest->QUESTION_BLOCK->text);\r
$question->name = $question->questiontext; \r
$question->qtype = MULTICHOICE;\r
$question->defaultgrade = 1;\r
- $question->single = 0; // More than one answer allowed\r
- $question->image = ""; // No images with this format\r
+ $question->single = 0; // More than one answer allowed\r
+ $question->image = ""; // No images with this format\r
\r
$answers = $quest->responses;\r
$correct_answers = array();\r
foreach($answers as $answer) {\r
- \r
- //echo 'Line 779: $answer<br>';\r
- //print_object($answer);\r
if($answer->title == 'correct') {\r
- $answerset = $answer->ident[0]['and'][0]['#']['varequal']; // added [0]['and'][0]['#']['varequal'] to $answer->ident - CT 8/9/06\r
+ $answerset = $answer->ident[0]['and'][0]['#']['varequal'];\r
foreach($answerset as $ans) {\r
- $correct_answers[] = $ans['#']; // added ['#'] to $ans - CT 8/9/06\r
+ $correct_answers[] = $ans['#'];\r
}\r
}\r
}\r
}\r
\r
$questions[] = $question;\r
- //echo "Line 807: question<br>";\r
- //print_object($question);\r
}\r
\r
//----------------------------------------\r
function process_essay($quest, &$questions) {\r
// this should be rewritten to accomodate moodle 1.6 essay question type eventually\r
\r
- //echo "Line 822: Quest<br>";\r
- //print_object($quest);\r
- \r
if (defined("ESSAY")) {\r
// treat as short answer\r
- \r
- $question = $this->defaultquestion(); // copied this from process_mc\r
- // noticed it was missing - CT 8/8/06\r
+ $question = $this->defaultquestion(); // copied this from process_mc\r
$question->qtype = ESSAY;\r
$question->defaultgrade = 1;\r
- $question->usecase = 0; // Ignore case\r
- $question->image = ""; // No images with this format\r
+ $question->usecase = 0; // Ignore case\r
+ $question->image = ""; // No images with this format\r
$question->questiontext = addslashes(trim($quest->QUESTION_BLOCK->text));\r
$question->name = $question->questiontext;\r
\r
$question->feedback = array();\r
// not sure where to get the correct answer from\r
foreach($quest->feedback as $feedback) {\r
- \r
- // Added this code to put the possible solution that the instructor gives as the Moodle answer for an essay question\r
- // - CT 8/9/06\r
- if ($feedback->ident == 'solution') \r
- { \r
- $question->feedback = $feedback->text;\r
- }\r
- \r
- \r
- }\r
- \r
- $question->fraction[] = 1; //Added because essay/questiontype.php:save_question_option is expecting a \r
- //fraction property - CT 8/10/06\r
+ // Added this code to put the possible solution that the\r
+ // instructor gives as the Moodle answer for an essay question\r
+ if ($feedback->ident == 'solution') {\r
+ $question->feedback = $feedback->text;\r
+ }\r
+ }\r
+ //Added because essay/questiontype.php:save_question_option is expecting a \r
+ //fraction property - CT 8/10/06\r
+ $question->fraction[] = 1; \r
if (!empty($question)) {\r
$questions[]=$question;\r
}\r
- \r
- \r
}\r
else {\r
print "Essay question types are not handled because the quiz question type 'Essay' does not exist in this installation of Moodle<br/>";\r
// Process Matching Questions\r
//----------------------------------------\r
function process_matching($quest, &$questions) {\r
-\r
- //echo "Line 910: Quest<br>";\r
- //print_object($quest);\r
- \r
if (defined("RENDEREDMATCH")) {\r
$question = $this->defaultquestion($this->defaultquestion());\r
$question->valid = true;\r