From 8e0e642d3428ac94a8e77a3c9e7cf2e775e0f6b6 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Wed, 29 Nov 2023 22:47:51 +0100 Subject: [PATCH] PhotoMosaic: reorder methods to be alphabetically ordered --- models/PhotoMosaic.php | 71 +++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/models/PhotoMosaic.php b/models/PhotoMosaic.php index 901e8a0..c3cf9cd 100644 --- a/models/PhotoMosaic.php +++ b/models/PhotoMosaic.php @@ -8,10 +8,9 @@ class PhotoMosaic { - private $queue = []; - const NUM_DAYS_CUTOFF = 7; private AssetIterator $iterator; + private $queue = []; public function __construct(AssetIterator $iterator) { @@ -23,21 +22,9 @@ class PhotoMosaic $this->iterator->clean(); } - public static function getRecentPhotos() + private static function daysApart(Image $a, Image $b) { - return new self(AssetIterator::getByOptions([ - 'tag' => 'photo', - 'order' => 'date_captured', - 'direction' => 'desc', - 'limit' => 15, // worst case: 3 rows * (portrait + 4 thumbs) - ])); - } - - private static function matchTypeMask(Image $image, $type_mask) - { - return ($type_mask & Image::TYPE_PANORAMA) && $image->isPanorama() || - ($type_mask & Image::TYPE_LANDSCAPE) && $image->isLandscape() || - ($type_mask & Image::TYPE_PORTRAIT) && $image->isPortrait(); + return $a->getDateCaptured()->diff($b->getDateCaptured())->days; } private function fetchImage($desired_type = Image::TYPE_PORTRAIT | Image::TYPE_LANDSCAPE | Image::TYPE_PANORAMA, Image $refDateImage = null) @@ -66,25 +53,14 @@ class PhotoMosaic return false; } - private function pushToQueue(Image $image) + public static function getRecentPhotos() { - $this->queue[] = $image; - } - - private static function orderPhotos(Image $a, Image $b) - { - // Show images of highest priority first. - $priority_diff = $a->getPriority() - $b->getPriority(); - if ($priority_diff !== 0) - return -$priority_diff; - - // In other cases, we'll just show the newest first. - return $a->getDateCaptured() <=> $b->getDateCaptured(); - } - - private static function daysApart(Image $a, Image $b) - { - return $a->getDateCaptured()->diff($b->getDateCaptured())->days; + return new self(AssetIterator::getByOptions([ + 'tag' => 'photo', + 'order' => 'date_captured', + 'direction' => 'desc', + 'limit' => 15, // worst case: 3 rows * (portrait + 4 thumbs) + ])); } public function getRow() @@ -102,13 +78,13 @@ class PhotoMosaic // Alright, let's initalise a proper row, then. $photos = [$image]; - $num_portrait = $image->isPortrait() ? 1 : 0; + $num_portrait = $image->isPortrait() ? 1 : 0; $num_landscape = $image->isLandscape() ? 1 : 0; // Get an initial batch of non-panorama images to work with. for ($i = 1; $i < 3 && ($image = $this->fetchImage(Image::TYPE_LANDSCAPE | Image::TYPE_PORTRAIT, $image)); $i++) { - $num_portrait += $image->isPortrait() ? 1 : 0; + $num_portrait += $image->isPortrait() ? 1 : 0; $num_landscape += $image->isLandscape() ? 1 : 0; $photos[] = $image; } @@ -171,4 +147,27 @@ class PhotoMosaic else return [$photos, 'landscapes']; } + + private static function matchTypeMask(Image $image, $type_mask) + { + return ($type_mask & Image::TYPE_PANORAMA) && $image->isPanorama() || + ($type_mask & Image::TYPE_LANDSCAPE) && $image->isLandscape() || + ($type_mask & Image::TYPE_PORTRAIT) && $image->isPortrait(); + } + + private static function orderPhotos(Image $a, Image $b) + { + // Show images of highest priority first. + $priority_diff = $a->getPriority() - $b->getPriority(); + if ($priority_diff !== 0) + return -$priority_diff; + + // In other cases, we'll just show the newest first. + return $a->getDateCaptured() <=> $b->getDateCaptured(); + } + + private function pushToQueue(Image $image) + { + $this->queue[] = $image; + } }