LTI Integration Library  3.1.0
PHP class library for building LTI integrations
ContentItem.php
Go to the documentation of this file.
1 <?php
2 
3 namespace ceLTIc\LTI;
4 
14 {
15 
19  const LTI_LINK_MEDIA_TYPE = 'application/vnd.ims.lti.v1.ltilink';
20 
28  function __construct($type, $placementAdvice = null, $id = null)
29  {
30  $this->{'@type'} = $type;
31  if (is_object($placementAdvice) && (count(get_object_vars($placementAdvice)) > 0)) {
32  $this->placementAdvice = $placementAdvice;
33  }
34  if (!empty($id)) {
35  $this->{'@id'} = $id;
36  }
37  }
38 
44  public function setUrl($url)
45  {
46  if (!empty($url)) {
47  $this->url = $url;
48  } else {
49  unset($this->url);
50  }
51  }
52 
58  public function setMediaType($mediaType)
59  {
60  if (!empty($mediaType)) {
61  $this->mediaType = $mediaType;
62  } else {
63  unset($this->mediaType);
64  }
65  }
66 
72  public function setTitle($title)
73  {
74  if (!empty($title)) {
75  $this->title = $title;
76  } elseif (isset($this->title)) {
77  unset($this->title);
78  }
79  }
80 
86  public function setText($text)
87  {
88  if (!empty($text)) {
89  $this->text = $text;
90  } elseif (isset($this->text)) {
91  unset($this->text);
92  }
93  }
94 
102  public static function toJson($items)
103  {
104  $obj = new \stdClass();
105  $obj->{'@context'} = 'http://purl.imsglobal.org/ctx/lti/v1/ContentItem';
106  if (!is_array($items)) {
107  $obj->{'@graph'} = array();
108  $obj->{'@graph'}[] = $items;
109  } else {
110  $obj->{'@graph'} = $items;
111  }
112 
113  return json_encode($obj);
114  }
115 
116 }
static toJson($items)
Wrap the content items to form a complete application/vnd.ims.lti.v1.contentitems+json media type ins...
setTitle($title)
Set a title value for the content-item.
Definition: ContentItem.php:72
__construct($type, $placementAdvice=null, $id=null)
Class constructor.
Definition: ContentItem.php:28
setUrl($url)
Set a URL value for the content-item.
Definition: ContentItem.php:44
setText($text)
Set a link text value for the content-item.
Definition: ContentItem.php:86
const LTI_LINK_MEDIA_TYPE
Media type for LTI launch links.
Definition: ContentItem.php:19
setMediaType($mediaType)
Set a media type value for the content-item.
Definition: ContentItem.php:58
Class to represent a content-item object.
Definition: ContentItem.php:13