ILIAS  release_8 Revision v8.24
LtiLinkItem.php
Go to the documentation of this file.
1<?php
2
20
28class LtiLinkItem extends Item
29{
35 private array $custom = array();
36
42 private ?LineItem $lineItem = null;
43
49 private ?string $available = null;
50
56 private ?string $submission = null;
57
63 private ?bool $noUpdate = null;
64
71 public function __construct($placementAdvices = null, $id = null)
72 {
73 parent::__construct(Item::TYPE_LTI_LINK, $placementAdvices, $id);
75 }
76
82 public function addCustom(string $name, ?string $value = null)
83 {
84 if (!empty($name)) {
85 if (!empty($value)) {
86 $this->custom[$name] = $value;
87 } else {
88 reset($this->custom[$name]);
89 }
90 }
91 }
92
98 {
99 $this->lineItem = $lineItem;
100 }
101
106 public function setAvailable($available)
107 {
108 $this->available = $available;
109 }
110
115 public function setSubmission($submission)
116 {
117 $this->submission = $submission;
118 }
119
124 public function setNoUpdate(?bool $noUpdate)
125 {
126 $this->noUpdate = $noUpdate;
127 }
128
134 public function toJsonldObject(): object
135 {
136 $item = parent::toJsonldObject();
137 if (!empty($this->lineItem)) {
138 $item->lineItem = $this->lineItem->toJsonldObject();
139 }
140 if (!is_null($this->noUpdate)) {
141 $item->noUpdate = $this->noUpdate;
142 }
143 //ToDo: Check
144// if (!is_null($this->available)) {
145// $item->available = $this->available->toJsonldObject();
146// }
147// if (!is_null($this->submission)) {
148// $item->submission = $this->submission->toJsonldObject();
149// }
150 if (!empty($this->custom)) {
151 $item->custom = $this->custom;
152 }
153
154 return $item;
155 }
156
162 public function toJsonObject(): object
163 {
164 $item = parent::toJsonObject();
165 if (!empty($this->lineItem)) {
166 $item->lineItem = $this->lineItem->toJsonObject();
167 }
168 if (!is_null($this->noUpdate)) {
169 $item->noUpdate = $this->noUpdate;
170 }
171 //ToDo: Check
172// if (!is_null($this->available)) {
173// $item->available = $this->available->toJsonObject();
174// }
175// if (!is_null($this->submission)) {
176// $item->submission = $this->submission->toJsonObject();
177// }
178 if (!empty($this->custom)) {
179 $item->custom = $this->custom;
180 }
181
182 return $item;
183 }
184
189 protected function fromJsonObject(object $item)
190 {
191 parent::fromJsonObject($item);
192 foreach (get_object_vars($item) as $name => $value) {
193 switch ($name) {
194 case 'custom':
195 foreach ($item->custom as $paramName => $paramValue) {
196 $this->addCustom($paramName, $paramValue);
197 }
198 break;
199 case 'lineItem':
200 $this->setLineItem(LineItem::fromJsonObject($item->lineItem));
201 break;
202 case 'available':
203 $this->setAvailable(TimePeriod::fromJsonObject($item->available));
204 break;
205 case 'submission':
206 $this->setSubmission(TimePeriod::fromJsonObject($item->submission));
207 break;
208 case 'noUpdate':
209 $this->noUpdate = $item->noUpdate;
210 break;
211 }
212 }
213 }
214}
Class to represent a content-item object.
Definition: Item.php:32
setMediaType(string $mediaType)
Set a media type value for the content-item.
Definition: Item.php:185
const TYPE_LTI_LINK
Type for LTI link content-item.
Definition: Item.php:41
string $id
ID of content-item.
Definition: Item.php:86
const LTI_LINK_MEDIA_TYPE
Media type for LTI launch links.
Definition: Item.php:66
Class to represent a line-item object.
Definition: LineItem.php:29
static fromJsonObject(object $item)
Generate a LineItem object from its JSON or JSON-LD representation.
Definition: LineItem.php:122
Class to represent an LTI link content-item object.
Definition: LtiLinkItem.php:29
string $submission
Time period for submission.
Definition: LtiLinkItem.php:56
setLineItem(LineItem $lineItem)
Set a line-item for the content-item.
Definition: LtiLinkItem.php:97
addCustom(string $name, ?string $value=null)
Add a custom parameter for the content-item.
Definition: LtiLinkItem.php:82
setAvailable($available)
Set an availability time period for the content-item.
setNoUpdate(?bool $noUpdate)
Set whether the content-item should not be allowed to be updated.
toJsonObject()
Wrap the content items to form a complete value for the https://purl.imsglobal.org/spec/lti-dl/claim/...
LineItem $lineItem
Line-item object for content-item.
Definition: LtiLinkItem.php:42
toJsonldObject()
Wrap the content item to form an item complying with the application/vnd.ims.lti.v1....
__construct($placementAdvices=null, $id=null)
Class constructor.
Definition: LtiLinkItem.php:71
string $available
Time period for availability.
Definition: LtiLinkItem.php:49
fromJsonObject(object $item)
Extract content-item details from its JSON representation.
bool $noUpdate
Do not allow the item to be updated?
Definition: LtiLinkItem.php:63
array $custom
Custom parameters for content-item.
Definition: LtiLinkItem.php:35
setSubmission($submission)
Set a submission time period for the content-item.
static fromJsonObject(object $item)
Generate a LineItem object from its JSON or JSON-LD representation.
Definition: TimePeriod.php:88
if($format !==null) $name
Definition: metadata.php:247
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: FileItem.php:19