Backport asynchronous thumbnail generation from Kabuki.
This commit is contained in:
@@ -18,8 +18,10 @@ class Asset
|
||||
protected $image_height;
|
||||
protected $date_captured;
|
||||
protected $priority;
|
||||
|
||||
protected $meta;
|
||||
protected $tags;
|
||||
protected $thumbnails;
|
||||
|
||||
protected function __construct(array $data)
|
||||
{
|
||||
@@ -58,8 +60,10 @@ class Asset
|
||||
|
||||
public static function byRow(array $row, $return_format = 'object')
|
||||
{
|
||||
$db = Registry::get('db');
|
||||
|
||||
// Supplement with metadata.
|
||||
$row['meta'] = Registry::get('db')->queryPair('
|
||||
$row['meta'] = $db->queryPair('
|
||||
SELECT variable, value
|
||||
FROM assets_meta
|
||||
WHERE id_asset = {int:id_asset}',
|
||||
@@ -67,6 +71,24 @@ class Asset
|
||||
'id_asset' => $row['id_asset'],
|
||||
]);
|
||||
|
||||
// And thumbnails.
|
||||
$row['thumbnails'] = $db->queryPair('
|
||||
SELECT
|
||||
CONCAT(
|
||||
width,
|
||||
{string:x},
|
||||
height,
|
||||
IF(mode != {string:empty}, CONCAT({string:_}, mode), {string:empty})
|
||||
) AS selector, filename
|
||||
FROM assets_thumbs
|
||||
WHERE id_asset = {int:id_asset}',
|
||||
[
|
||||
'id_asset' => $row['id_asset'],
|
||||
'empty' => '',
|
||||
'x' => 'x',
|
||||
'_' => '_',
|
||||
]);
|
||||
|
||||
return $return_format == 'object' ? new Asset($row) : $row;
|
||||
}
|
||||
|
||||
@@ -91,6 +113,7 @@ class Asset
|
||||
{
|
||||
$assets[$asset['id_asset']] = $asset;
|
||||
$assets[$asset['id_asset']]['meta'] = [];
|
||||
$assets[$asset['id_asset']]['thumbnails'] = [];
|
||||
}
|
||||
|
||||
$metas = $db->queryRows('
|
||||
@@ -105,6 +128,27 @@ class Asset
|
||||
foreach ($metas as $meta)
|
||||
$assets[$meta[0]]['meta'][$meta[1]] = $meta[2];
|
||||
|
||||
$thumbnails = $db->queryRows('
|
||||
SELECT id_asset,
|
||||
CONCAT(
|
||||
width,
|
||||
{string:x},
|
||||
height,
|
||||
IF(mode != {string:empty}, CONCAT({string:_}, mode), {string:empty})
|
||||
) AS selector, filename
|
||||
FROM assets_thumbs
|
||||
WHERE id_asset IN ({array_int:id_assets})
|
||||
ORDER BY id_asset',
|
||||
[
|
||||
'id_assets' => $id_assets,
|
||||
'empty' => '',
|
||||
'x' => 'x',
|
||||
'_' => '_',
|
||||
]);
|
||||
|
||||
foreach ($thumbnails as $thumb)
|
||||
$assets[$thumb[0]]['thumbnails'][$thumb[1]] = $thumb[2];
|
||||
|
||||
if ($return_format == 'array')
|
||||
return $assets;
|
||||
else
|
||||
@@ -270,7 +314,7 @@ class Asset
|
||||
return ASSETSDIR . '/' . $this->subdir . '/' . $this->filename;
|
||||
}
|
||||
|
||||
public function getPath()
|
||||
public function getSubdir()
|
||||
{
|
||||
return $this->subdir;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user