forked from Public/pics
		
	ManageAssets: add thumbnails to asset table
This commit is contained in:
		
							parent
							
								
									01954d4a7d
								
							
						
					
					
						commit
						814a1f82f6
					
				@ -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' => [
 | 
									'id_asset' => [
 | 
				
			||||||
					'value' => 'id_asset',
 | 
										'value' => 'id_asset',
 | 
				
			||||||
					'header' => 'ID',
 | 
										'header' => 'ID',
 | 
				
			||||||
@ -107,7 +135,7 @@ class ManageAssets extends HTMLController
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
				$data = Registry::get('db')->queryAssocs('
 | 
									$data = Registry::get('db')->queryAssocs('
 | 
				
			||||||
					SELECT a.id_asset, a.subdir, a.filename,
 | 
										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
 | 
											u.id_user, u.first_name, u.surname
 | 
				
			||||||
					FROM assets AS a
 | 
										FROM assets AS a
 | 
				
			||||||
					LEFT JOIN users AS u ON a.id_user_uploaded = u.id_user
 | 
										LEFT JOIN users AS u ON a.id_user_uploaded = u.id_user
 | 
				
			||||||
 | 
				
			|||||||
@ -32,7 +32,7 @@ class Asset
 | 
				
			|||||||
				$this->$attribute = $value;
 | 
									$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']);
 | 
								$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')
 | 
						public static function fromIds(array $id_assets, $return_format = 'array')
 | 
				
			||||||
@ -168,7 +168,7 @@ class Asset
 | 
				
			|||||||
		foreach ($thumbnails as $thumb)
 | 
							foreach ($thumbnails as $thumb)
 | 
				
			||||||
			$assets[$thumb[0]]['thumbnails'][$thumb[1]] = $thumb[2];
 | 
								$assets[$thumb[0]]['thumbnails'][$thumb[1]] = $thumb[2];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if ($return_format == 'array')
 | 
							if ($return_format === 'array')
 | 
				
			||||||
			return $assets;
 | 
								return $assets;
 | 
				
			||||||
		else
 | 
							else
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
 | 
				
			|||||||
@ -12,12 +12,6 @@ class Image extends Asset
 | 
				
			|||||||
	const TYPE_LANDSCAPE = 2;
 | 
						const TYPE_LANDSCAPE = 2;
 | 
				
			||||||
	const TYPE_PORTRAIT = 4;
 | 
						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')
 | 
						public static function fromId($id_asset, $return_format = 'object')
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		$asset = parent::fromId($id_asset, 'array');
 | 
							$asset = parent::fromId($id_asset, 'array');
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user