forked from Public/pics
PhotoMosaic: reorder methods to be alphabetically ordered
This commit is contained in:
parent
aeaff887ca
commit
8e0e642d34
@ -8,10 +8,9 @@
|
|||||||
|
|
||||||
class PhotoMosaic
|
class PhotoMosaic
|
||||||
{
|
{
|
||||||
private $queue = [];
|
|
||||||
|
|
||||||
const NUM_DAYS_CUTOFF = 7;
|
const NUM_DAYS_CUTOFF = 7;
|
||||||
private AssetIterator $iterator;
|
private AssetIterator $iterator;
|
||||||
|
private $queue = [];
|
||||||
|
|
||||||
public function __construct(AssetIterator $iterator)
|
public function __construct(AssetIterator $iterator)
|
||||||
{
|
{
|
||||||
@ -23,21 +22,9 @@ class PhotoMosaic
|
|||||||
$this->iterator->clean();
|
$this->iterator->clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getRecentPhotos()
|
private static function daysApart(Image $a, Image $b)
|
||||||
{
|
{
|
||||||
return new self(AssetIterator::getByOptions([
|
return $a->getDateCaptured()->diff($b->getDateCaptured())->days;
|
||||||
'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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function fetchImage($desired_type = Image::TYPE_PORTRAIT | Image::TYPE_LANDSCAPE | Image::TYPE_PANORAMA, Image $refDateImage = null)
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function pushToQueue(Image $image)
|
public static function getRecentPhotos()
|
||||||
{
|
{
|
||||||
$this->queue[] = $image;
|
return new self(AssetIterator::getByOptions([
|
||||||
}
|
'tag' => 'photo',
|
||||||
|
'order' => 'date_captured',
|
||||||
private static function orderPhotos(Image $a, Image $b)
|
'direction' => 'desc',
|
||||||
{
|
'limit' => 15, // worst case: 3 rows * (portrait + 4 thumbs)
|
||||||
// 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getRow()
|
public function getRow()
|
||||||
@ -102,13 +78,13 @@ class PhotoMosaic
|
|||||||
|
|
||||||
// Alright, let's initalise a proper row, then.
|
// Alright, let's initalise a proper row, then.
|
||||||
$photos = [$image];
|
$photos = [$image];
|
||||||
$num_portrait = $image->isPortrait() ? 1 : 0;
|
$num_portrait = $image->isPortrait() ? 1 : 0;
|
||||||
$num_landscape = $image->isLandscape() ? 1 : 0;
|
$num_landscape = $image->isLandscape() ? 1 : 0;
|
||||||
|
|
||||||
// Get an initial batch of non-panorama images to work with.
|
// 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++)
|
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;
|
$num_landscape += $image->isLandscape() ? 1 : 0;
|
||||||
$photos[] = $image;
|
$photos[] = $image;
|
||||||
}
|
}
|
||||||
@ -171,4 +147,27 @@ class PhotoMosaic
|
|||||||
else
|
else
|
||||||
return [$photos, 'landscapes'];
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user