Skip to content

Commit

Permalink
4.0.6 issues pt4 (xibosignage#2261)
Browse files Browse the repository at this point in the history
* Layout import : Fix importing elements with images. xibosignage/xibo#3262
* Image : use upsize constraint
  • Loading branch information
PeterMis authored Dec 7, 2023
1 parent acd138b commit 92a2cd3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
49 changes: 48 additions & 1 deletion lib/Factory/LayoutFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,14 @@ public function loadByJson($layoutJson, $playlistJson, $nestedPlaylistJson, Fold
$widget->assignMedia($widget->tempId);
}

// if we have any elements with mediaIds, make sure we assign them here
if ($module->type === 'global' && !empty($mediaNode['mediaIds'])) {
foreach ($mediaNode['mediaIds'] as $mediaId) {
$this->getLog()->debug(sprintf('Assigning mediaId %d to element', $mediaId));
$widget->assignMedia($mediaId);
}
}

//
// Audio
//
Expand Down Expand Up @@ -1329,7 +1337,9 @@ public function createFromZip(
null,
$importTags
);
/** @var Layout $layout */
$layout = $jsonResults[0];
/** @var Playlist[] $playlists */
$playlists = $jsonResults[1];

if (array_key_exists('code', $layoutDetails['layoutDefinitions'])) {
Expand Down Expand Up @@ -1619,12 +1629,49 @@ public function createFromZip(
}
$uploadedMediaIds = array_combine($oldMediaIds, $newMediaIds);

foreach ($widgets as $widget) {
// handle importing elements with image.
// if we have multiple images in global widget
// we need to go through them here and replace all old media with new ones
// this cannot be done one by one in the loop when uploading from mapping
// as one widget can have multiple elements with mediaId in it.
if ($widget->type === 'global' && !empty($widget->getOptionValue('elements', []))) {
$widgetElements = $widget->getOptionValue('elements', null);
$widgetElements = json_decode($widgetElements, true);
$updatedWidgetElements = [];
$updatedElements = [];
foreach (($widgetElements ?? []) as $widgetElement) {
foreach (($widgetElement['elements'] ?? []) as $element) {
if (isset($element['mediaId'])) {
foreach ($uploadedMediaIds as $old => $new) {
if ($element['mediaId'] === $old) {
$element['mediaId'] = $new;
}
}
}
// if we have combo of say text element and image
// make sure we have the element updated here (outside the if condition),
// otherwise we would end up only with image elements in the options.
$updatedElements[] = $element;
}
}

if (!empty($updatedElements)) {
$updatedWidgetElements[]['elements'] = $updatedElements;
$widget->setOptionValue(
'elements',
'raw',
json_encode($updatedWidgetElements)
);
}
}
}

// Playlists with media widgets
// We will iterate through all Playlists we've created during layout import here and
// replace any mediaIds if needed
if (isset($playlists) && $playlistDetails !== false) {
foreach ($playlists as $playlist) {
/** @var $playlist Playlist */
foreach ($playlist->widgets as $widget) {
$audioIds = $widget->getAudioIds();

Expand Down
5 changes: 3 additions & 2 deletions lib/Widget/Render/WidgetDownloader.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
/*
* Copyright (C) 2022 Xibo Signage Ltd
* Copyright (C) 2023 Xibo Signage Ltd
*
* Xibo - Digital Signage - http://www.xibo.org.uk
* Xibo - Digital Signage - https://xibosignage.com
*
* This file is part of Xibo.
*
Expand Down Expand Up @@ -251,6 +251,7 @@ public function imagePreview(
if ($proportional) {
$constraint->aspectRatio();
}
$constraint->upsize();
});
}
}
Expand Down

0 comments on commit 92a2cd3

Please sign in to comment.