Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.0.6 issues pt4 #2261

Merged
merged 2 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 48 additions & 1 deletion lib/Factory/LayoutFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@
*/
public function getByCode($code)
{
$layouts = $this->query(null, ['disableUserCheck' => 1, 'code' => $code, 'excludeTemplates' => -1, 'retired' => -1]);

Check warning on line 540 in lib/Factory/LayoutFactory.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 125 characters

if (count($layouts) <= 0) {
throw new NotFoundException(__('Layout not found'));
Expand Down Expand Up @@ -588,7 +588,7 @@
*/
public function getLinkedFullScreenMediaId(int $campaignId): ?int
{
$mediaId = $this->getStore()->select('SELECT `lkwidgetmedia`.mediaId

Check failure on line 591 in lib/Factory/LayoutFactory.php

View workflow job for this annotation

GitHub Actions / phpcs

Opening parenthesis of a multi-line function call must be the last content on the line
FROM region
INNER JOIN playlist
ON playlist.regionId = region.regionId
Expand Down Expand Up @@ -616,7 +616,7 @@
*/
public function getLinkedFullScreenPlaylistId(int $campaignId): ?int
{
$playlistId = $this->getStore()->select('SELECT `lkplaylistplaylist`.childId

Check failure on line 619 in lib/Factory/LayoutFactory.php

View workflow job for this annotation

GitHub Actions / phpcs

Opening parenthesis of a multi-line function call must be the last content on the line
FROM region
INNER JOIN playlist
ON `playlist`.regionId = `region`.regionId
Expand Down Expand Up @@ -904,7 +904,7 @@
* @throws InvalidArgumentException
* @throws NotFoundException
*/
public function loadByJson($layoutJson, $playlistJson, $nestedPlaylistJson, Folder $folder, $layout = null, $importTags = false): array

Check warning on line 907 in lib/Factory/LayoutFactory.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 139 characters
{
$this->getLog()->debug('Loading Layout by JSON');

Expand Down Expand Up @@ -980,7 +980,7 @@
$this->getLog()->debug('Finished creating nested playlists there are ' . count($playlists) . ' Playlists created');
}

$drawers = (array_key_exists('drawers', $layoutJson['layoutDefinitions'])) ? $layoutJson['layoutDefinitions']['drawers'] : [];

Check warning on line 983 in lib/Factory/LayoutFactory.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 134 characters

// merge Layout Regions and Drawers into one array.
$allRegions = array_merge($layoutJson['layoutDefinitions']['regions'], $drawers);
Expand Down Expand Up @@ -1112,6 +1112,14 @@
$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 @@ -1219,7 +1227,7 @@

$this->getLog()->debug(sprintf('Finished loading layout - there are %d regions.', count($layout->regions)));

$this->getLog()->debug(sprintf('Finished loading layout - there are %d drawer regions.', count($layout->drawers)));

Check warning on line 1230 in lib/Factory/LayoutFactory.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 123 characters

if ($importTags) {
foreach ($layoutJson['layoutDefinitions']['tags'] as $tagNode) {
Expand Down Expand Up @@ -1329,7 +1337,9 @@
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 @@
}
$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 Expand Up @@ -2058,7 +2105,7 @@
$parsedFilter = $this->getSanitizer($filterBy);
$params = [];
$select = 'SELECT DISTINCT code, `campaign`.CampaignID, `campaign`.permissionsFolderId ';
$body = ' FROM layout INNER JOIN `lkcampaignlayout` ON lkcampaignlayout.LayoutID = layout.LayoutID INNER JOIN `campaign` ON lkcampaignlayout.CampaignID = campaign.CampaignID AND campaign.IsLayoutSpecific = 1 WHERE `layout`.code IS NOT NULL AND `layout`.code <> \'\' ';

Check warning on line 2108 in lib/Factory/LayoutFactory.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 276 characters

// get by Code
if ($parsedFilter->getString('code') != '') {
Expand Down Expand Up @@ -2377,7 +2424,7 @@

// get by Code
if ($parsedFilter->getString('code') != '') {
$body.= " AND layout.code = :code ";

Check failure on line 2427 in lib/Factory/LayoutFactory.php

View workflow job for this annotation

GitHub Actions / phpcs

String " AND layout.code = :code " does not require double quotes; use single quotes instead
$params['code'] = $parsedFilter->getString('code');
}

Expand Down Expand Up @@ -2629,12 +2676,12 @@

// if we are importing from layout.json the Widget from/to expiry dates are already timestamps
// for old Layouts when the Widget from/to dt are missing we set them to timestamps as well.
$timestampFromDt = is_integer($widget->fromDt) ? $widget->fromDt : Carbon::createFromTimeString($widget->fromDt)->format('U');

Check warning on line 2679 in lib/Factory/LayoutFactory.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 134 characters
$timestampToDt = is_integer($widget->toDt) ? $widget->toDt : Carbon::createFromTimeString($widget->toDt)->format('U');

Check warning on line 2680 in lib/Factory/LayoutFactory.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 127 characters

// convert the date string to a unix timestamp, if the layout xlf does not contain dates, then set it to the $DATE_MIN / $DATE_MAX which are already unix timestamps, don't attempt to convert them
// we need to check if provided from and to dates are within $DATE_MIN +- year to avoid issues with CMS Instances in different timezones https://github.com/xibosignage/xibo/issues/1934
if ($widget->fromDt === Widget::$DATE_MIN || ($timestampFromDt > $minSubYear && $timestampFromDt < $minAddYear)) {

Check warning on line 2684 in lib/Factory/LayoutFactory.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 122 characters
$widget->fromDt = Widget::$DATE_MIN;
} else {
$widget->fromDt = $timestampFromDt;
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