ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
Placement.php
Go to the documentation of this file.
1 <?php
2 
20 
28 class Placement
29 {
33  public const TYPE_EMBED = 'embed';
34 
38  public const TYPE_IFRAME = 'iframe';
39 
43  public const TYPE_FRAME = 'frame';
44 
48  public const TYPE_WINDOW = 'window';
49 
53  public const TYPE_POPUP = 'popup';
54 
58  public const TYPE_OVERLAY = 'overlay';
59 
65  public ?string $documentTarget = null;
66 
72  private ?string $windowTarget = null;
73 
79  private ?string $windowFeatures = null;
80 
86  private ?string $url = null;
87 
93  private ?int $displayWidth = null;
94 
100  private ?int $displayHeight = null;
101 
107  private ?string $html = null;
108 
119  public function __construct(
120  string $documentTarget,
121  ?int $displayWidth = null,
122  ?int $displayHeight = null,
123  ?string $windowTarget = null,
124  ?string $windowFeatures = null,
125  string $url = null,
126  ?string $html = null
127  ) {
128  $this->documentTarget = $documentTarget;
129  $this->displayWidth = $displayWidth;
130  $this->displayHeight = $displayHeight;
131  $this->windowTarget = $windowTarget;
132  $this->windowFeatures = $windowFeatures;
133  $this->url = $url;
134  $this->html = $html;
135  }
136 
142  public function toJsonldObject(): object
143  {
144  if (!empty($this->documentTarget)) {
145  $placement = new \stdClass();
146  $placement->presentationDocumentTarget = $this->documentTarget;
147  if (!is_null($this->displayHeight)) {
148  $placement->displayHeight = $this->displayHeight;
149  }
150  if (!is_null($this->displayWidth)) {
151  $placement->displayWidth = $this->displayWidth;
152  }
153  if (!empty($this->windowTarget)) {
154  $placement->windowTarget = $this->windowTarget;
155  }
156  } else {
157  $placement = null;
158  }
159 
160  return $placement;
161  }
162 
168  public function toJsonObject(): object
169  {
170  if (!empty($this->documentTarget)) {
171  $placement = new \stdClass();
172  switch ($this->documentTarget) {
173  case self::TYPE_IFRAME:
174  if (!empty($this->url)) {
175  $placement->src = $this->url;
176  }
177  if (!is_null($this->displayWidth)) {
178  $placement->width = $this->displayWidth;
179  }
180  if (!is_null($this->displayHeight)) {
181  $placement->height = $this->displayHeight;
182  }
183  break;
184  case self::TYPE_WINDOW:
185  if (!is_null($this->displayWidth)) {
186  $placement->width = $this->displayWidth;
187  }
188  if (!is_null($this->displayHeight)) {
189  $placement->height = $this->displayHeight;
190  }
191  if (!is_null($this->windowTarget)) {
192  $placement->targetName = $this->windowTarget;
193  }
194  if (!is_null($this->windowFeatures)) {
195  $placement->windowFeatures = $this->windowFeatures;
196  }
197  break;
198  case self::TYPE_EMBED:
199  if (!empty($this->html)) {
200  $placement->html = $this->html;
201  }
202  break;
203  }
204  } else {
205  $placement = null;
206  }
207 
208  return $placement;
209  }
210 
217  public static function fromJsonObject(object $item, string $documentTarget = null): ?Placement
218  {
219  $obj = null;
220  $displayWidth = null;
221  $displayHeight = null;
222  $windowTarget = null;
223  $windowFeatures = null;
224  $url = null;
225  $html = null;
226  if (isset($item->{'@type'})) { // Version 1
227  if (empty($documentTarget) && isset($item->placementAdvice)) {
228  if (isset($item->placementAdvice->presentationDocumentTarget)) {
229  $documentTarget = $item->placementAdvice->presentationDocumentTarget;
230  }
231  }
232  if (!empty($documentTarget) && isset($item->placementAdvice)) {
233  if (isset($item->placementAdvice->displayWidth)) {
234  $displayWidth = $item->placementAdvice->displayWidth;
235  }
236  if (isset($item->placementAdvice->displayHeight)) {
237  $displayHeight = $item->placementAdvice->displayHeight;
238  }
239  if (isset($item->placementAdvice->windowTarget)) {
240  $windowTarget = $item->placementAdvice->windowTarget;
241  }
242  }
243  if (isset($item->url)) {
244  $url = $item->url;
245  }
246  } else { // Version 2
247  if (empty($documentTarget)) {
248  if (isset($item->embed)) {
249  $documentTarget = 'embed';
250  } elseif (isset($item->iframe)) {
251  $documentTarget = 'iframe';
252  } elseif (isset($item->window)) {
253  $documentTarget = 'window';
254  }
255  } elseif (!isset($item->{$documentTarget})) {
256  $documentTarget = null;
257  }
258  if (!empty($documentTarget)) {
259  if (isset($item->{$documentTarget}->width)) {
260  $displayWidth = $item->{$documentTarget}->width;
261  }
262  if (isset($item->{$documentTarget}->height)) {
263  $displayHeight = $item->{$documentTarget}->height;
264  }
265  if (isset($item->{$documentTarget}->targetName)) {
266  $windowTarget = $item->{$documentTarget}->targetName;
267  }
268  if (isset($item->{$documentTarget}->windowFeatures)) {
269  $windowFeatures = $item->{$documentTarget}->windowFeatures;
270  }
271  if (isset($item->{$documentTarget}->src)) {
272  $url = $item->{$documentTarget}->src;
273  }
274  if (isset($item->{$documentTarget}->html)) {
275  $html = $item->{$documentTarget}->html;
276  }
277  }
278  }
279  if (!empty($documentTarget)) {
280  $obj = new Placement($documentTarget, $displayWidth, $displayHeight, $windowTarget, $windowFeatures, $url, $html);
281  }
282 
283  return $obj;
284  }
285 }
string $url
URL of iframe src.
Definition: Placement.php:86
static fromJsonObject(object $item, string $documentTarget=null)
Generate the Placement object from an item.
Definition: Placement.php:217
const TYPE_FRAME
Frame placement type.
Definition: Placement.php:43
Class to represent a content-item placement object.
Definition: Placement.php:28
int $displayHeight
Height of item location.
Definition: Placement.php:100
__construct(string $documentTarget, ?int $displayWidth=null, ?int $displayHeight=null, ?string $windowTarget=null, ?string $windowFeatures=null, string $url=null, ?string $html=null)
Class constructor.
Definition: Placement.php:119
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: FileItem.php:19
string $html
HTML to be embedded.
Definition: Placement.php:107
toJsonObject()
Generate the JSON object representation of the placement.
Definition: Placement.php:168
toJsonldObject()
Generate the JSON-LD object representation of the placement.
Definition: Placement.php:142
const TYPE_OVERLAY
Overlay placement type.
Definition: Placement.php:58
const TYPE_WINDOW
Window placement type.
Definition: Placement.php:48
string $documentTarget
Location to open content in.
Definition: Placement.php:65
string $windowTarget
Name of window target.
Definition: Placement.php:72
string $windowFeatures
Comma-separated list of window features.
Definition: Placement.php:79
const TYPE_IFRAME
iFrame placement type.
Definition: Placement.php:38
const TYPE_EMBED
Embed placement type.
Definition: Placement.php:33
const TYPE_POPUP
Popup placement type.
Definition: Placement.php:53
int $displayWidth
Width of item location.
Definition: Placement.php:93