AlbumIndex: rewrite to use Bootstrap grid for tiles

This commit is contained in:
2023-04-01 14:02:58 +02:00
parent a260f4ff88
commit b05015e76e
2 changed files with 70 additions and 52 deletions

View File

@@ -15,6 +15,7 @@ class AlbumIndex extends Template
const TILE_WIDTH = 400;
const TILE_HEIGHT = 300;
const TILE_RATIO = self::TILE_WIDTH / self::TILE_HEIGHT;
public function __construct(array $albums, $show_edit_buttons = false, $show_labels = true)
{
@@ -26,57 +27,56 @@ class AlbumIndex extends Template
public function html_main()
{
echo '
<div class="tiled_grid clearfix">';
<div class="container album-index">
<div class="row g-5">';
foreach (array_chunk($this->albums, 3) as $photos)
{
echo '
<div class="tiled_row">';
foreach ($photos as $album)
{
echo '
<div class="landscape">';
if ($this->show_edit_buttons)
echo '
<a class="edit" href="#">Edit</a>';
echo '
<a href="', $album['link'], '">';
if (isset($album['thumbnail']))
{
$thumbs = [];
foreach ([1, 2] as $factor)
$thumbs[$factor] = $album['thumbnail']->getThumbnailUrl(
static::TILE_WIDTH * $factor, static::TILE_HEIGHT * $factor, true, true);
echo '
<img src="', $thumbs[1], '"' . (isset($thumbs[2]) ?
' srcset="' . $thumbs[2] . ' 2x"' : '') .
' alt="" style="width: ', static::TILE_WIDTH,
'px; height: ', static::TILE_HEIGHT, 'px">';
}
else
echo '
<img src="', BASEURL, '/images/nothumb.svg" alt="" style="width: ',
static::TILE_WIDTH, 'px; height: ', static::TILE_HEIGHT, 'px; object-fit: unset">';
if ($this->show_labels)
echo '
<h4>', $album['caption'], '</h4>';
echo '
</a>
</div>';
}
echo '
</div>';
}
foreach ($this->albums as $album)
$this->renderAlbum($album);
echo '
</div>
</div>';
}
private function renderAlbum(array $album)
{
echo '
<div class="col-md-6 col-xl-4">
<div class="polaroid landscape">';
if ($this->show_edit_buttons)
echo '
<a class="edit" href="#">Edit</a>';
echo '
<a href="', $album['link'], '">';
if (isset($album['thumbnail']))
{
$thumbs = [];
foreach ([1, 2] as $factor)
$thumbs[$factor] = $album['thumbnail']->getThumbnailUrl(
static::TILE_WIDTH * $factor, static::TILE_HEIGHT * $factor, true, true);
echo '
<img alt="" src="', $thumbs[1], '"' . (isset($thumbs[2]) ?
' srcset="' . $thumbs[2] . ' 2x"' : '') .
' alt="" style="aspect-ratio: ', self::TILE_RATIO, '">';
}
else
{
echo '
<img alt="" src="', BASEURL, '/images/nothumb.svg"',
' style="aspect-ratio: ', self::TILE_RATIO, '; object-fit: unset">';
}
if ($this->show_labels)
echo '
<h4>', $album['caption'], '</h4>';
echo '
</a>
</div>
</div>';
}
}