Skip to content

Commit

Permalink
MDL-34483 qformat_examview: changes required to make it basically work.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Michel Vedrine authored and timhunt committed Jul 26, 2012
1 parent 55a568f commit 2562c13
Showing 1 changed file with 41 additions and 11 deletions.
52 changes: 41 additions & 11 deletions question/format/examview/format.php
Expand Up @@ -58,6 +58,10 @@ function provide_import() {
return true;
}

public function mime_type() {
return 'application/xml';
}

/**
* unxmlise reconstructs part of the xml data structure in order
* to identify the actual data therein
Expand All @@ -84,6 +88,26 @@ function unxmlise( $xml ) {
$text = strip_tags($text);
return $text;
}
protected function text_field($text) {
return array(
'text' => htmlspecialchars(trim($text), ENT_NOQUOTES),
'format' => FORMAT_HTML,
'files' => array(),
);
}

protected function add_blank_combined_feedback($question) {
$question->correctfeedback['text'] = '';
$question->correctfeedback['format'] = $question->questiontextformat;
$question->correctfeedback['files'] = array();
$question->partiallycorrectfeedback['text'] = '';
$question->partiallycorrectfeedback['format'] = $question->questiontextformat;
$question->partiallycorrectfeedback['files'] = array();
$question->incorrectfeedback['text'] = '';
$question->incorrectfeedback['format'] = $question->questiontextformat;
$question->incorrectfeedback['files'] = array();
return $question;
}

function parse_matching_groups($matching_groups)
{
Expand Down Expand Up @@ -115,7 +139,7 @@ function parse_ma($qrec, $groupname)
$phrase = trim($this->unxmlise($qrec['text']['0']['#']));
$answer = trim($this->unxmlise($qrec['answer']['0']['#']));
$answer = strip_tags( $answer );
$match_group->subquestions[] = $phrase;
$match_group->subquestions[] = $this->text_field($phrase);
$match_group->subanswers[] = $match_group->subchoices[$answer];
$this->matching_questions[$groupname] = $match_group;
return NULL;
Expand All @@ -130,8 +154,11 @@ function process_matches(&$questions)
$question = $this->defaultquestion();
$htmltext = s($match_group->questiontext);
$question->questiontext = $htmltext;
$question->name = $question->questiontext;
$question->questiontextformat = FORMAT_HTML;
$question->questiontextfiles = array();
$question->name = shorten_text( $question->questiontext, 250 );
$question->qtype = MATCH;
$question = $this->add_blank_combined_feedback($question);
$question->subquestions = array();
$question->subanswers = array();
foreach($match_group->subquestions as $key => $value) {
Expand Down Expand Up @@ -192,6 +219,8 @@ function readquestion($qrec)
// Only one answer is allowed
$htmltext = $this->unxmlise($qrec['#']['text'][0]['#']);
$question->questiontext = $htmltext;
$question->questiontextformat = FORMAT_HTML;
$question->questiontextfiles = array();
$question->name = shorten_text( $question->questiontext, 250 );

switch ($question->qtype) {
Expand Down Expand Up @@ -232,30 +261,31 @@ function parse_tf_yn($qrec, $question)
$question->answer = $choices[$answer];
$question->correctanswer = $question->answer;
if ($question->answer == 1) {
$question->feedbacktrue = 'Correct';
$question->feedbackfalse = 'Incorrect';
$question->feedbacktrue = $this->text_field('Correct');
$question->feedbackfalse = $this->text_field('Incorrect');
} else {
$question->feedbacktrue = 'Incorrect';
$question->feedbackfalse = 'Correct';
$question->feedbacktrue = $this->text_field('Incorrect');
$question->feedbackfalse = $this->text_field('Correct');
}
return $question;
}

function parse_mc($qrec, $question)
{
$question = $this->add_blank_combined_feedback($question);
$answer = 'choice-'.strtolower(trim($qrec['answer'][0]['#']));

$choices = $qrec['choices'][0]['#'];
foreach($choices as $key => $value) {
if (strpos(trim($key),'choice-') !== FALSE) {

$question->answer[$key] = s($this->unxmlise($value[0]['#']));
$question->answer[$key] = $this->text_field(s($this->unxmlise($value[0]['#'])));
if (strcmp($key, $answer) == 0) {
$question->fraction[$key] = 1;
$question->feedback[$key] = 'Correct';
$question->feedback[$key] = $this->text_field('Correct');
} else {
$question->fraction[$key] = 0;
$question->feedback[$key] = 'Incorrect';
$question->feedback[$key] = $this->text_field('Incorrect');
}
}
}
Expand All @@ -274,7 +304,7 @@ function parse_co($qrec, $question)
if (strlen($value) > 0) {
$question->answer[$key] = $value;
$question->fraction[$key] = 1;
$question->feedback[$key] = "Correct";
$question->feedback[$key] = $this->text_field("Correct");
}
}
return $question;
Expand All @@ -299,7 +329,7 @@ function parse_nr($qrec, $question)
$errormargin = 0;
$question->answer[$key] = $value;
$question->fraction[$key] = 1;
$question->feedback[$key] = "Correct";
$question->feedback[$key] = $this->text_field("Correct");
$question->min[$key] = $question->answer[$key] - $errormargin;
$question->max[$key] = $question->answer[$key] + $errormargin;
}
Expand Down

0 comments on commit 2562c13

Please sign in to comment.