3namespace ceLTIc\LTI\Content;
22 private $label =
null;
29 private $scoreMaximum =
null;
36 private $resourceId =
null;
50 private $submissionReview =
null;
61 function __construct($label, $scoreMaximum, $resourceId =
null, $tag =
null, $submissionReview =
null)
63 $this->label = $label;
64 $this->scoreMaximum = $scoreMaximum;
65 $this->resourceId = $resourceId;
67 $this->submissionReview = $submissionReview;
77 $lineItem = new \stdClass();
79 $lineItem->{
'@type'} =
'LineItem';
80 $lineItem->label = $this->label;
81 $lineItem->reportingMethod =
'http://purl.imsglobal.org/ctx/lis/v2p1/Result#normalScore';
82 if (!empty($this->resourceId)) {
83 $lineItem->assignedActivity = new \stdClass();
84 $lineItem->assignedActivity->activityId = $this->resourceId;
86 $lineItem->scoreConstraints = new \stdClass();
87 $lineItem->scoreConstraints->{
'@type'} =
'NumericLimits';
88 $lineItem->scoreConstraints->normalMaximum = $this->scoreMaximum;
89 if (!empty($this->submissionReview)) {
90 $lineItem->submissionReview = $this->submissionReview->toJsonObject();
103 $lineItem = new \stdClass();
105 $lineItem->label = $this->label;
106 $lineItem->scoreMaximum = $this->scoreMaximum;
107 if (!empty($this->resourceId)) {
108 $lineItem->resourceId = $this->resourceId;
110 if (!empty($this->tag)) {
111 $lineItem->tag = $this->tag;
113 if (!empty($this->submissionReview)) {
114 $lineItem->submissionReview = $this->submissionReview->toJsonObject();
131 $reportingMethod =
null;
132 $scoreMaximum =
null;
137 $submissionReview =
null;
138 foreach (get_object_vars($item) as $name => $value) {
141 $label = $item->label;
143 case 'reportingMethod':
144 $reportingMethod = $item->reportingMethod;
146 case 'scoreConstraints':
147 $scoreConstraints = $item->scoreConstraints;
150 $scoreMaximum = $item->scoreMaximum;
152 case 'assignedActivity':
153 if (isset($item->assignedActivity->activityId)) {
154 $activityId = $item->assignedActivity->activityId;
158 $activityId = $item->resourceId;
163 case 'submissionReview':
164 $submissionReview = SubmissionReview::fromJsonObject($item->submissionReview);
168 if (is_null($scoreMaximum) && $label && $reportingMethod && $scoreConstraints) {
169 foreach (get_object_vars($scoreConstraints) as $name => $value) {
170 $method = str_replace(
'Maximum',
'Score', $name);
171 if (substr($reportingMethod, -strlen($method)) === $method) {
172 $scoreMaximum = $value;
177 if (!is_null($scoreMaximum)) {
178 $obj =
new LineItem($label, $scoreMaximum, $activityId, $tag, $submissionReview);
Class to represent a line-item object.
__construct($label, $scoreMaximum, $resourceId=null, $tag=null, $submissionReview=null)
Class constructor.
static fromJsonObject($item)
Generate a LineItem object from its JSON or JSON-LD representation.
toJsonObject()
Generate the JSON object representation of the line-item.
toJsonldObject()
Generate the JSON-LD object representation of the line-item.
Class to represent a submission review.