-
Notifications
You must be signed in to change notification settings - Fork 2
CTP-4639 grade decimal validation #62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: CTP-4710---use-mustache-templates
Are you sure you want to change the base?
Changes from 3 commits
339485a
17e7385
084a58f
a636f06
04389b7
3b24730
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,6 +323,7 @@ protected function create_feedback() { | |
'code' => 'guidenotcompleted', | ||
]); | ||
} else { | ||
\core\notification::error(get_string('guidenotcompleted', 'gradingform_guide')); | ||
$renderer = $this->get_page_renderer(); | ||
$renderer->new_feedback_page($teacherfeedback); | ||
} | ||
|
@@ -331,7 +332,7 @@ protected function create_feedback() { | |
} | ||
|
||
/** | ||
* Saves the new feedback form for the first time. | ||
* Saves feedback form when updated from /actions/feedbacks/update.php. | ||
*/ | ||
protected function update_feedback() { | ||
|
||
|
@@ -372,9 +373,11 @@ protected function update_feedback() { | |
|
||
} else { | ||
$teacherfeedback->destroy(); | ||
// Clear cache. | ||
\mod_coursework\models\feedback::remove_cache($this->submission->courseworkid); | ||
\mod_coursework\models\submission::remove_cache($this->submission->courseworkid); | ||
if ($this->submission) { | ||
// Clear cache. | ||
\mod_coursework\models\feedback::remove_cache($this->submission->courseworkid); | ||
\mod_coursework\models\submission::remove_cache($this->submission->courseworkid); | ||
} | ||
|
||
// Remove associated files | ||
$fs = get_file_storage(); | ||
|
@@ -424,12 +427,20 @@ protected function update_feedback() { | |
if ($form->is_cancelled()) { | ||
redirect($courseworkpageurl); | ||
} | ||
|
||
$teacherfeedback = $form->process_data($teacherfeedback); | ||
|
||
$teacherfeedback->save(); | ||
$form->save_feedback_files($teacherfeedback); | ||
|
||
$formdata = $form->get_data(); | ||
$hasadvancedgrading = !empty($formdata->advancedgrading); | ||
if ($hasadvancedgrading || (isset($formdata->grade) && $form->grade_in_range($formdata->grade))) { | ||
$teacherfeedback = $form->process_data($teacherfeedback); | ||
$teacherfeedback->save(); | ||
$form->save_feedback_files($teacherfeedback); | ||
} else { | ||
\core\notification::error(get_string('pleasecorrecterrors', 'mod_coursework')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This appears to show Please correct errors and re-submit but doesn't give any indication exactly what the errors are and where they are. Maybe given mod_coursework's idiosyncratic form handling it's enough to stop a user saving an out-of-range number, but some indication of this (e.g. Grade must be between 0 and 100) would be better. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed it would be better to give more information but I wanted to avoid introducing more complexity. As it's only a single field I thought we could get away with this |
||
global $OUTPUT; | ||
echo $OUTPUT->header(); | ||
$form->display(); | ||
echo $OUTPUT->footer(); | ||
die(); | ||
} | ||
$gradeeditingtime = $teacherfeedback->get_coursework()->get_grade_editing_time(); | ||
if (empty($gradeeditingtime) || time() > $teacherfeedback->timecreated + $gradeeditingtime) { | ||
$this->try_auto_feedback_creation($teacherfeedback->get_submission()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,7 @@ public function definition() { | |
} else if ($feedback->stage_identifier == 'final_agreed_1') { | ||
$mform->addElement('text', 'grade', get_string('grade', 'mod_coursework')); | ||
$mform->setType('grade', PARAM_RAW); | ||
$mform->addRule('grade', get_string('error'), 'numeric', null, 'client'); | ||
} else { | ||
$mform->addElement('select', | ||
'grade', | ||
|
@@ -181,7 +182,6 @@ public function validate_grade($data) { | |
* @return feedback | ||
*/ | ||
public function process_data(feedback $feedback) { | ||
|
||
$formdata = $this->get_data(); | ||
$coursework = $feedback->get_coursework(); | ||
|
||
|
@@ -259,5 +259,36 @@ public function get_editor_options() { | |
$options = $editor->get_options(); | ||
return $options; | ||
} | ||
|
||
/** | ||
* If there are errors return array of errors ("fieldname" => "error message"). | ||
* | ||
* Server side rules do not work for uploaded files, implement serverside rules here if needed. | ||
* | ||
* @param array $data array of ("fieldname"=>value) of submitted data | ||
* @param array $files array of uploaded files "element_name"=>tmp_file_path | ||
* @return array of "element_name"=>"error_description" if there are errors, | ||
* or an empty array if everything is OK (true allowed for backwards compatibility too). | ||
*/ | ||
public function validation($data, $files) { | ||
$errors = parent::validation($data, $files); | ||
$hasadvancedgrading = !empty($data['advancedgrading']); | ||
if (!$hasadvancedgrading && isset($data['stage_identifier']) && $data['stage_identifier'] == 'final_agreed_1') { | ||
if (!$this->grade_in_range($data['grade'])) { | ||
$errors['grade'] = get_string('err_numeric', 'form'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't see this message ever gets shown to the user? Also, this message, You must enter a number here., is returned (but not shown) if you enter 12345 (i.e. a number), so I'm not sure this is the best message. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, it isn't shown, as the rest of the code is not handling the form in the standard moodle way. However it does stop the form being submitted, which was my main reason for including it, and then the core\notification::error() call notifies the user (not ideal but saves lots of refactoring) |
||
} | ||
} | ||
return $errors; | ||
} | ||
|
||
/** | ||
* Agreed grade can be entered as text field (float or int) so need to validate it. | ||
*/ | ||
public function grade_in_range(string $grade): bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the coursework instance has Grading method = "Rubric" then when the manager attempts to save the agreed grade they get:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks I addressed this in commit 084a58f |
||
$feedback = $this->_customdata['feedback']; | ||
$coursework = $feedback->get_coursework(); | ||
$gradeoptions = array_keys(make_grades_menu($coursework->grade)); | ||
return is_numeric($grade) && $grade >= min($gradeoptions) && $grade <= max($gradeoptions); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,3 +44,21 @@ Feature: For the final grade the mark should be to the decimal point | |
And I click the new multiple final feedback button for the student | ||
And I grade the submission as 56.12 using the ajax form | ||
Then I should see the final grade as 56.12 on the multiple marker page | ||
|
||
Scenario: If I enter non-numeric characters for the grade I should see an error | ||
Given there are feedbacks from both teachers | ||
And I log in as a manager | ||
And I visit the coursework page | ||
And I click on "Add agreed feedback" "link" | ||
And I set the field "Grade" to "abc" | ||
And I wait "1" seconds | ||
Then I should see "- Error" | ||
|
||
Scenario: If I enter a grade which is out of range I should see an error | ||
Given there are feedbacks from both teachers | ||
And I log in as a manager | ||
And I visit the coursework page | ||
And I click on "Add agreed feedback" "link" | ||
And I set the field "Grade" to "1234" | ||
And I press "Save and finalise" | ||
Then I should see "Please correct errors and re-submit" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commit 084a58f changed this error message so this test fails currently:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great I fixed this in commit a636f06. Also fixed some other issues in the test and added some more checks so it is pretty thorough now. Also figured out why the form was not displaying validation messages as it should and fixed that. Finally removed some of the now redundant "ajax" code. Note the change to styles.css was tiny though the diff here is showing up some formatting changes only (tabs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this declaration,
$CFG
,$USER
and$PAGE
are all in scope.