86 public ?
string $id =
null;
161 if (!empty($placementAdvices)) {
162 if (!is_array($placementAdvices)) {
163 $placementAdvices = array($placementAdvices);
165 foreach ($placementAdvices as $placementAdvice) {
166 $this->placements[$placementAdvice->documentTarget] = $placementAdvice;
223 if (!empty($placementAdvice)) {
224 $this->placements[$placementAdvice->documentTarget] = $placementAdvice;
263 if (!is_array($items)) {
264 $items = array($items);
267 $obj = new \stdClass();
268 $obj->{
'@context'} =
'http://purl.imsglobal.org/ctx/lti/v1/ContentItem';
269 $obj->{
'@graph'} = array();
270 foreach ($items as $item) {
271 $obj->{
'@graph'}[] = $item->toJsonldObject();
275 foreach ($items as $item) {
276 $obj[] = $item->toJsonObject();
280 return json_encode($obj);
288 public static function fromJson(
object $items): array
290 $isJsonLd = isset($items->{
'@graph'});
292 $items = $items->{
'@graph'};
294 if (!is_array($items)) {
295 $items = array($items);
298 foreach ($items as $item) {
299 $obj = self::fromJsonItem($item);
315 $item = new \stdClass();
316 if (!empty($this->
id)) {
319 if (!empty($this->type)) {
320 if (($this->type === self::TYPE_LTI_LINK) || ($this->type === self::TYPE_LTI_ASSIGNMENT)) {
321 $item->{
'@type'} =
'LtiLinkItem';
322 } elseif ($this->type === self::TYPE_FILE) {
323 $item->{
'@type'} =
'FileItem';
325 $item->{
'@type'} =
'ContentItem';
328 $item->{
'@type'} =
'ContentItem';
330 if (!empty($this->title)) {
331 $item->title = $this->title;
333 if (!empty($this->text)) {
334 $item->text = $this->text;
335 } elseif (!empty($this->
html)) {
336 $item->text = $this->html;
338 if (!empty($this->url)) {
341 if (!empty($this->mediaType)) {
342 $item->mediaType = $this->mediaType;
344 if (!empty($this->placements)) {
345 $placementAdvice = new \stdClass();
346 $placementAdvices = array();
347 foreach ($this->placements as $placement) {
348 $obj = $placement->toJsonldObject();
350 if (!empty($placement->documentTarget)) {
351 $placementAdvices[] = $placement->documentTarget;
353 $placementAdvice = (
object) array_merge((array) $placementAdvice, (array) $obj);
356 if (!empty($placementAdvice)) {
357 $item->placementAdvice = $placementAdvice;
358 if (!empty($placementAdvices)) {
359 $item->placementAdvice->presentationDocumentTarget = implode(
',', $placementAdvices);
363 if (!empty($this->icon)) {
364 $item->icon = $this->icon->toJsonldObject();
366 if (!empty($this->thumbnail)) {
367 $item->thumbnail = $this->thumbnail->toJsonldObject();
369 if (!is_null($this->hideOnCreate)) {
370 $item->hideOnCreate = $this->hideOnCreate;
383 $item = new \stdClass();
384 switch ($this->type) {
386 $item->type = self::TYPE_LTI_LINK;
389 $item->type = self::TYPE_FILE;
392 if (empty($this->url)) {
393 $item->type = self::TYPE_HTML;
394 } elseif (!empty($this->mediaType) && (strpos($this->mediaType,
'image') === 0)) {
395 $item->type = self::TYPE_IMAGE;
397 $item->type = self::TYPE_LINK;
404 if (!empty($this->title)) {
405 $item->title = $this->title;
407 if (!empty($this->text)) {
408 $item->text = Util::stripHtml($this->text);
410 if (!empty($this->
html)) {
411 $item->html = $this->html;
413 if (!empty($this->url)) {
416 foreach ($this->placements as
$type => $placement) {
418 case Placement::TYPE_EMBED:
419 case Placement::TYPE_IFRAME:
420 case Placement::TYPE_WINDOW:
421 case Placement::TYPE_FRAME:
422 $obj = $placement->toJsonObject();
429 $item->{
$type} = $obj;
432 if (!empty($this->icon)) {
433 $item->icon = $this->icon->toJsonObject();
435 if (!empty($this->thumbnail)) {
436 $item->thumbnail = $this->thumbnail->toJsonObject();
438 if (!is_null($this->hideOnCreate)) {
439 $item->hideOnCreate = $this->hideOnCreate;
454 if (isset($item->{
'@type'})) {
455 if (isset($item->presentationDocumentTarget)) {
456 $placement = Placement::fromJsonObject($item, $item->presentationDocumentTarget);
458 switch ($item->{
'@type'}) {
460 $obj =
new Item(
'ContentItem', $placement);
463 $obj =
new LtiLinkItem($placement);
466 $obj =
new FileItem($placement);
469 } elseif (isset($item->type)) {
470 $placements = array();
471 $placement = Placement::fromJsonObject($item,
'embed');
472 if (!empty($placement)) {
473 $placements[] = $placement;
475 $placement = Placement::fromJsonObject($item,
'iframe');
476 if (!empty($placement)) {
477 $placements[] = $placement;
479 $placement = Placement::fromJsonObject($item,
'window');
480 if (!empty($placement)) {
481 $placements[] = $placement;
483 switch ($item->type) {
484 case self::TYPE_LINK:
485 case self::TYPE_HTML:
486 case self::TYPE_IMAGE:
487 $obj =
new Item($item->type, $placements);
489 case self::TYPE_LTI_LINK:
490 $obj =
new LtiLinkItem($placements);
492 case self::TYPE_LTI_ASSIGNMENT:
493 $obj =
new LtiAssignmentItem($placements);
495 case self::TYPE_FILE:
496 $obj =
new FileItem($placements);
501 $obj->fromJsonObject($item);
513 if (isset($item->{
'@id'})) {
514 $this->
id = $item->{
'@id'};
516 foreach (get_object_vars($item) as
$name => $value) {
526 case 'placementAdvice':
527 $this->addPlacementAdvice(Placement::fromJsonObject($item));
532 $this->addPlacementAdvice(Placement::fromJsonObject($item,
$name));
536 $this->{
$name} = Image::fromJsonObject($item->{
$name});
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Class to represent a content-item image object.
Class to represent a content-item object.
Image $icon
Icon image object for content-item.
setHtml(string $html)
Set an HTML embed value for the content-item.
setIcon(Image $icon)
Set an icon image for the content-item.
const TYPE_IMAGE
Type for image content-item.
string $type
Type of content-item.
string $mediaType
Media type of content-item.
setTitle(string $title)
Set a title value for the content-item.
setThumbnail(Image $thumbnail)
Set a thumbnail image for the content-item.
array $placements
Array of placement objects for content-item.
const TYPE_FILE
Type for file content-item.
string $title
Title of content-item.
setMediaType(string $mediaType)
Set a media type value for the content-item.
const TYPE_LINK
Type for link content-item.
__construct(string $type, $placementAdvices=null, string $id=null)
Class constructor.
setText(string $text)
Set a link text value for the content-item.
static toJson($items, string $ltiVersion=Util::LTI_VERSION1)
Wrap the content items to form a complete application/vnd.ims.lti.v1.contentitems+json media type ins...
toJsonldObject()
Wrap the content item to form an item complying with the application/vnd.ims.lti.v1....
fromJsonObject(object $item)
Extract content-item details from its JSON representation.
const TYPE_LTI_LINK
Type for LTI link content-item.
setHideOnCreate(?bool $hideOnCreate)
Set whether the content-item should be hidden from learners by default.
static fromJsonItem(object $item)
Generate an Item object from its JSON or JSON-LD representation.
string $html
HTML to be embedded.
string $id
ID of content-item.
bool $hideOnCreate
Hide the item from learners by default?
const TYPE_LTI_ASSIGNMENT
Type for LTI assignment content-item.
const LTI_LINK_MEDIA_TYPE
Media type for LTI launch links.
string $url
URL of content-item.
string $text
Description of content-item.
Image $thumbnail
Thumbnail image object for content-item.
static fromJson(object $items)
Generate an array of Item objects from their JSON representation.
const TYPE_HTML
Type for HTML content-item.
const LTI_ASSIGNMENT_MEDIA_TYPE
Media type for LTI assignment links.
toJsonObject()
Wrap the content items to form a complete value for the https://purl.imsglobal.org/spec/lti-dl/claim/...
addPlacementAdvice(Placement $placementAdvice)
Add a placement for the content-item.
setUrl(string $url)
Set a URL value for the content-item.
Class to represent a content-item placement object.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...