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

Layout: cannot add a layout if you remove the 1920x1080 resolution #2474

Merged
merged 1 commit into from
Apr 8, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/Controller/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,12 @@

// Empty template so we create a blank layout with the provided resolution
if (empty($resolutionId)) {
// Pick landscape
$resolution = $this->resolutionFactory->getByDimensions(1920, 1080);
$resolutionId = $resolution->resolutionId;
// Get the nearest landscape resolution we can
$resolution = $this->resolutionFactory->getClosestMatchingResolution(1920, 1080);

$this->getLog()->debug('add: no resolution resolved: ' . $resolutionId);
// Get the ID
$resolutionId = $resolution->resolutionId;
$this->getLog()->debug('add: resolution resolved: ' . $resolutionId);
}

$layout = $this->layoutFactory->createFromResolution(
Expand Down Expand Up @@ -1074,8 +1075,8 @@

// Make sure we aren't the global default
if ($layout->layoutId == $this->getConfig()->getSetting('DEFAULT_LAYOUT')) {
throw new InvalidArgumentException(__('This Layout is used as the global default and cannot be retired'),

Check failure on line 1078 in lib/Controller/Layout.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
'layoutId');

Check failure on line 1079 in lib/Controller/Layout.php

View workflow job for this annotation

GitHub Actions / phpcs

Multi-line function call not indented correctly; expected 12 spaces but found 16

Check failure on line 1079 in lib/Controller/Layout.php

View workflow job for this annotation

GitHub Actions / phpcs

Closing parenthesis of a multi-line function call must be on a line by itself
}

$layout->retired = 1;
Expand Down Expand Up @@ -1708,7 +1709,7 @@
'id' => 'layout_button_preview_draft',
'external' => true,
'url' => '#',
'onclick' => 'createMiniLayoutPreview("' . $this->urlFor($request, 'layout.preview', ['id' => $layout->layoutId]) . '?isPreviewDraft=true");',

Check warning on line 1712 in lib/Controller/Layout.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 166 characters
'text' => __('Preview Draft Layout')
);
}
Expand Down Expand Up @@ -3363,7 +3364,7 @@
$media->height
)->resolutionId;
} else if ($type === 'playlist') {
$resolutionId = $this->resolutionFactory->getByDimensions(
$resolutionId = $this->resolutionFactory->getClosestMatchingResolution(
1920,
1080
)->resolutionId;
Expand Down
23 changes: 8 additions & 15 deletions lib/Factory/ResolutionFactory.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (C) 2023 Xibo Signage Ltd
* Copyright (C) 2024 Xibo Signage Ltd
*
* Xibo - Digital Signage - https://xibosignage.com
*
Expand Down Expand Up @@ -98,14 +98,17 @@ public function getByDimensions($width, $height)
* @return Resolution
* @throws NotFoundException
*/
public function getClosestMatchingResolution($width, $height)
public function getClosestMatchingResolution($width, $height): Resolution
{
$area = $width * $height;
$sort = ['ABS(' . $area . ' - (`intended_width` * `intended_height`))'];
$sort[] = $width > $height ? '`intended_width` DESC' : '`intended_height` DESC';

$resolutions = $this->query(
['intended_width'],
$sort,
[
'disableUserCheck' => 1,
'widthGe' => $width,
'heightGe' => $height,
'enabled' => 1,
'start' => 0,
'length' => 1
]
Expand Down Expand Up @@ -203,21 +206,11 @@ public function query($sortOrder = null, $filterBy = [])
$params['width'] = $parsedFilter->getDouble('width');
}

if ($parsedFilter->getDouble('widthGe') !== null) {
$body .= ' AND intended_width >= :widthGe ';
$params['widthGe'] = $parsedFilter->getDouble('widthGe');
}

if ($parsedFilter->getDouble('height') !== null) {
$body .= ' AND intended_height = :height ';
$params['height'] = $parsedFilter->getDouble('height');
}

if ($parsedFilter->getDouble('heightGe') !== null) {
$body .= ' AND intended_height >= :heightGe ';
$params['heightGe'] = $parsedFilter->getDouble('heightGe');
}

if ($parsedFilter->getDouble('designerWidth') !== null) {
$body .= ' AND width = :designerWidth ';
$params['designerWidth'] = $parsedFilter->getDouble('designerWidth');
Expand Down
Loading