From 383a8dfb0408fc278f8fd1af71c3298dfa144a52 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 26 Nov 2014 19:42:40 -0800 Subject: [PATCH 1/2] MDL-46498 mod_assign: display correct grading status --- mod/assign/lib.php | 16 ++++++++-- mod/assign/locallib.php | 62 +++++++++++++++++++++++++++++---------- mod/assign/renderable.php | 8 ++++- mod/assign/renderer.php | 16 ++++++---- 4 files changed, 77 insertions(+), 25 deletions(-) diff --git a/mod/assign/lib.php b/mod/assign/lib.php index 872e0b13ba4..91d7b556c26 100644 --- a/mod/assign/lib.php +++ b/mod/assign/lib.php @@ -493,11 +493,21 @@ function assign_print_overview($courses, &$htmlarray) { } else { $str .= get_string('submissionstatus_' . $submission->status, 'assign'); } - if (!$submission || !$submission->grade || $submission->grade < 0) { - $str .= ', ' . get_string('notgraded', 'assign'); + + if ($assignment->markingworkflow) { + $workflowstate = $DB->get_field('assign_user_flags', 'workflowstate', array('assignment' => + $assignment->id, 'userid' => $USER->id)); + if ($workflowstate) { + $gradingstatus = 'markingworkflowstate' . $workflowstate; + } else { + $gradingstatus = 'markingworkflowstate' . ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED; + } + } else if (!empty($submission->grade) && $submission->grade !== null && $submission->grade >= 0) { + $gradingstatus = ASSIGN_GRADING_STATUS_GRADED; } else { - $str .= ', ' . get_string('graded', 'assign'); + $gradingstatus = ASSIGN_GRADING_STATUS_NOT_GRADED; } + $str .= ', ' . get_string($gradingstatus, 'assign'); $str .= ''; } $str .= ''; diff --git a/mod/assign/locallib.php b/mod/assign/locallib.php index 57aac5550ef..7b0e3612eb4 100644 --- a/mod/assign/locallib.php +++ b/mod/assign/locallib.php @@ -48,6 +48,10 @@ define('ASSIGN_ATTEMPT_REOPEN_METHOD_UNTILPASS', 'untilpass'); // Special value means allow unlimited attempts. define('ASSIGN_UNLIMITED_ATTEMPTS', -1); +// Grading states. +define('ASSIGN_GRADING_STATUS_GRADED', 'graded'); +define('ASSIGN_GRADING_STATUS_NOT_GRADED', 'notgraded'); + // Marking workflow states. define('ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED', 'notmarked'); define('ASSIGN_MARKING_WORKFLOW_STATE_INMARKING', 'inmarking'); @@ -1924,7 +1928,9 @@ class assign { return true; } - $this->gradebook_item_update(null, $grade); + if ($this->gradebook_item_update(null, $grade)) { + \mod_assign\event\submission_graded::create_from_grade($this, $grade)->trigger(); + } // If the conditions are met, allow another attempt. if ($submission) { @@ -1932,7 +1938,7 @@ class assign { $submission, $reopenattempt); } - \mod_assign\event\submission_graded::create_from_grade($this, $grade)->trigger(); + return true; } @@ -2971,7 +2977,8 @@ class assign { $this->is_blind_marking(), '', $instance->attemptreopenmethod, - $instance->maxattempts); + $instance->maxattempts, + $this->get_grading_status($userid)); $o .= $this->get_renderer()->render($submissionstatus); } @@ -3285,7 +3292,6 @@ class assign { require_once($CFG->dirroot . '/mod/assign/gradeform.php'); // Only load this if it is. - $o .= $this->view_grading_table(); $o .= $this->view_footer(); @@ -3826,6 +3832,7 @@ class assign { } $viewfullnames = has_capability('moodle/site:viewfullnames', $this->get_course_context()); + $gradingstatus = $this->get_grading_status($user->id); $submissionstatus = new assign_submission_status($instance->allowsubmissionsfromdate, $instance->alwaysshowdescription, $submission, @@ -3852,7 +3859,8 @@ class assign { $this->is_blind_marking(), $gradingcontrollerpreview, $instance->attemptreopenmethod, - $instance->maxattempts); + $instance->maxattempts, + $gradingstatus); $o .= $this->get_renderer()->render($submissionstatus); require_once($CFG->libdir.'/gradelib.php'); @@ -3883,10 +3891,7 @@ class assign { } } - $gradereleased = true; - if ($this->get_instance()->markingworkflow && - (empty($grade) || $flags->workflowstate != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED)) { - $gradereleased = false; + if ($this->get_instance()->markingworkflow && $gradingstatus != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) { $emptyplugins = true; // Don't show feedback plugins until released either. } @@ -4226,12 +4231,12 @@ class assign { if ($this->is_blind_marking()) { return false; } - // If marking workflow is enabled and grade is not released then don't send to gradebook yet. - if ($this->get_instance()->markingworkflow && !empty($grade)) { - $flags = $this->get_user_flags($grade->userid, false); - if (empty($flags->workflowstate) || $flags->workflowstate != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) { - return false; - } + + // If marking workflow is enabled and grade is not released then remove any grade that may exist in the gradebook. + if ($this->get_instance()->markingworkflow && !empty($grade) && + $this->get_grading_status($grade->userid) != ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) { + // Remove the grade (if it exists) from the gradebook as it is not 'final'. + $grade->grade = -1; } if ($submission != null) { @@ -4261,7 +4266,7 @@ class assign { $assign->cmidnumber = $this->get_course_module()->idnumber; // Set assign gradebook feedback plugin status (enabled and visible). $assign->gradefeedbackenabled = $this->is_gradebook_feedback_enabled(); - return assign_grade_item_update($assign, $gradebookgrade); + return assign_grade_item_update($assign, $gradebookgrade) == GRADE_UPDATE_OK; } /** @@ -7167,6 +7172,31 @@ class assign { // Gradebook feedback plugin is either not visible/enabled. return false; } + + /** + * Returns the grading status. + * + * @param int $userid the user id + * @return string returns the grading status + */ + public function get_grading_status($userid) { + if ($this->get_instance()->markingworkflow) { + $flags = $this->get_user_flags($userid, false); + if (!empty($flags->workflowstate)) { + return $flags->workflowstate; + } + return ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED; + } else { + $attemptnumber = optional_param('attemptnumber', -1, PARAM_INT); + $grade = $this->get_user_grade($userid, false, $attemptnumber); + + if (!empty($grade) && $grade->grade !== null && $grade->grade >= 0) { + return ASSIGN_GRADING_STATUS_GRADED; + } else { + return ASSIGN_GRADING_STATUS_NOT_GRADED; + } + } + } } /** diff --git a/mod/assign/renderable.php b/mod/assign/renderable.php index 021cad2794e..55d3c7c90bc 100644 --- a/mod/assign/renderable.php +++ b/mod/assign/renderable.php @@ -384,6 +384,9 @@ class assign_submission_status implements renderable { public $attemptreopenmethod = 'none'; /** @var int maxattempts */ public $maxattempts = -1; + /** @var string gradingstatus */ + public $gradingstatus = ''; + /** * Constructor @@ -415,6 +418,7 @@ class assign_submission_status implements renderable { * @param string $gradingcontrollerpreview * @param string $attemptreopenmethod - The method of reopening student attempts. * @param int $maxattempts - How many attempts can a student make? + * @param string $gradingstatus - The submission status (ie. Graded, Not Released etc). */ public function __construct($allowsubmissionsfromdate, $alwaysshowdescription, @@ -442,7 +446,8 @@ class assign_submission_status implements renderable { $blindmarking, $gradingcontrollerpreview, $attemptreopenmethod, - $maxattempts) { + $maxattempts, + $gradingstatus) { $this->allowsubmissionsfromdate = $allowsubmissionsfromdate; $this->alwaysshowdescription = $alwaysshowdescription; $this->submission = $submission; @@ -470,6 +475,7 @@ class assign_submission_status implements renderable { $this->gradingcontrollerpreview = $gradingcontrollerpreview; $this->attemptreopenmethod = $attemptreopenmethod; $this->maxattempts = $maxattempts; + $this->gradingstatus = $gradingstatus; } } diff --git a/mod/assign/renderer.php b/mod/assign/renderer.php index cdd72ad3cee..0520e1cf96b 100644 --- a/mod/assign/renderer.php +++ b/mod/assign/renderer.php @@ -552,12 +552,18 @@ class mod_assign_renderer extends plugin_renderer_base { $row = new html_table_row(); $cell1 = new html_table_cell(get_string('gradingstatus', 'assign')); - if ($status->graded) { - $cell2 = new html_table_cell(get_string('graded', 'assign')); - $cell2->attributes = array('class'=>'submissiongraded'); + if ($status->gradingstatus == ASSIGN_GRADING_STATUS_GRADED || + $status->gradingstatus == ASSIGN_GRADING_STATUS_NOT_GRADED) { + $cell2 = new html_table_cell(get_string($status->gradingstatus, 'assign')); } else { - $cell2 = new html_table_cell(get_string('notgraded', 'assign')); - $cell2->attributes = array('class'=>'submissionnotgraded'); + $gradingstatus = 'markingworkflowstate' . $status->gradingstatus; + $cell2 = new html_table_cell(get_string($gradingstatus, 'assign')); + } + if ($status->gradingstatus == ASSIGN_GRADING_STATUS_GRADED || + $status->gradingstatus == ASSIGN_MARKING_WORKFLOW_STATE_RELEASED) { + $cell2->attributes = array('class' => 'submissiongraded'); + } else { + $cell2->attributes = array('class' => 'submissionnotgraded'); } $row->cells = array($cell1, $cell2); $t->data[] = $row; From 7eeca30cef9b4ff2dafe4111b2f0025fe945a147 Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Wed, 10 Dec 2014 23:04:48 -0800 Subject: [PATCH 2/2] MDL-46498 mod_assign: added behat tests --- mod/assign/tests/behat/grading_status.feature | 155 ++++++++++++++++++ 1 file changed, 155 insertions(+) create mode 100644 mod/assign/tests/behat/grading_status.feature diff --git a/mod/assign/tests/behat/grading_status.feature b/mod/assign/tests/behat/grading_status.feature new file mode 100644 index 00000000000..f265f3ea8d2 --- /dev/null +++ b/mod/assign/tests/behat/grading_status.feature @@ -0,0 +1,155 @@ +@mod @mod_assign +Feature: View the grading status of an assignment + In order to test the grading status for assignments is displaying correctly + As a student + I need to view my grading status + + Background: + Given the following "courses" exist: + | fullname | shortname | category | groupmode | + | Course 1 | C1 | 0 | 1 | + And the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@asd.com | + | student1 | Student | 1 | student1@asd.com | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + + @javascript + Scenario: View the grading status for an assignment with marking workflow enabled + # Add the assignment. + And I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + And I add a "Assignment" to section "1" and I fill the form with: + | Assignment name | Test assignment name | + | Description | Test assignment description | + | Online text | 1 | + | Use marking workflow | Yes | + And I log out + # Add a submission. + And I log in as "student1" + And I follow "Course 1" + When I follow "Test assignment name" + Then I should not see "Feedback" + And I should see "Not marked" in the "Grading status" "table_row" + And I press "Add submission" + And I set the following fields to these values: + | Online text | I'm the student's first submission | + And I press "Save changes" + And I click on "My home" "link" in the "Navigation" "block" + And I click on ".collapsibleregioncaption" "css_element" + And I should see "Not marked" + And I log out + # Mark the submission. + And I log in as "teacher1" + And I follow "Course 1" + And I follow "Test assignment name" + And I follow "View/grade all submissions" + And I should see "Not marked" in the "Student 1" "table_row" + And I click on "Grade Student 1" "link" in the "Student 1" "table_row" + And I set the field "Grade out of 100" to "50" + And I set the field "Marking workflow state" to "In review" + And I set the field "Feedback comments" to "Great job! Lol, not really." + And I press "Save changes" + And I press "Continue" + And I should see "In review" in the "Student 1" "table_row" + And I log out + # View the grading status as a student. + And I log in as "student1" + And I follow "Course 1" + And I follow "Test assignment name" + And I should see "In review" in the "Grading status" "table_row" + And I should not see "Great job! Lol, not really." + And I click on "My home" "link" in the "Navigation" "block" + And I click on ".collapsibleregioncaption" "css_element" + And I should see "In review" + And I log out + # Mark the submission again but set the marking workflow to 'Released'. + And I log in as "teacher1" + And I follow "Course 1" + And I follow "Test assignment name" + And I follow "View/grade all submissions" + And I should see "In review" in the "Student 1" "table_row" + And I click on "Grade Student 1" "link" in the "Student 1" "table_row" + And I set the field "Marking workflow state" to "Released" + And I press "Save changes" + And I press "Continue" + And I should see "Released" in the "Student 1" "table_row" + And I log out + # View the grading status as a student. + And I log in as "student1" + And I follow "Course 1" + And I follow "Test assignment name" + And I should see "Released" in the "Grading status" "table_row" + And I should see "Great job! Lol, not really." + And I click on "My home" "link" in the "Navigation" "block" + And I click on ".collapsibleregioncaption" "css_element" + And I should see "Released" + And I log out + # Now, change the status from 'Released' to 'In marking' (this will remove the grade from the gradebook). + And I log in as "teacher1" + And I follow "Course 1" + And I follow "Test assignment name" + And I follow "View/grade all submissions" + And I should see "Released" in the "Student 1" "table_row" + And I click on "Grade Student 1" "link" in the "Student 1" "table_row" + And I set the field "Marking workflow state" to "In marking" + And I press "Save changes" + And I press "Continue" + And I should see "In marking" in the "Student 1" "table_row" + # The grade should also remain displayed as it's stored in the assign DB tables, but the final grade should be empty. + And I should see "50.00" in the "#mod_assign_grading_r0_c5" "css_element" + And I should see "-" in the "#mod_assign_grading_r0_c13" "css_element" + And I log out + + @javascript + Scenario: View the grading status for an assignment with marking workflow disabled + # Add the assignment. + And I log in as "teacher1" + And I follow "Course 1" + And I turn editing mode on + And I add a "Assignment" to section "1" and I fill the form with: + | Assignment name | Test assignment name | + | Description | Test assignment description | + | Online text | 1 | + And I log out + # Add a submission. + And I log in as "student1" + And I click on "My home" "link" in the "Navigation" "block" + When I click on ".collapsibleregioncaption" "css_element" + Then I should see "Not graded" + And I follow "Course 1" + And I follow "Test assignment name" + And I should not see "Feedback" + And I should see "Not graded" in the "Grading status" "table_row" + And I press "Add submission" + And I set the following fields to these values: + | Online text | I'm the student's first submission | + And I press "Save changes" + And I log out + # Mark the submission. + And I log in as "teacher1" + And I follow "Course 1" + And I follow "Test assignment name" + And I follow "View/grade all submissions" + And I should not see "Graded" in the "Student 1" "table_row" + And I click on "Grade Student 1" "link" in the "Student 1" "table_row" + And I set the field "Grade out of 100" to "50" + And I set the field "Feedback comments" to "Great job! Lol, not really." + And I press "Save changes" + And I press "Continue" + And I should see "Graded" in the "Student 1" "table_row" + And I log out + # View the grading status as a student. + And I log in as "student1" + And I follow "Course 1" + And I follow "Test assignment name" + And I should see "Graded" in the "Grading status" "table_row" + And I should see "Great job! Lol, not really." + And I click on "My home" "link" in the "Navigation" "block" + And I click on ".collapsibleregioncaption" "css_element" + And I should see "Graded" + And I log out