PhotoMosaic: keep queue ordered by date captured

This commit is contained in:
Aaron van Geffen 2023-12-19 17:16:57 +01:00
parent 6150922a1f
commit d2fa547257
2 changed files with 27 additions and 3 deletions

View File

@ -8,15 +8,18 @@
class AssetIterator extends Asset
{
private Database $db;
private $direction;
private $return_format;
private $res_assets;
private $res_meta;
private $res_thumbs;
private Database $db;
protected function __construct($res_assets, $res_meta, $res_thumbs, $return_format)
protected function __construct($res_assets, $res_meta, $res_thumbs, $return_format, $direction)
{
$this->db = Registry::get('db');
$this->direction = $direction;
$this->res_assets = $res_assets;
$this->res_meta = $res_meta;
$this->res_thumbs = $res_thumbs;
@ -174,7 +177,7 @@ class AssetIterator extends Asset
'_' => '_',
]);
$iterator = new self($res_assets, $res_meta, $res_thumbs, $return_format);
$iterator = new self($res_assets, $res_meta, $res_thumbs, $return_format, $params['direction']);
// Returning total count, too?
if ($return_count)
@ -190,4 +193,14 @@ class AssetIterator extends Asset
else
return $iterator;
}
public function isAscending()
{
return $this->direction === 'asc';
}
public function isDescending()
{
return $this->direction === 'desc';
}
}

View File

@ -8,6 +8,7 @@
class PhotoMosaic
{
private $descending;
private AssetIterator $iterator;
private $layouts;
private $processedImages = 0;
@ -19,6 +20,7 @@ class PhotoMosaic
{
$this->iterator = $iterator;
$this->layouts = $this->availableLayouts();
$this->descending = $iterator->isDescending();
}
public function __destruct()
@ -143,8 +145,17 @@ class PhotoMosaic
return -$priority_diff;
}
private function orderQueueByDate()
{
usort($this->queue, function($a, $b) {
$score = $a->getDateCaptured() <=> $b->getDateCaptured();
return $score * ($this->descending ? -1 : 1);
});
}
private function pushToQueue(Image $image)
{
$this->queue[] = $image;
$this->orderQueueByDate();
}
}