Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 400 and 402] [Versions 400 and 403]

   1  <?php
   2  
   3  namespace Packback\Lti1p3;
   4  
   5  class LtiGrade
   6  {
   7      private $score_given;
   8      private $score_maximum;
   9      private $comment;
  10      private $activity_progress;
  11      private $grading_progress;
  12      private $timestamp;
  13      private $user_id;
  14      private $submission_review;
  15  
  16      public function __construct(array $grade = null)
  17      {
  18          $this->score_given = $grade['scoreGiven'] ?? null;
  19          $this->score_maximum = $grade['scoreMaximum'] ?? null;
  20          $this->comment = $grade['comment'] ?? null;
  21          $this->activity_progress = $grade['activityProgress'] ?? null;
  22          $this->grading_progress = $grade['gradingProgress'] ?? null;
  23          $this->timestamp = $grade['timestamp'] ?? null;
  24          $this->user_id = $grade['userId'] ?? null;
  25          $this->submission_review = $grade['submissionReview'] ?? null;
  26          $this->canvas_extension = $grade['https://canvas.instructure.com/lti/submission'] ?? null;
  27      }
  28  
  29      public function __toString()
  30      {
  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,
  35              'comment' => $this->comment,
  36              'activityProgress' => $this->activity_progress,
  37              'gradingProgress' => $this->grading_progress,
  38              'timestamp' => $this->timestamp,
  39              'userId' => $this->user_id,
  40              'submissionReview' => $this->submission_review,
  41              'https://canvas.instructure.com/lti/submission' => $this->canvas_extension,
  42          ], '\Packback\Lti1p3\Helpers\Helpers::checkIfNullValue');
  43  
  44          return json_encode($request);
  45      }
  46  
  47      /**
  48       * Static function to allow for method chaining without having to assign to a variable first.
  49       */
  50      public static function new()
  51      {
  52          return new LtiGrade();
  53      }
  54  
  55      public function getScoreGiven()
  56      {
  57          return $this->score_given;
  58      }
  59  
  60      public function setScoreGiven($value)
  61      {
  62          $this->score_given = $value;
  63  
  64          return $this;
  65      }
  66  
  67      public function getScoreMaximum()
  68      {
  69          return $this->score_maximum;
  70      }
  71  
  72      public function setScoreMaximum($value)
  73      {
  74          $this->score_maximum = $value;
  75  
  76          return $this;
  77      }
  78  
  79      public function getComment()
  80      {
  81          return $this->comment;
  82      }
  83  
  84      public function setComment($comment)
  85      {
  86          $this->comment = $comment;
  87  
  88          return $this;
  89      }
  90  
  91      public function getActivityProgress()
  92      {
  93          return $this->activity_progress;
  94      }
  95  
  96      public function setActivityProgress($value)
  97      {
  98          $this->activity_progress = $value;
  99  
 100          return $this;
 101      }
 102  
 103      public function getGradingProgress()
 104      {
 105          return $this->grading_progress;
 106      }
 107  
 108      public function setGradingProgress($value)
 109      {
 110          $this->grading_progress = $value;
 111  
 112          return $this;
 113      }
 114  
 115      public function getTimestamp()
 116      {
 117          return $this->timestamp;
 118      }
 119  
 120      public function setTimestamp($value)
 121      {
 122          $this->timestamp = $value;
 123  
 124          return $this;
 125      }
 126  
 127      public function getUserId()
 128      {
 129          return $this->user_id;
 130      }
 131  
 132      public function setUserId($value)
 133      {
 134          $this->user_id = $value;
 135  
 136          return $this;
 137      }
 138  
 139      public function getSubmissionReview()
 140      {
 141          return $this->submission_review;
 142      }
 143  
 144      public function setSubmissionReview($value)
 145      {
 146          $this->submission_review = $value;
 147  
 148          return $this;
 149      }
 150  
 151      public function getCanvasExtension()
 152      {
 153          return $this->canvas_extension;
 154      }
 155  
 156      // Custom Extension for Canvas.
 157      // https://documentation.instructure.com/doc/api/score.html
 158      public function setCanvasExtension($value)
 159      {
 160          $this->canvas_extension = $value;
 161  
 162          return $this;
 163      }
 164  }