86 public ?
string $id = null;
158 public function __construct(
string $type, $placementAdvices = null,
string $id = null)
161 if (!empty($placementAdvices)) {
162 if (!is_array($placementAdvices)) {
163 $placementAdvices = array($placementAdvices);
165 foreach ($placementAdvices as $placementAdvice) {
166 $this->placements[$placementAdvice->documentTarget] = $placementAdvice;
223 if (!empty($placementAdvice)) {
224 $this->placements[$placementAdvice->documentTarget] = $placementAdvice;
263 if (!is_array($items)) {
264 $items = array($items);
267 $obj = new \stdClass();
268 $obj->{
'@context'} =
'http://purl.imsglobal.org/ctx/lti/v1/ContentItem';
269 $obj->{
'@graph'} = array();
270 foreach ($items as $item) {
271 $obj->{
'@graph'}[] = $item->toJsonldObject();
275 foreach ($items as $item) {
276 $obj[] = $item->toJsonObject();
280 return json_encode($obj);
288 public static function fromJson(
object $items): array
290 $isJsonLd = isset($items->{
'@graph'});
292 $items = $items->{
'@graph'};
294 if (!is_array($items)) {
295 $items = array($items);
298 foreach ($items as $item) {
299 $obj = self::fromJsonItem($item);
315 $item = new \stdClass();
316 if (!empty($this->
id)) {
319 if (!empty($this->type)) {
320 if (($this->type === self::TYPE_LTI_LINK) || ($this->type === self::TYPE_LTI_ASSIGNMENT)) {
321 $item->{
'@type'} =
'LtiLinkItem';
322 } elseif ($this->type === self::TYPE_FILE) {
323 $item->{
'@type'} =
'FileItem';
325 $item->{
'@type'} =
'ContentItem';
328 $item->{
'@type'} =
'ContentItem';
330 if (!empty($this->title)) {
333 if (!empty($this->text)) {
335 } elseif (!empty($this->
html)) {
338 if (!empty($this->url)) {
341 if (!empty($this->mediaType)) {
344 if (!empty($this->placements)) {
345 $placementAdvice = new \stdClass();
346 $placementAdvices = array();
347 foreach ($this->placements as $placement) {
348 $obj = $placement->toJsonldObject();
350 if (!empty($placement->documentTarget)) {
351 $placementAdvices[] = $placement->documentTarget;
353 $placementAdvice = (
object) array_merge((array) $placementAdvice, (array) $obj);
356 if (!empty($placementAdvice)) {
357 $item->placementAdvice = $placementAdvice;
358 if (!empty($placementAdvices)) {
359 $item->placementAdvice->presentationDocumentTarget = implode(
',', $placementAdvices);
363 if (!empty($this->icon)) {
364 $item->icon = $this->icon->toJsonldObject();
366 if (!empty($this->thumbnail)) {
367 $item->thumbnail = $this->thumbnail->toJsonldObject();
369 if (!is_null($this->hideOnCreate)) {
383 $item = new \stdClass();
384 switch ($this->type) {
386 $item->type = self::TYPE_LTI_LINK;
389 $item->type = self::TYPE_FILE;
392 if (empty($this->url)) {
393 $item->type = self::TYPE_HTML;
394 } elseif (!empty($this->mediaType) && (strpos($this->mediaType,
'image') === 0)) {
395 $item->type = self::TYPE_IMAGE;
397 $item->type = self::TYPE_LINK;
404 if (!empty($this->title)) {
407 if (!empty($this->text)) {
410 if (!empty($this->
html)) {
413 if (!empty($this->url)) {
416 foreach ($this->placements as
$type => $placement) {
422 $obj = $placement->toJsonObject();
429 $item->{
$type} = $obj;
432 if (!empty($this->icon)) {
433 $item->icon = $this->icon->toJsonObject();
435 if (!empty($this->thumbnail)) {
436 $item->thumbnail = $this->thumbnail->toJsonObject();
438 if (!is_null($this->hideOnCreate)) {
454 if (isset($item->{
'@type'})) {
455 if (isset($item->presentationDocumentTarget)) {
458 switch ($item->{
'@type'}) {
460 $obj =
new Item(
'ContentItem', $placement);
463 $obj =
new LtiLinkItem($placement);
466 $obj =
new FileItem($placement);
469 } elseif (isset($item->type)) {
472 if (!empty($placement)) {
476 if (!empty($placement)) {
480 if (!empty($placement)) {
483 switch ($item->type) {
484 case self::TYPE_LINK:
485 case self::TYPE_HTML:
486 case self::TYPE_IMAGE:
489 case self::TYPE_LTI_LINK:
492 case self::TYPE_LTI_ASSIGNMENT:
495 case self::TYPE_FILE:
501 $obj->fromJsonObject($item);
513 if (isset($item->{
'@id'})) {
514 $this->
id = $item->{
'@id'};
516 foreach (get_object_vars($item) as
$name => $value) {
526 case 'placementAdvice':
const TYPE_LINK
Type for link content-item.
static fromJsonObject(object $item, string $documentTarget=null)
Generate the Placement object from an item.
const TYPE_FRAME
Frame placement type.
bool $hideOnCreate
Hide the item from learners by default?
Class to represent a content-item placement object.
string $type
Type of content-item.
string $html
HTML to be embedded.
static toJson($items, string $ltiVersion=Util::LTI_VERSION1)
Wrap the content items to form a complete application/vnd.ims.lti.v1.contentitems+json media type ins...
setIcon(Image $icon)
Set an icon image for the content-item.
const LTI_ASSIGNMENT_MEDIA_TYPE
Media type for LTI assignment links.
const TYPE_HTML
Type for HTML content-item.
string $url
URL of content-item.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $mediaType
Media type of content-item.
const TYPE_IMAGE
Type for image content-item.
Image $icon
Icon image object for content-item.
setText(string $text)
Set a link text value for the content-item.
Class to represent a content-item image object.
toJsonObject()
Wrap the content items to form a complete value for the https://purl.imsglobal.org/spec/lti-dl/claim/...
setHtml(string $html)
Set an HTML embed value for the content-item.
setTitle(string $title)
Set a title value for the content-item.
toJsonldObject()
Wrap the content item to form an item complying with the application/vnd.ims.lti.v1.contentitems+json media type.
addPlacementAdvice(Placement $placementAdvice)
Add a placement for the content-item.
const TYPE_LTI_LINK
Type for LTI link content-item.
string $text
Description of content-item.
setUrl(string $url)
Set a URL value for the content-item.
fromJsonObject(object $item)
Extract content-item details from its JSON representation.
string $id
ID of content-item.
Class to represent a content-item object.
const TYPE_WINDOW
Window placement type.
__construct(string $type, $placementAdvices=null, string $id=null)
Class constructor.
Image $thumbnail
Thumbnail image object for content-item.
static fromJsonItem(object $item)
Generate an Item object from its JSON or JSON-LD representation.
setThumbnail(Image $thumbnail)
Set a thumbnail image for the content-item.
array $placements
Array of placement objects for content-item.
const TYPE_LTI_ASSIGNMENT
Type for LTI assignment content-item.
const TYPE_FILE
Type for file content-item.
const LTI_LINK_MEDIA_TYPE
Media type for LTI launch links.
setMediaType(string $mediaType)
Set a media type value for the content-item.
static fromJsonObject(object $item)
Generate an Image object from its JSON or JSON-LD representation.
static fromJson(object $items)
Generate an array of Item objects from their JSON representation.
const TYPE_IFRAME
iFrame placement type.
const TYPE_EMBED
Embed placement type.
string $title
Title of content-item.
setHideOnCreate(?bool $hideOnCreate)
Set whether the content-item should be hidden from learners by default.