-
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 all 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
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,9 @@ 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('err_valueoutofrange', 'mod_coursework'), 'numeric', null, 'client' | ||
); | ||
} else { | ||
$mform->addElement('select', | ||
'grade', | ||
|
@@ -114,6 +117,7 @@ public function definition() { | |
'return_types' => FILE_INTERNAL, | ||
]; | ||
|
||
|
||
$uploadfilestring = get_string('uploadafile'); | ||
$this->_form->addElement('filemanager', | ||
'feedback_manager', | ||
|
@@ -166,12 +170,16 @@ public function add_submit_buttons($draftenabled, $feedbackid) { | |
* @param $data | ||
* @return bool | ||
*/ | ||
public function validate_grade($data) { | ||
$result = true; | ||
public function validate_grade($data): bool { | ||
if (!empty($this->_grading_instance) && property_exists($data, 'advancedgrading')) { | ||
$result = $this->_grading_instance->validate_grading_element($data->advancedgrading); | ||
return $this->_grading_instance->validate_grading_element($data->advancedgrading); | ||
} else { | ||
$errors = self::validation($data, []); | ||
if (!empty($errors)) { | ||
return false; | ||
} | ||
} | ||
return $result; | ||
return true; | ||
} | ||
|
||
/** | ||
|
@@ -181,7 +189,6 @@ public function validate_grade($data) { | |
* @return feedback | ||
*/ | ||
public function process_data(feedback $feedback) { | ||
|
||
$formdata = $this->get_data(); | ||
$coursework = $feedback->get_coursework(); | ||
|
||
|
@@ -259,5 +266,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_valueoutofrange', 'coursework'); | ||
} | ||
} | ||
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); | ||
} | ||
} | ||
|
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.