LTI Integration Library 4.10.3
PHP class library for building LTI integrations
 
Loading...
Searching...
No Matches
LtiLinkItem.php
1<?php
2
3namespace ceLTIc\LTI\Content;
4
12class LtiLinkItem extends Item
13{
14
20 private $custom = array();
21
27 private $lineItem = null;
28
34 private $available = null;
35
41 private $submission = null;
42
48 private $noUpdate = null;
49
56 function __construct($placementAdvices = null, $id = null)
57 {
58 parent::__construct(Item::TYPE_LTI_LINK, $placementAdvices, $id);
60 }
61
68 public function addCustom($name, $value = null)
69 {
70 if (!empty($name)) {
71 if (!empty($value)) {
72 $this->custom[$name] = $value;
73 } else {
74 reset($this->custom[$name]);
75 }
76 }
77 }
78
84 public function setLineItem($lineItem)
85 {
86 $this->lineItem = $lineItem;
87 }
88
94 public function setAvailable($available)
95 {
96 $this->available = $available;
97 }
98
104 public function setSubmission($submission)
105 {
106 $this->submission = $submission;
107 }
108
114 public function setNoUpdate($noUpdate)
115 {
116 $this->noUpdate = $noUpdate;
117 }
118
124 public function toJsonldObject()
125 {
126 $item = parent::toJsonldObject();
127 if (!empty($this->lineItem)) {
128 $item->lineItem = $this->lineItem->toJsonldObject();
129 }
130 if (!is_null($this->noUpdate)) {
131 $item->noUpdate = $this->noUpdate;
132 }
133 if (!is_null($this->available)) {
134 $item->available = $this->available->toJsonldObject();
135 }
136 if (!is_null($this->submission)) {
137 $item->submission = $this->submission->toJsonldObject();
138 }
139 if (!empty($this->custom)) {
140 $item->custom = $this->custom;
141 }
142
143 return $item;
144 }
145
151 public function toJsonObject()
152 {
153 $item = parent::toJsonObject();
154 if (!empty($this->lineItem)) {
155 $item->lineItem = $this->lineItem->toJsonObject();
156 }
157 if (!is_null($this->noUpdate)) {
158 $item->noUpdate = $this->noUpdate;
159 }
160 if (!is_null($this->available)) {
161 $item->available = $this->available->toJsonObject();
162 }
163 if (!is_null($this->submission)) {
164 $item->submission = $this->submission->toJsonObject();
165 }
166 if (!empty($this->custom)) {
167 $item->custom = $this->custom;
168 }
169
170 return $item;
171 }
172
178 protected function fromJsonObject($item)
179 {
180 parent::fromJsonObject($item);
181 foreach (get_object_vars($item) as $name => $value) {
182 switch ($name) {
183 case 'custom':
184 foreach ($item->custom as $paramName => $paramValue) {
185 $this->addCustom($paramName, $paramValue);
186 }
187 break;
188 case 'lineItem':
189 $this->setLineItem(LineItem::fromJsonObject($item->lineItem));
190 break;
191 case 'available':
192 $this->setAvailable(TimePeriod::fromJsonObject($item->available));
193 break;
194 case 'submission':
195 $this->setSubmission(TimePeriod::fromJsonObject($item->submission));
196 break;
197 case 'noUpdate':
198 $this->noUpdate = $item->noUpdate;
199 break;
200 }
201 }
202 }
203
204}
Class to represent a content-item object.
const TYPE_LTI_LINK
Type for LTI link content-item.
const LTI_LINK_MEDIA_TYPE
Media type for LTI launch links.
setMediaType($mediaType)
Set a media type value for the content-item.
static fromJsonObject($item)
Generate a LineItem object from its JSON or JSON-LD representation.
Class to represent an LTI link content-item object.
addCustom($name, $value=null)
Add a custom parameter for the content-item.
__construct($placementAdvices=null, $id=null)
Class constructor.
toJsonObject()
Wrap the content items to form a complete value for the https://purl.imsglobal.org/spec/lti-dl/claim/...
fromJsonObject($item)
Extract content-item details from its JSON representation.
setSubmission($submission)
Set a submission time period for the content-item.
setLineItem($lineItem)
Set a line-item for the content-item.
setNoUpdate($noUpdate)
Set whether the content-item should not be allowed to be updated.
setAvailable($available)
Set an availability time period for the content-item.
toJsonldObject()
Wrap the content item to form an item complying with the application/vnd.ims.lti.v1....
static fromJsonObject($item)
Generate a LineItem object from its JSON or JSON-LD representation.