function qformat_blackboard_6::process_matching in Quiz 6.6
Same name and namespace in other branches
- 6.5 includes/moodle/question/format/blackboard_6/format.php \qformat_blackboard_6::process_matching()
1 call to qformat_blackboard_6::process_matching()
- qformat_blackboard_6::readquestions in includes/
moodle/ question/ format/ blackboard_6/ format.php - Parses an array of lines into an array of questions, where each item is a question object as defined by readquestion(). Questions are defined as anything between blank lines.
File
- includes/
moodle/ question/ format/ blackboard_6/ format.php, line 816
Class
Code
function process_matching($quest, &$questions) {
global $QTYPES;
// renderedmatch is an optional plugin, so we need to check if it is defined
if (array_key_exists('renderedmatch', $QTYPES)) {
$question = $this
->process_common($quest);
$question->valid = true;
$question->qtype = 'renderedmatch';
foreach ($quest->RESPONSE_BLOCK->subquestions as $qid => $subq) {
foreach ($quest->responses as $rid => $resp) {
if ($resp->ident == $subq->ident) {
$correct = addslashes($resp->correct);
$feedback = addslashes($resp->feedback);
}
}
foreach ($subq->choices as $cid => $choice) {
if ($choice == $correct) {
$question->subquestions[] = addslashes($subq->text);
$question->subanswers[] = addslashes($quest->RIGHT_MATCH_BLOCK->matching_answerset[$cid]->text);
}
}
}
// check format
$status = true;
if (count($quest->RESPONSE_BLOCK->subquestions) > count($quest->RIGHT_MATCH_BLOCK->matching_answerset) || count($question->subquestions) < 2) {
$status = false;
}
else {
// need to redo to make sure that no two questions have the same answer (rudimentary now)
foreach ($question->subanswers as $qstn) {
if (isset($previous)) {
if ($qstn == $previous) {
$status = false;
}
}
$previous = $qstn;
if ($qstn == '') {
$status = false;
}
}
}
if ($status) {
$questions[] = $question;
}
else {
global $COURSE, $CFG;
print '<table class="boxaligncenter" border="1">';
print '<tr><td colspan="2" style="background-color:#FF8888;">This matching question is malformed. Please ensure there are no blank answers, no two questions have the same answer, and/or there are correct answers for each question. There must be at least as many subanswers as subquestions, and at least one subquestion.</td></tr>';
print "<tr><td>Question:</td><td>" . $quest->QUESTION_BLOCK->text;
if (isset($quest->QUESTION_BLOCK->file)) {
print '<br/><font color="red">There is a subfile contained in the zipfile that has been copied to course files: bb_import/' . basename($quest->QUESTION_BLOCK->file) . '</font>';
if (preg_match('/(gif|jpg|jpeg|png)$/i', $quest->QUESTION_BLOCK->file)) {
print '<img src="' . $CFG->wwwroot . '/file.php/' . $COURSE->id . '/bb_import/' . basename($quest->QUESTION_BLOCK->file) . '" />';
}
}
print "</td></tr>";
print "<tr><td>Subquestions:</td><td><ul>";
foreach ($quest->responses as $rs) {
$correct_responses->{$rs->ident} = $rs->correct;
}
foreach ($quest->RESPONSE_BLOCK->subquestions as $subq) {
print '<li>' . $subq->text . '<ul>';
foreach ($subq->choices as $id => $choice) {
print '<li>';
if ($choice == $correct_responses->{$subq->ident}) {
print '<font color="green">';
}
else {
print '<font color="red">';
}
print $quest->RIGHT_MATCH_BLOCK->matching_answerset[$id]->text . '</font></li>';
}
print '</ul>';
}
print '</ul></td></tr>';
print '<tr><td>Feedback:</td><td><ul>';
foreach ($quest->feedback as $fb) {
print '<li>' . $fb->ident . ': ' . $fb->text . '</li>';
}
print '</ul></td></tr></table>';
}
}
else {
print "Matching question types are not handled because the quiz question type 'Rendered Matching' does not exist in this installation of Moodle<br/>";
print " Omitted Question: " . $quest->QUESTION_BLOCK->text . '<br/><br/>';
}
}