ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ContentItem.php
Go to the documentation of this file.
1<?php
2
4
15{
16
20 const LTI_LINK_MEDIA_TYPE = 'application/vnd.ims.lti.v1.ltilink';
21
29 function __construct($type, $placementAdvice = null, $id = null)
30 {
31
32 $this->{'@type'} = $type;
33 if (is_object($placementAdvice) && (count(get_object_vars($placementAdvice)) > 0)) {
34 $this->placementAdvice = $placementAdvice;
35 }
36 if (!empty($id)) {
37 $this->{'@id'} = $id;
38 }
39
40 }
41
47 public function setUrl($url)
48 {
49
50 if (!empty($url)) {
51 $this->url = $url;
52 } else {
53 unset($this->url);
54 }
55
56 }
57
63 public function setMediaType($mediaType)
64 {
65
66 if (!empty($mediaType)) {
67 $this->mediaType = $mediaType;
68 } else {
69 unset($this->mediaType);
70 }
71
72 }
73
79 public function setTitle($title)
80 {
81
82 if (!empty($title)) {
83 $this->title = $title;
84 } else if (isset($this->title)) {
85 unset($this->title);
86 }
87
88 }
89
95 public function setText($text)
96 {
97
98 if (!empty($text)) {
99 $this->text = $text;
100 } else if (isset($this->text)) {
101 unset($this->text);
102 }
103
104 }
105
112 public static function toJson($items)
113 {
114/*
115 $data = array();
116 if (!is_array($items)) {
117 $data[] = json_encode($items);
118 } else {
119 foreach ($items as $item) {
120 $data[] = json_encode($item);
121 }
122 }
123 $json = '{ "@context" : "http://purl.imsglobal.org/ctx/lti/v1/ContentItem", "@graph" : [' . implode(", ", $data) . '] }';
124*/
125 $obj = new \stdClass();
126 $obj->{'@context'} = 'http://purl.imsglobal.org/ctx/lti/v1/ContentItem';
127 if (!is_array($items)) {
128 $obj->{'@graph'} = array();
129 $obj->{'@graph'}[] = $items;
130 } else {
131 $obj->{'@graph'} = $items;
132 }
133
134 return json_encode($obj);
135
136 }
137
138}
An exception for terminatinating execution or to throw for unit testing.
Class to represent a content-item object.
Definition: ContentItem.php:15
setTitle($title)
Set a title value for the content-item.
Definition: ContentItem.php:79
setText($text)
Set a link text value for the content-item.
Definition: ContentItem.php:95
__construct($type, $placementAdvice=null, $id=null)
Class constructor.
Definition: ContentItem.php:29
static toJson($items)
Wrap the content items to form a complete application/vnd.ims.lti.v1.contentitems+json media type ins...
setMediaType($mediaType)
Set a media type value for the content-item.
Definition: ContentItem.php:63
const LTI_LINK_MEDIA_TYPE
Media type for LTI launch links.
Definition: ContentItem.php:20
setUrl($url)
Set a URL value for the content-item.
Definition: ContentItem.php:47
if(!array_key_exists('StateId', $_REQUEST)) $id
$type
$url
$text
Definition: errorreport.php:18