mirror of
https://github.com/moodle/moodle.git
synced 2025-03-19 23:20:09 +01:00
Merge branch 'MDL-43386' of git://github.com/jmvedrine/moodle
This commit is contained in:
commit
7b0fdf24ab
@ -50,6 +50,11 @@ $attempt = new stdClass();
|
||||
$user = new stdClass();
|
||||
$attemptid = optional_param('attemptid', 0, PARAM_INT);
|
||||
|
||||
$formattextdefoptions = new stdClass();
|
||||
$formattextdefoptions->noclean = true;
|
||||
$formattextdefoptions->para = false;
|
||||
$formattextdefoptions->context = $context;
|
||||
|
||||
if ($attemptid > 0) {
|
||||
$attempt = $DB->get_record('lesson_attempts', array('id' => $attemptid));
|
||||
$answer = $DB->get_record('lesson_answers', array('lessonid' => $lesson->id, 'pageid' => $attempt->pageid));
|
||||
@ -201,8 +206,6 @@ switch ($mode) {
|
||||
if (!$answers = $DB->get_records_select('lesson_answers', "lessonid = ? AND pageid $answerUsql", $parameters, '', 'pageid, score')) {
|
||||
print_error('cannotfindanswer', 'lesson');
|
||||
}
|
||||
$options = new stdClass;
|
||||
$options->noclean = true;
|
||||
|
||||
foreach ($attempts as $attempt) {
|
||||
$essayinfo = unserialize($attempt->useranswer);
|
||||
@ -226,8 +229,9 @@ switch ($mode) {
|
||||
|
||||
// Set rest of the message values
|
||||
$currentpage = $lesson->load_page($attempt->pageid);
|
||||
$a->question = format_text($currentpage->contents, $currentpage->contentsformat, $options);
|
||||
$a->response = s($essayinfo->answer);
|
||||
$a->question = format_text($currentpage->contents, $currentpage->contentsformat, $formattextdefoptions);
|
||||
$a->response = format_text($essayinfo->answer, $essayinfo->answerformat,
|
||||
array('context' => $context, 'para' => true));
|
||||
$a->comment = s($essayinfo->response);
|
||||
|
||||
// Fetch message HTML and plain text formats
|
||||
@ -401,8 +405,9 @@ switch ($mode) {
|
||||
$data->id = $cm->id;
|
||||
$data->attemptid = $attemptid;
|
||||
$data->score = $essayinfo->score;
|
||||
$data->question = format_string($currentpage->contents, $currentpage->contentsformat);
|
||||
$data->studentanswer = format_string($essayinfo->answer, $essayinfo->answerformat);
|
||||
$data->question = format_text($currentpage->contents, $currentpage->contentsformat, $formattextdefoptions);
|
||||
$data->studentanswer = format_text($essayinfo->answer, $essayinfo->answerformat,
|
||||
array('context' => $context, 'para' => true));
|
||||
$data->response = $essayinfo->response;
|
||||
$mform->set_data($data);
|
||||
|
||||
|
@ -2087,12 +2087,20 @@ abstract class lesson_page extends lesson_base {
|
||||
$options->noclean = true;
|
||||
$options->para = true;
|
||||
$options->overflowdiv = true;
|
||||
$options->context = $context;
|
||||
$result->response = file_rewrite_pluginfile_urls($result->response, 'pluginfile.php', $context->id,
|
||||
'mod_lesson', 'page_responses', $result->answerid);
|
||||
|
||||
$result->feedback = $OUTPUT->box(format_text($this->get_contents(), $this->properties->contentsformat, $options), 'generalbox boxaligncenter');
|
||||
$result->feedback .= '<div class="correctanswer generalbox"><em>'.get_string("youranswer", "lesson").'</em> : '.$result->studentanswer; // already in clean html
|
||||
$result->feedback .= $OUTPUT->box($result->response, $class); // already conerted to HTML
|
||||
if (isset($result->studentanswerformat)) {
|
||||
// This is the student's answer so it should be cleaned.
|
||||
$studentanswer = format_text($result->studentanswer, $result->studentanswerformat,
|
||||
array('context' => $context, 'para' => true));
|
||||
} else {
|
||||
$studentanswer = format_string($result->studentanswer);
|
||||
}
|
||||
$result->feedback .= '<div class="correctanswer generalbox"><em>'
|
||||
. get_string("youranswer", "lesson").'</em> : ' . $studentanswer;
|
||||
$result->feedback .= $OUTPUT->box($result->response, $class); // Already converted to HTML.
|
||||
$result->feedback .= '</div>';
|
||||
}
|
||||
}
|
||||
|
@ -237,6 +237,8 @@ class lesson_page_type_branchtable extends lesson_page {
|
||||
$answers = $this->get_answers();
|
||||
$formattextdefoptions = new stdClass;
|
||||
$formattextdefoptions->para = false; //I'll use it widely in this page
|
||||
$formattextdefoptions->context = $answerpage->context;
|
||||
|
||||
foreach ($answers as $answer) {
|
||||
$data = "<input type=\"button\" name=\"$answer->id\" value=\"".s(strip_tags(format_text($answer->answer, FORMAT_MOODLE,$formattextdefoptions)))."\" disabled=\"disabled\"> ";
|
||||
$data .= get_string('jumpsto', 'lesson', $this->get_jump_name($answer->jumpto));
|
||||
|
@ -122,7 +122,7 @@ class lesson_page_type_essay extends lesson_page {
|
||||
$userresponse->response = "";
|
||||
$result->userresponse = serialize($userresponse);
|
||||
$result->studentanswerformat = $studentanswerformat;
|
||||
$result->studentanswer = s($studentanswer);
|
||||
$result->studentanswer = $studentanswer;
|
||||
return $result;
|
||||
}
|
||||
public function update($properties, $context = null, $maxbytes = null) {
|
||||
@ -179,9 +179,6 @@ class lesson_page_type_essay extends lesson_page {
|
||||
}
|
||||
public function report_answers($answerpage, $answerdata, $useranswer, $pagestats, &$i, &$n) {
|
||||
$answers = $this->get_answers();
|
||||
$formattextdefoptions = new stdClass;
|
||||
$formattextdefoptions->para = false; //I'll use it widely in this page
|
||||
$formattextdefoptions->context = $answerpage->context;
|
||||
|
||||
foreach ($answers as $answer) {
|
||||
if ($useranswer != null) {
|
||||
@ -224,7 +221,9 @@ class lesson_page_type_essay extends lesson_page {
|
||||
// dont think this should ever be reached....
|
||||
$avescore = get_string("nooneansweredthisquestion", "lesson");
|
||||
}
|
||||
$answerdata->answers[] = array(format_text($essayinfo->answer, $essayinfo->answerformat, $formattextdefoptions), $avescore);
|
||||
// This is the student's answer so it should be cleaned.
|
||||
$answerdata->answers[] = array(format_text($essayinfo->answer, $essayinfo->answerformat,
|
||||
array('para' => true, 'context' => $answerpage->context)), $avescore);
|
||||
$answerpage->answerdata = $answerdata;
|
||||
}
|
||||
return $answerpage;
|
||||
|
@ -353,6 +353,7 @@ class lesson_page_type_multichoice extends lesson_page {
|
||||
$answers = $this->get_used_answers();
|
||||
$formattextdefoptions = new stdClass;
|
||||
$formattextdefoptions->para = false; //I'll use it widely in this page
|
||||
$formattextdefoptions->context = $answerpage->context;
|
||||
|
||||
foreach ($answers as $answer) {
|
||||
if ($this->properties->qoption) {
|
||||
|
@ -245,6 +245,8 @@ class lesson_page_type_truefalse extends lesson_page {
|
||||
$formattextdefoptions = new stdClass(); //I'll use it widely in this page
|
||||
$formattextdefoptions->para = false;
|
||||
$formattextdefoptions->noclean = true;
|
||||
$formattextdefoptions->context = $answerpage->context;
|
||||
|
||||
foreach ($answers as $answer) {
|
||||
$answer = parent::rewrite_answers_urls($answer);
|
||||
if ($this->properties->qoption) {
|
||||
|
@ -466,6 +466,7 @@ if ($action === 'delete') {
|
||||
$options = new stdClass;
|
||||
$options->noclean = true;
|
||||
$options->overflowdiv = true;
|
||||
$options->context = $context;
|
||||
$answerpage->contents = format_text($page->contents, $page->contentsformat, $options);
|
||||
|
||||
$answerpage->qtype = $qtypes[$page->qtype].$page->option_description_string();
|
||||
|
79
mod/lesson/tests/behat/lesson_essay_question.feature
Normal file
79
mod/lesson/tests/behat/lesson_essay_question.feature
Normal file
@ -0,0 +1,79 @@
|
||||
@mod @mod_lesson
|
||||
Feature: In a lesson activity, teacher can add an essay question
|
||||
As a teacher
|
||||
I need to add an essay question in a lesson and grade student attempts
|
||||
|
||||
@javascript
|
||||
Scenario: questions with essay question
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@asd.com |
|
||||
| student1 | Student | 1 | student1@asd.com |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| student1 | C1 | student |
|
||||
And I log in as "teacher1"
|
||||
And I navigate to "My private files" node in "My profile"
|
||||
And I upload "mod/lesson/tests/fixtures/moodle_logo.jpg" file to "Files" filemanager
|
||||
And I click on "Save changes" "button"
|
||||
When I am on homepage
|
||||
And I follow "Course 1"
|
||||
And I turn editing mode on
|
||||
And I add a "Lesson" to section "1" and I fill the form with:
|
||||
| Name | Test lesson name |
|
||||
| Description | Test lesson description |
|
||||
| Use default feedback | Yes |
|
||||
And I follow "Test lesson name"
|
||||
And I follow "Add a question page"
|
||||
And I set the field "Select a question type" to "Essay"
|
||||
And I press "Add a question page"
|
||||
And I set the following fields to these values:
|
||||
| Page title | Essay question |
|
||||
| Page contents | <p>Please write a story about a <b>frog</b>.</p> |
|
||||
And I click on "Image" "button"
|
||||
And I click on "Browse repositories..." "button"
|
||||
And I click on "Private files" "link"
|
||||
And I click on "moodle_logo.jpg" "link"
|
||||
And I click on "Select this file" "button"
|
||||
And I set the field "Describe this image for someone who cannot see it" to "It's the logo"
|
||||
And I click on "Save image" "button"
|
||||
And I press "Save page"
|
||||
And I log out
|
||||
And I log in as "student1"
|
||||
And I follow "Course 1"
|
||||
When I follow "Test lesson name"
|
||||
Then I should see "Please write a story about a frog."
|
||||
And I set the field "Your answer" to "<p>Once upon a time there was a little <b>green</b> frog."
|
||||
And I click on "Image" "button"
|
||||
And I set the following fields to these values:
|
||||
| Enter URL | http://upload.wikimedia.org/wikipedia/commons/thumb/3/38/Greenfrog.jpg/120px-Greenfrog.jpg |
|
||||
| Describe this image for someone who cannot see it | A frog |
|
||||
And I press "Save image"
|
||||
And I press "Submit"
|
||||
And I should see "Your answer"
|
||||
And I should see "Once upon a time there was a little green frog."
|
||||
And I should not see "<b>"
|
||||
And I press "Continue"
|
||||
And I should see "Congratulations - end of lesson reached"
|
||||
And I should see "You earned 0 out of 0 for the automatically graded questions."
|
||||
And I should see "Your 1 essay question(s) will be graded and added into your final score at a later date."
|
||||
And I should see "Your current grade without the essay question(s) is 0 out of 1."
|
||||
And I log out
|
||||
And I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
And I follow "Test lesson name"
|
||||
And I follow "Grade essays"
|
||||
And I should see "Student 1"
|
||||
And I should see "Essay question"
|
||||
And I follow "Essay question"
|
||||
And I should see "Student 1's response"
|
||||
And I should see "Once upon a time there was a little green frog."
|
||||
And I set the following fields to these values:
|
||||
| Your comments | Well done. |
|
||||
| Essay score | 1 |
|
||||
And I press "Save changes"
|
||||
And I should see "Changes saved"
|
Loading…
x
Reference in New Issue
Block a user