From 7242fdc5e9f868a250a4662ff19f806cf507dd5c Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 7 Dec 2023 16:21:59 +0000 Subject: [PATCH 1/2] Layout import : Fix importing elements with images. xibosignage/xibo#3262 --- lib/Factory/LayoutFactory.php | 49 ++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/lib/Factory/LayoutFactory.php b/lib/Factory/LayoutFactory.php index f83ae1620f..33083b6fe9 100644 --- a/lib/Factory/LayoutFactory.php +++ b/lib/Factory/LayoutFactory.php @@ -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 // @@ -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'])) { @@ -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(); From dd4be450a5aa1bae174f843a2e83f2db1b97f621 Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 7 Dec 2023 16:25:58 +0000 Subject: [PATCH 2/2] Image : use upsize constraint --- lib/Widget/Render/WidgetDownloader.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Widget/Render/WidgetDownloader.php b/lib/Widget/Render/WidgetDownloader.php index 655a7c498d..bfafe8efe0 100644 --- a/lib/Widget/Render/WidgetDownloader.php +++ b/lib/Widget/Render/WidgetDownloader.php @@ -1,8 +1,8 @@ aspectRatio(); } + $constraint->upsize(); }); } }