diff --git a/controllers/ManageAssets.php b/controllers/ManageAssets.php index 2c2bfdc..5ae3597 100644 --- a/controllers/ManageAssets.php +++ b/controllers/ManageAssets.php @@ -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('', $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 diff --git a/models/Asset.php b/models/Asset.php index eaabbd0..edadd5f 100644 --- a/models/Asset.php +++ b/models/Asset.php @@ -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 { diff --git a/models/Image.php b/models/Image.php index 0172a9c..9348467 100644 --- a/models/Image.php +++ b/models/Image.php @@ -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');