Skip to content

Commit fc2dae1

Browse files
authored
Merge pull request #30 from packbackbooks/fix-no-sync-for-0-grades
PODB-263 Fix 0 grades not syncing for LTI 1.3
2 parents 78fab66 + dd2a358 commit fc2dae1

File tree

5 files changed

+44
-6
lines changed

5 files changed

+44
-6
lines changed

src/Helpers/Helpers.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace Packback\Lti1p3\Helpers;
4+
5+
class Helpers
6+
{
7+
/**
8+
* @param $value
9+
*/
10+
public static function checkIfNullValue($value): bool
11+
{
12+
return !is_null($value);
13+
}
14+
}

src/LtiGrade.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,20 @@ public function __construct(array $grade = null)
2828

2929
public function __toString()
3030
{
31-
return json_encode(array_filter([
32-
'scoreGiven' => 0 + $this->score_given,
33-
'scoreMaximum' => 0 + $this->score_maximum,
31+
// Additionally, includes the call back to filter out only NULL values
32+
$request = array_filter([
33+
'scoreGiven' => $this->score_given,
34+
'scoreMaximum' => $this->score_maximum,
3435
'comment' => $this->comment,
3536
'activityProgress' => $this->activity_progress,
3637
'gradingProgress' => $this->grading_progress,
3738
'timestamp' => $this->timestamp,
3839
'userId' => $this->user_id,
3940
'submissionReview' => $this->submission_review,
4041
'https://canvas.instructure.com/lti/submission' => $this->canvas_extension,
41-
]));
42+
], '\Packback\Lti1p3\Helpers\Helpers::checkIfNullValue');
43+
44+
return json_encode($request);
4245
}
4346

4447
/**

src/LtiGradeSubmissionReview.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@ public function __construct(array $gradeSubmission = null)
1919

2020
public function __toString()
2121
{
22+
// Additionally, includes the call back to filter out only NULL values
2223
return json_encode(array_filter([
2324
'reviewableStatus' => $this->reviewable_status,
2425
'label' => $this->label,
2526
'url' => $this->url,
2627
'custom' => $this->custom,
27-
]));
28+
], '\Packback\Lti1p3\Helpers\Helpers::checkIfNullValue'));
2829
}
2930

3031
/**

src/LtiLineitem.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public function __construct(array $lineitem = null)
2727

2828
public function __toString()
2929
{
30+
// Additionally, includes the call back to filter out only NULL values
3031
return json_encode(array_filter([
3132
'id' => $this->id,
3233
'scoreMaximum' => $this->score_maximum,
@@ -35,7 +36,7 @@ public function __toString()
3536
'tag' => $this->tag,
3637
'startDateTime' => $this->start_date_time,
3738
'endDateTime' => $this->end_date_time,
38-
]));
39+
], '\Packback\Lti1p3\Helpers\Helpers::checkIfNullValue'));
3940
}
4041

4142
/**

tests/LtiGradeTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,25 @@ public function testItCastsFullObjectToString()
213213
$this->assertEquals(json_encode($expected), (string) $grade);
214214
}
215215

216+
public function testItCastsFullObjectToStringWith0Grade()
217+
{
218+
$expected = [
219+
'scoreGiven' => 0,
220+
'scoreMaximum' => 10,
221+
'comment' => 'Comment',
222+
'activityProgress' => 'ActivityProgress',
223+
'gradingProgress' => 'GradingProgress',
224+
'timestamp' => 'Timestamp',
225+
'userId' => 'UserId',
226+
'submissionReview' => 'SubmissionReview',
227+
'https://canvas.instructure.com/lti/submission' => 'CanvasExtension',
228+
];
229+
230+
$grade = new LtiGrade($expected);
231+
232+
$this->assertEquals(json_encode($expected), (string) $grade);
233+
}
234+
216235
public function testItCastsEmptyObjectToString()
217236
{
218237
$this->assertEquals('[]', (string) $this->grade);

0 commit comments

Comments
 (0)