alexdaniels.me/src/Controller/FrontEnd/PhotosController.php

73 lines
2.5 KiB
PHP
Raw Normal View History

2026-06-03 17:18:50 -07:00
<?php
namespace App\Controller\FrontEnd;
use App\Entity\Photos;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Doctrine\ORM\EntityManagerInterface;
final class PhotosController extends AbstractController
{
#[Route('/photos', name: 'front_end_photos_list', priority: 1)]
public function index(EntityManagerInterface $entityManager): Response
{
$photos = $entityManager->getRepository(Photos::class)->findAllOrderByLatest();
$albums = [];
foreach ($photos as $index => $photo) {
$albums[] = [
'title' => $photo->getTitle(),
'date' => $photo->getDate(),
'category' => $photo->getCategory()->getTitle(),
2026-06-08 14:12:08 -07:00
'thumbnail' => 'files/uploads/photos/' . strtolower(str_replace(' ', '_', $photo->getTitle())) . '/' . $photo->getThumbnail(),
2026-06-03 17:18:50 -07:00
'url' => $photo->getUrl(),
];
}
return $this->render('front/photos/index.html.twig', [
'photos' => $albums
]);
}
#[Route('/photos/{url:photos}', name: 'front_end_photos_detail')]
public function detail(Photos $photos): Response
{
$album = [];
$uploads = $photos->getUploads();
$album = [
'title' => $photos->getTitle(),
'category' => $photos->getCategory()->getTitle(),
'urlSafeCategory' => $photos->getCategory()->getUrlSafeTitle(),
2026-06-08 14:12:08 -07:00
'tags' => $photos->getTags(),
2026-06-03 17:18:50 -07:00
'text' => $photos->getText(),
2026-06-08 14:12:08 -07:00
'description' => $photos->getDescription(),
'date' => $photos->getDate(),
'thumbnail' => '/files/uploads/photos/' . strtolower(str_replace(' ', '_', $photos->getTitle())) . '/' . $photos->getThumbnail(),
2026-06-03 17:18:50 -07:00
];
foreach ($uploads as $index => $upload) {
2026-06-08 14:12:08 -07:00
$filePath = 'files/uploads/photos/' . strtolower(str_replace(' ', '_', $album['title'])) . '/' . $upload->getFile();
2026-06-03 17:18:50 -07:00
$album['uploads'][] = [
'file' => $filePath,
'alt' => $upload->getAltText(),
'equipment' => $upload->getEquipment(),
'caption' => $upload->getCaption(),
'location' => $upload->getLocation(),
'date' => $upload->getDate()
];
}
return $this->render('front/photos/detail.html.twig', [
'photos' => $album
]);
}
}