Skip to content

Commit

Permalink
Merge pull request 1EdTech#30 from packbackbooks/fix-no-sync-for-0-gr…
Browse files Browse the repository at this point in the history
…ades

PODB-263 Fix 0 grades not syncing for LTI 1.3
  • Loading branch information
zlayaAvocado authored Oct 25, 2021
2 parents 78fab66 + dd2a358 commit fc2dae1
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 6 deletions.
14 changes: 14 additions & 0 deletions src/Helpers/Helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Packback\Lti1p3\Helpers;

class Helpers
{
/**
* @param $value
*/
public static function checkIfNullValue($value): bool
{
return !is_null($value);
}
}
11 changes: 7 additions & 4 deletions src/LtiGrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ public function __construct(array $grade = null)

public function __toString()
{
return json_encode(array_filter([
'scoreGiven' => 0 + $this->score_given,
'scoreMaximum' => 0 + $this->score_maximum,
// Additionally, includes the call back to filter out only NULL values
$request = array_filter([
'scoreGiven' => $this->score_given,
'scoreMaximum' => $this->score_maximum,
'comment' => $this->comment,
'activityProgress' => $this->activity_progress,
'gradingProgress' => $this->grading_progress,
'timestamp' => $this->timestamp,
'userId' => $this->user_id,
'submissionReview' => $this->submission_review,
'https://canvas.instructure.com/lti/submission' => $this->canvas_extension,
]));
], '\Packback\Lti1p3\Helpers\Helpers::checkIfNullValue');

return json_encode($request);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/LtiGradeSubmissionReview.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ public function __construct(array $gradeSubmission = null)

public function __toString()
{
// Additionally, includes the call back to filter out only NULL values
return json_encode(array_filter([
'reviewableStatus' => $this->reviewable_status,
'label' => $this->label,
'url' => $this->url,
'custom' => $this->custom,
]));
], '\Packback\Lti1p3\Helpers\Helpers::checkIfNullValue'));
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/LtiLineitem.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function __construct(array $lineitem = null)

public function __toString()
{
// Additionally, includes the call back to filter out only NULL values
return json_encode(array_filter([
'id' => $this->id,
'scoreMaximum' => $this->score_maximum,
Expand All @@ -35,7 +36,7 @@ public function __toString()
'tag' => $this->tag,
'startDateTime' => $this->start_date_time,
'endDateTime' => $this->end_date_time,
]));
], '\Packback\Lti1p3\Helpers\Helpers::checkIfNullValue'));
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/LtiGradeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,25 @@ public function testItCastsFullObjectToString()
$this->assertEquals(json_encode($expected), (string) $grade);
}

public function testItCastsFullObjectToStringWith0Grade()
{
$expected = [
'scoreGiven' => 0,
'scoreMaximum' => 10,
'comment' => 'Comment',
'activityProgress' => 'ActivityProgress',
'gradingProgress' => 'GradingProgress',
'timestamp' => 'Timestamp',
'userId' => 'UserId',
'submissionReview' => 'SubmissionReview',
'https://canvas.instructure.com/lti/submission' => 'CanvasExtension',
];

$grade = new LtiGrade($expected);

$this->assertEquals(json_encode($expected), (string) $grade);
}

public function testItCastsEmptyObjectToString()
{
$this->assertEquals('[]', (string) $this->grade);
Expand Down

0 comments on commit fc2dae1

Please sign in to comment.