diff --git a/.gitignore b/.gitignore index a08302f..b726d58 100644 --- a/.gitignore +++ b/.gitignore @@ -46,5 +46,8 @@ development/node_modules/ # Local History for Visual Studio Code .history/ +## vim +.phpactor.json + # macOS .DS_Store diff --git a/classes/grading/grading_service.php b/classes/grading/grading_service.php index 23a01f9..a058743 100644 --- a/classes/grading/grading_service.php +++ b/classes/grading/grading_service.php @@ -74,7 +74,7 @@ public static function get_line_item(int $courseid, int $cmid, string $resourcel * * @param int $courseid * @param int $cmid - * @param array $data array with required fields userId, scoreGiven, comment, timestamp + * @param array $data array with required field userId * @return bool Returns true if the grade information could be persisted. * @throws LtiException * @throws \coding_exception @@ -91,14 +91,14 @@ public static function update_grade(int $courseid, int $cmid, array $data): bool throw new LtiException("Grade item for module CMID=$cmid (instance={$module->instance}) not found"); } - // Validate that the required fields exist in $data. - if (!isset($data['userId']) || !isset($data['scoreGiven']) || !isset($data['timestamp'])) { - throw new LtiException("Missing required fields in the request body"); + // Validate that the userId exist in $data. + if (!isset($data['userId'])) { + throw new LtiException("Missing userId in the request body"); } // Receive a score for the line item via JSON request body. $userid = $data['userId']; - $scoregiven = isset($data['scoreGiven']) ? max(0, min(floatval($data['scoreGiven']), $gradeitem->grademax)) : null; + $scoregiven = isset($data['scoreGiven']) ? floatval($data['scoreGiven']) : null; $comment = $data['comment'] ?? ''; $timestamp = isset($data['timestamp']) ? strtotime($data['timestamp']) : time(); diff --git a/lib.php b/lib.php index c996760..75fb9e9 100644 --- a/lib.php +++ b/lib.php @@ -213,7 +213,7 @@ function kialo_grade_item_update(stdClass $kialo, ?stdClass $grades = null): int 'idnumber' => $kialo->cmidnumber ?? '', ]; - if ($kialo->grade > 0) { + if ($kialo->grade >= 0) { $params['gradetype'] = GRADE_TYPE_VALUE; $params['grademax'] = $kialo->grade; $params['grademin'] = 0;