Skip to content

Commit

Permalink
Merge branch 'MDL-27973' of git://github.com/timhunt/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Jun 22, 2011
2 parents 4d05c97 + ef01d2c commit e059fa9
Showing 1 changed file with 42 additions and 48 deletions.
90 changes: 42 additions & 48 deletions question/format/qti_two/format.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,13 @@ public function exportprocess() {
// get the questions (from database) in this category
$questions = get_questions_category( $this->category );

echo $OUTPUT->notification("Exporting ".count($questions)." questions.");
$count = 0;

// create the imsmanifest file
$smarty =& $this->init_smarty();
$this->add_qti_info($questions);
// copy files used by the main questions to the export directory
$result = $this->handle_questions_media($questions, $path, $courseid);
if ($result !== true) {
echo $OUTPUT->notification(implode("<br />", $result));
throw new coding_exception(implode("<br />", $result));
}

$manifestquestions = $this->objects_to_array($questions);
Expand Down Expand Up @@ -311,8 +308,6 @@ public function exportprocess() {
foreach($questions as $question) {

// results are first written into string (and then to a file)
$count++;
echo "<hr /><p><b>$count</b>. ".$question->questiontext."</p>";
$expout = $this->writequestion( $question , null, true, $path) . "\n";
$expout = $this->presave_process( $expout );

Expand Down Expand Up @@ -380,14 +375,16 @@ function exportprocess_quiz($quiz, $questions, $result, $submiturl, $course) {
global $USER;
global $CFG;

$gradingmethod = array (1 => 'GRADEHIGHEST',
2 => 'GRADEAVERAGE',
3 => 'ATTEMPTFIRST' ,
4 => 'ATTEMPTLAST');
$gradingmethod = array(
1 => 'GRADEHIGHEST',
2 => 'GRADEAVERAGE',
3 => 'ATTEMPTFIRST',
4 => 'ATTEMPTLAST'
);

$questions = $this->quiz_export_prepare_questions($questions, $quiz->id, $course->id, $quiz->shuffleanswers);

$smarty =& $this->init_smarty();
$smarty = $this->init_smarty();
$smarty->assign('questions', $questions);

// quiz level smarty variables
Expand All @@ -409,22 +406,19 @@ function exportprocess_quiz($quiz, $questions, $result, $submiturl, $course) {
return true;
}




/**
* Prepares questions for quiz export
*
* The questions are changed as follows:
* - the question answers atached to the questions
* - image set to an http reference instead of a file path
* - qti specific info added
* - exporttext added, which contains an xml-formatted qti assesmentItem
*
* @param array $questions - an array of question objects
* @param int $quizid
* @return an array of question arrays
*/
/**
* Prepares questions for quiz export
*
* The questions are changed as follows:
* - the question answers atached to the questions
* - image set to an http reference instead of a file path
* - qti specific info added
* - exporttext added, which contains an xml-formatted qti assesmentItem
*
* @param array $questions - an array of question objects
* @param int $quizid
* @return an array of question arrays
*/
function quiz_export_prepare_questions($questions, $quizid, $courseid, $shuffleanswers = null) {
global $CFG;
// add the answers to the questions and format the image property
Expand Down Expand Up @@ -510,16 +504,16 @@ function questions_with_export_info($questions, $shuffleanswers = null) {
return $exportquestions;
}

/**
* Creates the export text for a question
*
* @todo handle in-line media (specified in the question/subquestion/answer text) for course-level exports
* @param object $question
* @param bool $shuffleanswers whether or not to shuffle the answers
* @param bool $courselevel whether or not this is a course-level export
* @param string $path provide the path to copy question media files to, if $courselevel == true
* @return string containing export text
*/
/**
* Creates the export text for a question
*
* @todo handle in-line media (specified in the question/subquestion/answer text) for course-level exports
* @param object $question
* @param bool $shuffleanswers whether or not to shuffle the answers
* @param bool $courselevel whether or not this is a course-level export
* @param string $path provide the path to copy question media files to, if $courselevel == true
* @return string containing export text
*/
function writequestion($question, $shuffleanswers = null, $courselevel = false, $path = '') {
// turns question into string
// question reflects database fields for general question and specific to type
Expand Down Expand Up @@ -560,31 +554,31 @@ function writequestion($question, $shuffleanswers = null, $courselevel = false,
switch($question->qtype) {
case TRUEFALSE:
$qanswers = $question->options->answers;
$answers[0] = (array)$qanswers['true'];
$answers[0] = (array)$qanswers[$question->options->trueanswer];
$answers[0]['answer'] = get_string('true', 'qtype_truefalse');
$answers[1] = (array)$qanswers['false'];
$answers[1] = (array)$qanswers[$question->options->falseanswer];
$answers[1]['answer'] = get_string('false', 'qtype_truefalse');

if (!empty($shuffleanswers)) {
$answers = $this->shuffle_things($answers);
}

if (isset($question->response)) {
$correctresponseid = $question->response[$questionid];
if ($answers[0]['id'] == $correctresponseid) {
$correctresponse = $answers[0];
} else {
$correctresponse = $answers[1];
}
}
else {
$correctresponse = '';
$correctresponseid = $question->response[$questionid];
if ($answers[0]['id'] == $correctresponseid) {
$correctresponse = $answers[0];
} else {
$correctresponse = $answers[1];
}
} else {
$correctresponse = '';
}

$smarty->assign('correctresponse', $correctresponse);
$smarty->assign('answers', $answers);
$expout = $smarty->fetch('choice.tpl');
break;

case MULTICHOICE:
$answers = $this->objects_to_array($question->options->answers);
$correctresponses = $this->get_correct_answers($answers);
Expand Down

0 comments on commit e059fa9

Please sign in to comment.