Merge branch 'MDL-61211-33' of git://github.com/mihailges/moodle into MOODLE_33_STABLE
This commit is contained in:
+63
-14
@@ -3676,6 +3676,11 @@ abstract class lesson_page extends lesson_base {
|
||||
const TYPE_QUESTION = 0;
|
||||
const TYPE_STRUCTURE = 1;
|
||||
|
||||
/**
|
||||
* Constant used as a delimiter when parsing multianswer questions
|
||||
*/
|
||||
const MULTIANSWER_DELIMITER = '@^#|';
|
||||
|
||||
/**
|
||||
* This method should return the integer used to identify the page type within
|
||||
* the database and throughout code. This maps back to the defines used in 1.x
|
||||
@@ -4097,37 +4102,81 @@ abstract class lesson_page extends lesson_base {
|
||||
$result->feedback .= '<div class="correctanswer generalbox"><em>'
|
||||
. get_string("youranswer", "lesson").'</em> : <div class="studentanswer m-t-2 m-b-2">';
|
||||
|
||||
$studentanswerarray = explode('<br />', $result->studentanswer);
|
||||
$responsearr = explode('<br />', $result->response);
|
||||
$studentanswerresponse = array_combine($studentanswerarray, $responsearr);
|
||||
// Create a table containing the answers and responses.
|
||||
$table = new html_table();
|
||||
foreach ($studentanswerresponse as $answer => $response) {
|
||||
// Multianswer allowed.
|
||||
if ($this->properties->qoption) {
|
||||
$studentanswerarray = explode(self::MULTIANSWER_DELIMITER, $result->studentanswer);
|
||||
$responsearr = explode(self::MULTIANSWER_DELIMITER, $result->response);
|
||||
$studentanswerresponse = array_combine($studentanswerarray, $responsearr);
|
||||
|
||||
foreach ($studentanswerresponse as $answer => $response) {
|
||||
// Add a table row containing the answer.
|
||||
$studentanswer = $this->format_answer($answer, $context, $result->studentanswerformat);
|
||||
$table->data[] = array($studentanswer);
|
||||
// If the response exists, add a table row containing the response. If not, add en empty row.
|
||||
if (!empty(trim($response))) {
|
||||
$studentresponse = isset($result->responseformat) ?
|
||||
$this->format_response($response, $context, $result->responseformat, $options) : $response;
|
||||
$table->data[] = array('<em>'.get_string("response", "lesson").
|
||||
'</em>: <br/>'.$studentresponse);
|
||||
} else {
|
||||
$table->data[] = array('');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Add a table row containing the answer.
|
||||
$studentanswer = format_text($answer, $result->studentanswerformat,
|
||||
array('context' => $context, 'para' => true));
|
||||
$studentanswer = $this->format_answer($result->studentanswer, $context, $result->studentanswerformat);
|
||||
$table->data[] = array($studentanswer);
|
||||
// If the response exists, add a table row containing the response. If not, add en empty row.
|
||||
if (!empty(trim($response))) {
|
||||
if (isset($result->responseformat)) {
|
||||
$convertstudentresponse = file_rewrite_pluginfile_urls($response, 'pluginfile.php',
|
||||
$context->id, 'mod_lesson', 'page_responses', $result->answerid);
|
||||
$studentresponse = format_text($convertstudentresponse, $result->responseformat, $options);
|
||||
} else {
|
||||
$studentresponse = $response;
|
||||
}
|
||||
if (!empty(trim($result->response))) {
|
||||
$studentresponse = isset($result->responseformat) ?
|
||||
$this->format_response($result->response, $context, $result->responseformat,
|
||||
$result->answerid, $options) : $result->response;
|
||||
$table->data[] = array('<em>'.get_string("response", "lesson").
|
||||
'</em>: <br/>'.$studentresponse);
|
||||
} else {
|
||||
$table->data[] = array('');
|
||||
}
|
||||
}
|
||||
|
||||
$result->feedback .= html_writer::table($table).'</div></div>';
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the answer
|
||||
*
|
||||
* @param string $answer
|
||||
* @param context $context
|
||||
* @param int $answerformat
|
||||
* @return string Returns formatted string
|
||||
*/
|
||||
private function format_answer($answer, $context, $answerformat) {
|
||||
|
||||
return format_text($answer, $answerformat, array('context' => $context, 'para' => true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the response
|
||||
*
|
||||
* @param string $response
|
||||
* @param context $context
|
||||
* @param int $responseformat
|
||||
* @param int $answerid
|
||||
* @param stdClass $options
|
||||
* @return string Returns formatted string
|
||||
*/
|
||||
private function format_response($response, $context, $responseformat, $answerid, $options) {
|
||||
|
||||
$convertstudentresponse = file_rewrite_pluginfile_urls($response, 'pluginfile.php',
|
||||
$context->id, 'mod_lesson', 'page_responses', $answerid);
|
||||
|
||||
return format_text($convertstudentresponse, $responseformat, $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the string for a jump name
|
||||
*
|
||||
|
||||
@@ -174,7 +174,7 @@ class lesson_page_type_multichoice extends lesson_page {
|
||||
}
|
||||
}
|
||||
}
|
||||
$result->studentanswer = implode('<br />', $studentanswerarray);
|
||||
$result->studentanswer = implode(self::MULTIANSWER_DELIMITER, $studentanswerarray);
|
||||
$correctpageid = null;
|
||||
$wrongpageid = null;
|
||||
|
||||
@@ -222,11 +222,11 @@ class lesson_page_type_multichoice extends lesson_page {
|
||||
|
||||
if ((count($studentanswers) == $ncorrect) and ($nhits == $ncorrect)) {
|
||||
$result->correctanswer = true;
|
||||
$result->response = implode('<br />', $responses);
|
||||
$result->response = implode(self::MULTIANSWER_DELIMITER, $responses);
|
||||
$result->newpageid = $correctpageid;
|
||||
$result->answerid = $correctanswerid;
|
||||
} else {
|
||||
$result->response = implode('<br />', $responses);
|
||||
$result->response = implode(self::MULTIANSWER_DELIMITER, $responses);
|
||||
$result->newpageid = $wrongpageid;
|
||||
$result->answerid = $wronganswerid;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user