diff --git a/mod/quiz/report/grading/lang/en/quiz_grading.php b/mod/quiz/report/grading/lang/en/quiz_grading.php index 08c65530fb4e2..1912ceb716e49 100644 --- a/mod/quiz/report/grading/lang/en/quiz_grading.php +++ b/mod/quiz/report/grading/lang/en/quiz_grading.php @@ -71,7 +71,7 @@ $string['questionsthatneedgrading'] = 'Questions that need grading'; $string['questiontitle'] = 'Question {$a->number} : "{$a->name}" ({$a->openspan}{$a->gradedattempts}{$a->closespan} / {$a->totalattempts} attempts {$a->openspan}graded{$a->closespan}).'; $string['random'] = 'Random'; -$string['saveandnext'] = 'Save and go to next page'; +$string['saveandnext'] = 'Save and show next'; $string['showstudentnames'] = 'Show student names'; $string['tograde'] = 'To grade'; $string['total'] = 'Total'; diff --git a/mod/quiz/report/grading/renderer.php b/mod/quiz/report/grading/renderer.php index 624c0a35f05a6..62e3bff2b3b3d 100644 --- a/mod/quiz/report/grading/renderer.php +++ b/mod/quiz/report/grading/renderer.php @@ -22,8 +22,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); - /** * The renderer for the quiz_grading module. * @@ -148,9 +146,7 @@ public function render_grading_interface($questioninfo, $listquestionsurl, $filt $output .= $this->heading(get_string('gradingattemptsxtoyofz', 'quiz_grading', $paginginfo), 3); - if ($pagingbar->count > $pagingbar->pagesize && $pagingbar->order != 'random') { - $output .= $this->paging_bar($pagingbar->count, $pagingbar->page, $pagingbar->pagesize, $pagingbar->pagingurl); - } + $output .= $this->render_paging_bar($pagingbar); $output .= html_writer::start_tag('form', [ 'method' => 'post', @@ -170,6 +166,8 @@ public function render_grading_interface($questioninfo, $listquestionsurl, $filt ]), ['class' => 'mdl-align']); $output .= html_writer::end_tag('div') . html_writer::end_tag('form'); + $output .= $this->render_paging_bar($pagingbar); + // Add the form change checker. $this->page->requires->js_call_amd('core_form/changechecker', 'watchFormById', ['manualgradingform']); @@ -197,4 +195,17 @@ public function render_grade_question($questionusage, $slot, $displayoptions, $q return $output; } + + /** + * Render paging bar. + * + * @param object $pagingbar Pagination bar information. + * @return string The HTML for the question display. + */ + public function render_paging_bar(object $pagingbar): string { + if ($pagingbar->count > $pagingbar->pagesize && $pagingbar->order != 'random') { + return $this->paging_bar($pagingbar->count, $pagingbar->page, $pagingbar->pagesize, $pagingbar->pagingurl); + } + return ''; + } } diff --git a/mod/quiz/report/grading/report.php b/mod/quiz/report/grading/report.php index 7f90ed9f56260..e1b94c49a3ba6 100644 --- a/mod/quiz/report/grading/report.php +++ b/mod/quiz/report/grading/report.php @@ -148,9 +148,16 @@ public function display($quiz, $cm, $course) { // Process any submitted data. if ($data = data_submitted() && confirm_sesskey() && $this->validate_submitted_marks()) { - $this->process_submitted_data(); + // Changes done to handle attempts being missed from grading due to redirecting to new page. + $attemptsgraded = $this->process_submitted_data(); - redirect($this->grade_question_url($slot, $questionid, $grade, $page + 1)); + $nextpagenumber = $page + 1; + // If attempts need grading and one or more have now been graded, then page number should remain the same. + if ($grade == 'needsgrading' && $attemptsgraded) { + $nextpagenumber = $page; + } + + redirect($this->grade_question_url($slot, $questionid, $grade, $nextpagenumber)); } // Get the group, and the list of significant users. @@ -552,15 +559,17 @@ protected function validate_submitted_marks() { /** * Save all submitted marks to the database. + * + * @return bool returns true if some attempts or all are graded. False, if none of the attempts are graded. */ - protected function process_submitted_data() { + protected function process_submitted_data(): bool { global $DB; $qubaids = optional_param('qubaids', null, PARAM_SEQUENCE); $assumedslotforevents = optional_param('slot', null, PARAM_INT); if (!$qubaids) { - return; + return false; } $qubaids = clean_param_array(explode(',', $qubaids), PARAM_INT); @@ -568,11 +577,24 @@ protected function process_submitted_data() { $events = []; $transaction = $DB->start_delegated_transaction(); + $attemptsgraded = false; foreach ($qubaids as $qubaid) { $attempt = $attempts[$qubaid]; $attemptobj = new quiz_attempt($attempt, $this->quiz, $this->cm, $this->course); + + // State of the attempt before grades are changed. + $attemptoldtstate = $attemptobj->get_question_state($assumedslotforevents); + $attemptobj->process_submitted_actions(time()); + // Get attempt state after grades are changed. + $attemptnewtstate = $attemptobj->get_question_state($assumedslotforevents); + + // Check if any attempts are graded. + if (!$attemptsgraded && $attemptoldtstate->is_graded() != $attemptnewtstate->is_graded()) { + $attemptsgraded = true; + } + // Add the event we will trigger later. $params = [ 'objectid' => $attemptobj->get_question_attempt($assumedslotforevents)->get_question_id(), @@ -592,6 +614,8 @@ protected function process_submitted_data() { foreach ($events as $event) { $event->trigger(); } + + return $attemptsgraded; } /** diff --git a/mod/quiz/report/grading/tests/behat/grading.feature b/mod/quiz/report/grading/tests/behat/grading.feature index 962c9478240b3..ecf4770acca6c 100644 --- a/mod/quiz/report/grading/tests/behat/grading.feature +++ b/mod/quiz/report/grading/tests/behat/grading.feature @@ -51,8 +51,9 @@ Feature: Basic use of the Manual grading report | questioncategory | qtype | name | questiontext | answer 1 | grade | | Test questions | shortanswer | Short answer 001 | Where is the capital city of France? | Paris | 100% | And the following "activities" exist: - | activity | name | course | idnumber | groupmode | grouping | - | quiz | Quiz 1 | C1 | quiz1 | 1 | tging | + | activity | name | course | idnumber | groupmode | grouping | + | quiz | Quiz 1 | C1 | quiz1 | 1 | tging | + | quiz | Quiz 2 | C1 | quiz2 | 1 | tging | And quiz "Quiz 1" contains the following questions: | question | page | | Short answer 001 | 1 | @@ -95,7 +96,7 @@ Feature: Basic use of the Manual grading report # Adjust the mark for Student1 And I set the field "Comment" to "I have adjusted your mark to 0.6" And I set the field "Mark" to "0.6" - And I press "Save and go to next page" + And I press "Save and show next" And I should see "All selected attempts have been graded. Returning to the list of questions." And "Short answer 001" row "To grade" column of "questionstograde" table should contain "0" And "Short answer 001" row "Already graded" column of "questionstograde" table should contain "1" @@ -164,3 +165,53 @@ Feature: Basic use of the Manual grading report Then I should see "Quiz 1" And I should see "Separate groups: All participants" Then I should see "Sorry, but you need to be part of a group to see this page." + + @javascript + Scenario: Manual grading report with attempts to be graded + Given the following "questions" exist: + | questioncategory | qtype | name | user | questiontext | + | Test questions | essay | Essay Q1 | admin | Question 1 text | + And quiz "Quiz 2" contains the following questions: + | question | page | + | Essay Q1 | 1 | + And I log out + When I am on the "Quiz 2" "mod_quiz > View" page logged in as "student1" + And I press "Attempt quiz" + And I set the field with xpath "//*[contains(concat(' ', @class, ' '), ' editor_atto_content ')]" to "This is my attempt 1" + And I follow "Finish attempt ..." + And I press "Submit all and finish" + And I click on "Submit all and finish" "button" in the "Confirmation" "dialogue" + And I click on "Finish review" "link" + And I press "Re-attempt quiz" + And I set the field with xpath "//*[contains(concat(' ', @class, ' '), ' editor_atto_content ')]" to "This is my attempt 2" + And I follow "Finish attempt ..." + And I press "Submit all and finish" + And I click on "Submit all and finish" "button" in the "Confirmation" "dialogue" + And I click on "Finish review" "link" + And I press "Re-attempt quiz" + And I set the field with xpath "//*[contains(concat(' ', @class, ' '), ' editor_atto_content ')]" to "This is my attempt 3" + And I follow "Finish attempt ..." + And I press "Submit all and finish" + And I click on "Submit all and finish" "button" in the "Confirmation" "dialogue" + And I log out + + And I am on the "Quiz 2" "mod_quiz > Manual grading report" page logged in as "teacher1" + And I follow "Also show questions that have been graded automatically" + And I should see "Essay Q1" + And "Essay Q1" row "To grade" column of "questionstograde" table should contain "3" + And "Essay Q1" row "Already graded" column of "questionstograde" table should contain "0" + # Go to the grading page. + And I click on "grade" "link" in the "Essay Q1" "table_row" + And I should see "Grading attempts 1 to 3 of 3" + And I set the following fields to these values: + | Questions per page | 1 | + | Order attempts by | ID number | + And I press "Change options" + And I should see "Grading attempts 1 to 1 of 3" + # Adjust the mark for Student1 + And I set the field "Comment" to "I have adjusted your mark to 0.6" + And I set the field "Mark" to "0.6" + And I press "Save and show next" + Then I should see "Grading attempts 1 to 1 of 2" + And I press "Save and show next" + And I should see "Grading attempts 2 to 2 of 2" diff --git a/mod/quiz/tests/behat/attempt_redo_questions.feature b/mod/quiz/tests/behat/attempt_redo_questions.feature index 74b01c6c3607c..8694dfdac5356 100644 --- a/mod/quiz/tests/behat/attempt_redo_questions.feature +++ b/mod/quiz/tests/behat/attempt_redo_questions.feature @@ -177,7 +177,7 @@ Feature: Allow students to redo questions in a practice quiz, without starting a When I click on "update grades" "link" in the "SA1" "table_row" Then I set the field "Comment" to "I have adjusted your mark to 1.0" And I set the field "Mark" to "1.0" - And I press "Save and go to next page" + And I press "Save and show next" And I follow "Results" And I follow "Review attempt" And I should see "Teacher One" in the "I have adjusted your mark to 1.0" "table_row"