Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion actions/feedbacks/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
*/

require_once(dirname(__FILE__) . '/../../../../config.php');
require_login();
require_sesskey();

global $CFG, $USER;
global $CFG, $USER, $PAGE;
Copy link
Contributor

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.


$feedbackid = required_param('feedbackid', PARAM_INT);
$finalised = (bool)optional_param('submitbutton', 0, PARAM_TEXT);
Expand All @@ -46,5 +48,7 @@
$params['cell_type'] = required_param('cell_type', PARAM_TEXT);
}

$PAGE->set_url(new moodle_url('/mod/coursework/actions/feedbacks/update.php', $params));

$controller = new mod_coursework\controllers\feedback_controller($params);
$controller->update_feedback();
278 changes: 44 additions & 234 deletions classes/controllers/feedback_controller.php

Large diffs are not rendered by default.

48 changes: 43 additions & 5 deletions classes/forms/assessor_feedback_mform.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -114,6 +117,7 @@ public function definition() {
'return_types' => FILE_INTERNAL,
];


$uploadfilestring = get_string('uploadafile');
$this->_form->addElement('filemanager',
'feedback_manager',
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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();

Expand Down Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The 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:

Exception - mod_coursework\forms\assessor_feedback_mform::grade_in_range(): Argument #1 ($grade) must be of type string, null given, called in [dirroot]/mod/coursework/classes/forms/assessor_feedback_mform.php on line 276

[More information about this error](https://docs.moodle.org/405/en/error/moodle/generalexceptionmessage)

Debug info:
Error code: generalexceptionmessage×Dismiss this notification
Stack trace:
line 286 of /mod/coursework/classes/forms/assessor_feedback_mform.php: TypeError thrown
line 276 of /mod/coursework/classes/forms/assessor_feedback_mform.php: call to mod_coursework\forms\assessor_feedback_mform->grade_in_range()
line 674 of /lib/formslib.php: call to mod_coursework\forms\assessor_feedback_mform->validation()
line 610 of /lib/formslib.php: call to moodleform->validate_defined_fields()
line 720 of /lib/formslib.php: call to moodleform->is_validated()
line 224 of /mod/coursework/classes/controllers/feedback_controller.php: call to moodleform->get_data()
line ? of unknownfile: call to mod_coursework\controllers\feedback_controller->create_feedback()
line 175 of /mod/coursework/classes/controllers/controller_base.php: call to call_user_func()
line 52 of /mod/coursework/actions/feedbacks/create.php: call to mod_coursework\controllers\controller_base->__call()

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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);
}
}

1 change: 1 addition & 0 deletions lang/en/coursework.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@
$string['enablegeneralfeedback'] = 'Enable general feedback';
$string['enablegeneralfeedback_help'] = 'This will allow teachers to edit a bit of text which will be released to all students automatically once the deadline for general feedback passes. It is intended for situations when an exam or similar is coming up and areas for all students to improve upon are emerging, but there has not yet been time to mark and release the grades for all the students individually.';
$string['enroltask'] = 'Coursework process enrolment allocation task';
$string['err_valueoutofrange'] = 'You must enter a whole number or decimal within the range of marks accepted by this coursework';
$string['eventassessableuploaded'] = 'A file has been uploaded.';
$string['downloadgrades'] = 'Download grades';
$string['downloadgradingsheets'] = 'Download grading sheet';
Expand Down
Loading
Loading