LTI Integration Library 4.10.3
PHP class library for building LTI integrations
 
Loading...
Searching...
No Matches
Image.php
1<?php
2
3namespace ceLTIc\LTI\Content;
4
12class Image
13{
14
20 private $url = null;
21
27 private $width = null;
28
34 private $height = null;
35
43 function __construct($url, $width = null, $height = null)
44 {
45 $this->url = $url;
46 $this->height = $height;
47 $this->width = $width;
48 }
49
55 public function toJsonldObject()
56 {
57 $image = new \stdClass();
58 $image->{'@id'} = $this->url;
59 if (!is_null($this->width)) {
60 $image->width = $this->width;
61 }
62 if (!is_null($this->height)) {
63 $image->height = $this->height;
64 }
65
66 return $image;
67 }
68
74 public function toJsonObject()
75 {
76 $image = new \stdClass();
77 $image->url = $this->url;
78 if (!is_null($this->width)) {
79 $image->width = $this->width;
80 }
81 if (!is_null($this->height)) {
82 $image->height = $this->height;
83 }
84
85 return $image;
86 }
87
95 public static function fromJsonObject($item)
96 {
97 $obj = null;
98 $width = null;
99 $height = null;
100 if (is_object($item)) {
101 $url = null;
102 foreach (get_object_vars($item) as $name => $value) {
103 switch ($name) {
104 case '@id':
105 case 'url':
106 $url = $item->{$name};
107 break;
108 case 'width':
109 $width = $item->width;
110 break;
111 case 'height':
112 $height = $item->height;
113 break;
114 }
115 }
116 } else {
117 $url = $item;
118 }
119 if ($url) {
120 $obj = new Image($url, $height, $width);
121 }
122
123 return $obj;
124 }
125
126}
Class to represent a content-item image object.
Definition Image.php:13
static fromJsonObject($item)
Generate an Image object from its JSON or JSON-LD representation.
Definition Image.php:95
toJsonObject()
Generate the JSON object representation of the image.
Definition Image.php:74
__construct($url, $width=null, $height=null)
Class constructor.
Definition Image.php:43
toJsonldObject()
Generate the JSON-LD object representation of the image.
Definition Image.php:55