Skip to content

Commit

Permalink
MDL-63608 quiz: Fix Access order when manually grading quizzes
Browse files Browse the repository at this point in the history
Changes done to fix access order of attempts that need manual grading.
Changed button text from 'Save and go to next page' to 'Save and show next' to improve UI.
  • Loading branch information
AnupamaSarjoshi committed Feb 10, 2023
1 parent 44d77d0 commit d7d375e
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 14 deletions.
2 changes: 1 addition & 1 deletion mod/quiz/report/grading/lang/en/quiz_grading.php
Expand Up @@ -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';
Expand Down
21 changes: 16 additions & 5 deletions mod/quiz/report/grading/renderer.php
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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',
Expand All @@ -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']);

Expand Down Expand Up @@ -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 '';
}
}
32 changes: 28 additions & 4 deletions mod/quiz/report/grading/report.php
Expand Up @@ -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.
Expand Down Expand Up @@ -552,27 +559,42 @@ 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);
$attempts = $this->load_attempts_by_usage_ids($qubaids);
$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(),
Expand All @@ -592,6 +614,8 @@ protected function process_submitted_data() {
foreach ($events as $event) {
$event->trigger();
}

return $attemptsgraded;
}

/**
Expand Down
57 changes: 54 additions & 3 deletions mod/quiz/report/grading/tests/behat/grading.feature
Expand Up @@ -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 |
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
2 changes: 1 addition & 1 deletion mod/quiz/tests/behat/attempt_redo_questions.feature
Expand Up @@ -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"

0 comments on commit d7d375e

Please sign in to comment.