Skip to content

Commit

Permalink
PM-43593 fix: except empty scoreGrades and empty timestamps
Browse files Browse the repository at this point in the history
  • Loading branch information
jz-kialo authored and mk-kialo committed Oct 2, 2024
1 parent 310abb1 commit 34be721
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,8 @@ development/node_modules/
# Local History for Visual Studio Code
.history/

## vim
.phpactor.json

# macOS
.DS_Store
10 changes: 5 additions & 5 deletions classes/grading/grading_service.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 34be721

Please sign in to comment.