Skip to content

Commit

Permalink
Layout: cannot add a layout if you remove the 1920x1080 resolution (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
dasgarner authored Apr 8, 2024
1 parent d7d7f65 commit 8e5c452
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
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 @@ public function add(Request $request, Response $response)

// 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 @@ -3363,7 +3364,7 @@ public function createFullScreenLayout(Request $request, Response $response): Re
$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

0 comments on commit 8e5c452

Please sign in to comment.