LTI Integration Library 4.10.3
PHP class library for building LTI integrations
 
Loading...
Searching...
No Matches
Placement.php
1<?php
2
3namespace ceLTIc\LTI\Content;
4
13{
14
18 const TYPE_EMBED = 'embed';
19
23 const TYPE_IFRAME = 'iframe';
24
28 const TYPE_FRAME = 'frame';
29
33 const TYPE_WINDOW = 'window';
34
38 const TYPE_POPUP = 'popup';
39
43 const TYPE_OVERLAY = 'overlay';
44
50 public $documentTarget = null;
51
57 private $windowTarget = null;
58
64 private $windowFeatures = null;
65
71 private $url = null;
72
78 private $displayWidth = null;
79
85 private $displayHeight = null;
86
92 private $html = null;
93
105 function __construct($documentTarget, $displayWidth = null, $displayHeight = null, $windowTarget = null, $windowFeatures = null,
106 $url = null, $html = null)
107 {
108 $this->documentTarget = $documentTarget;
109 $this->displayWidth = $displayWidth;
110 $this->displayHeight = $displayHeight;
111 $this->windowTarget = $windowTarget;
112 $this->windowFeatures = $windowFeatures;
113 $this->url = $url;
114 $this->html = $html;
115 }
116
122 public function toJsonldObject()
123 {
124 if (!empty($this->documentTarget)) {
125 $placement = new \stdClass();
126 $placement->presentationDocumentTarget = $this->documentTarget;
127 if (!is_null($this->displayHeight)) {
128 $placement->displayHeight = $this->displayHeight;
129 }
130 if (!is_null($this->displayWidth)) {
131 $placement->displayWidth = $this->displayWidth;
132 }
133 if (!empty($this->windowTarget)) {
134 $placement->windowTarget = $this->windowTarget;
135 }
136 } else {
137 $placement = null;
138 }
139
140 return $placement;
141 }
142
148 public function toJsonObject()
149 {
150 if (!empty($this->documentTarget)) {
151 $placement = new \stdClass();
152 switch ($this->documentTarget) {
154 if (!empty($this->url)) {
155 $placement->src = $this->url;
156 }
157 if (!is_null($this->displayWidth)) {
158 $placement->width = $this->displayWidth;
159 }
160 if (!is_null($this->displayHeight)) {
161 $placement->height = $this->displayHeight;
162 }
163 break;
165 if (!is_null($this->displayWidth)) {
166 $placement->width = $this->displayWidth;
167 }
168 if (!is_null($this->displayHeight)) {
169 $placement->height = $this->displayHeight;
170 }
171 if (!is_null($this->windowTarget)) {
172 $placement->targetName = $this->windowTarget;
173 }
174 if (!is_null($this->windowFeatures)) {
175 $placement->windowFeatures = $this->windowFeatures;
176 }
177 break;
178 case self::TYPE_EMBED:
179 if (!empty($this->html)) {
180 $placement->html = $this->html;
181 }
182 break;
183 }
184 } else {
185 $placement = null;
186 }
187
188 return $placement;
189 }
190
199 public static function fromJsonObject($item, $documentTarget = null)
200 {
201 $obj = null;
202 $displayWidth = null;
203 $displayHeight = null;
204 $windowTarget = null;
205 $windowFeatures = null;
206 $url = null;
207 $html = null;
208 if (isset($item->{'@type'})) { // Version 1
209 if (empty($documentTarget) && isset($item->placementAdvice)) {
210 if (isset($item->placementAdvice->presentationDocumentTarget)) {
211 $documentTarget = $item->placementAdvice->presentationDocumentTarget;
212 }
213 }
214 if (!empty($documentTarget) && isset($item->placementAdvice)) {
215 if (isset($item->placementAdvice->displayWidth)) {
216 $displayWidth = $item->placementAdvice->displayWidth;
217 }
218 if (isset($item->placementAdvice->displayHeight)) {
219 $displayHeight = $item->placementAdvice->displayHeight;
220 }
221 if (isset($item->placementAdvice->windowTarget)) {
222 $windowTarget = $item->placementAdvice->windowTarget;
223 }
224 }
225 if (isset($item->url)) {
226 $url = $item->url;
227 }
228 } else { // Version 2
229 if (empty($documentTarget)) {
230 if (isset($item->embed)) {
231 $documentTarget = 'embed';
232 } elseif (isset($item->iframe)) {
233 $documentTarget = 'iframe';
234 } elseif (isset($item->window)) {
235 $documentTarget = 'window';
236 }
237 } elseif (!isset($item->{$documentTarget})) {
238 $documentTarget = null;
239 }
240 if (!empty($documentTarget)) {
241 if (isset($item->{$documentTarget}->width)) {
242 $displayWidth = $item->{$documentTarget}->width;
243 }
244 if (isset($item->{$documentTarget}->height)) {
245 $displayHeight = $item->{$documentTarget}->height;
246 }
247 if (isset($item->{$documentTarget}->targetName)) {
248 $windowTarget = $item->{$documentTarget}->targetName;
249 }
250 if (isset($item->{$documentTarget}->windowFeatures)) {
251 $windowFeatures = $item->{$documentTarget}->windowFeatures;
252 }
253 if (isset($item->{$documentTarget}->src)) {
254 $url = $item->{$documentTarget}->src;
255 }
256 if (isset($item->{$documentTarget}->html)) {
257 $html = $item->{$documentTarget}->html;
258 }
259 }
260 }
261 if (!empty($documentTarget)) {
262 $obj = new Placement($documentTarget, $displayWidth, $displayHeight, $windowTarget, $windowFeatures, $url, $html);
263 }
264
265 return $obj;
266 }
267
268}
Class to represent a content-item placement object.
Definition Placement.php:13
$documentTarget
Location to open content in.
Definition Placement.php:50
__construct($documentTarget, $displayWidth=null, $displayHeight=null, $windowTarget=null, $windowFeatures=null, $url=null, $html=null)
Class constructor.
const TYPE_OVERLAY
Overlay placement type.
Definition Placement.php:43
static fromJsonObject($item, $documentTarget=null)
Generate the Placement object from an item.
const TYPE_IFRAME
iFrame placement type.
Definition Placement.php:23
const TYPE_FRAME
Frame placement type.
Definition Placement.php:28
const TYPE_POPUP
Popup placement type.
Definition Placement.php:38
toJsonObject()
Generate the JSON object representation of the placement.
const TYPE_EMBED
Embed placement type.
Definition Placement.php:18
toJsonldObject()
Generate the JSON-LD object representation of the placement.
const TYPE_WINDOW
Window placement type.
Definition Placement.php:33