ManageAssets: add thumbnails to asset table

This commit is contained in:
Aaron van Geffen 2024-08-27 12:00:46 +02:00
parent 01954d4a7d
commit 814a1f82f6
3 changed files with 32 additions and 10 deletions

View File

@ -45,6 +45,34 @@ class ManageAssets extends HTMLController
},
],
],
'thumbnail' => [
'header' => ' ',
'is_sortable' => false,
'cell_class' => 'text-center',
'parse' => [
'type' => 'function',
'data' => function($row) {
$asset = Image::byRow($row);
$width = $height = 65;
if ($asset->isImage())
{
if ($asset->isPortrait())
$width = null;
else
$height = null;
$thumb = $asset->getThumbnailUrl($width, $height);
}
else
$thumb = BASEURL . '/images/nothumb.svg';
$width = isset($width) ? $width . 'px' : 'auto';
$height = isset($height) ? $height . 'px' : 'auto';
return sprintf('<img src="%s" style="width: %s; height: %s;">', $thumb, $width, $height);
},
],
],
'id_asset' => [
'value' => 'id_asset',
'header' => 'ID',
@ -107,7 +135,7 @@ class ManageAssets extends HTMLController
$data = Registry::get('db')->queryAssocs('
SELECT a.id_asset, a.subdir, a.filename,
a.image_width, a.image_height,
a.image_width, a.image_height, a.mimetype,
u.id_user, u.first_name, u.surname
FROM assets AS a
LEFT JOIN users AS u ON a.id_user_uploaded = u.id_user

View File

@ -32,7 +32,7 @@ class Asset
$this->$attribute = $value;
}
if (!empty($data['date_captured']) && $data['date_captured'] !== 'NULL')
if (isset($data['date_captured']) && $data['date_captured'] !== 'NULL' && !is_object($data['date_captured']))
$this->date_captured = new DateTime($data['date_captured']);
}
@ -108,7 +108,7 @@ class Asset
'_' => '_',
]);
return $return_format == 'object' ? new Asset($row) : $row;
return $return_format === 'object' ? new static($row) : $row;
}
public static function fromIds(array $id_assets, $return_format = 'array')
@ -168,7 +168,7 @@ class Asset
foreach ($thumbnails as $thumb)
$assets[$thumb[0]]['thumbnails'][$thumb[1]] = $thumb[2];
if ($return_format == 'array')
if ($return_format === 'array')
return $assets;
else
{

View File

@ -12,12 +12,6 @@ class Image extends Asset
const TYPE_LANDSCAPE = 2;
const TYPE_PORTRAIT = 4;
protected function __construct(array $data)
{
foreach ($data as $attribute => $value)
$this->$attribute = $value;
}
public static function fromId($id_asset, $return_format = 'object')
{
$asset = parent::fromId($id_asset, 'array');