Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| PortfolioController | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| portfolio | |
100.00% |
19 / 19 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Controller\Front; |
| 4 | |
| 5 | use App\Repository\AlbumRepository; |
| 6 | use App\Repository\MediaRepository; |
| 7 | use App\Repository\UserRepository; |
| 8 | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
| 9 | use Symfony\Component\HttpFoundation\Request; |
| 10 | use Symfony\Component\HttpFoundation\Response; |
| 11 | use Symfony\Component\Routing\Attribute\Route; |
| 12 | |
| 13 | class PortfolioController extends AbstractController |
| 14 | { |
| 15 | public function __construct( |
| 16 | private AlbumRepository $albumRepository, |
| 17 | private MediaRepository $mediaRepository, |
| 18 | private UserRepository $userRepository, |
| 19 | ) {} |
| 20 | |
| 21 | #[Route("/portfolio/{id<\d+>?}", name: "portfolio")] |
| 22 | public function portfolio(Request $request, ?int $id = null): Response |
| 23 | { |
| 24 | $albums = $this->albumRepository->findAll(); |
| 25 | $album = $id ? $this->albumRepository->find($id) : null; |
| 26 | |
| 27 | if ($id && !$album) { |
| 28 | return $this->redirectToRoute('portfolio'); |
| 29 | } |
| 30 | |
| 31 | $page = $request->query->getInt('page', 1); |
| 32 | |
| 33 | $criteria = ['super_admin' => true]; |
| 34 | |
| 35 | $user = $this->userRepository->findOneBy($criteria); |
| 36 | |
| 37 | if ($album) { |
| 38 | $medias = $this->mediaRepository->findBy(['album' => $album], ['id' => 'ASC'], 6, 6 * ($page - 1)); |
| 39 | $total = $this->mediaRepository->count(['album' => $album]); |
| 40 | } else { |
| 41 | $medias = $this->mediaRepository->findBy(['user' => $user], ['id' => 'ASC'], 6, 6 * ($page - 1)); |
| 42 | $total = $this->mediaRepository->count(['user' => $user]); |
| 43 | } |
| 44 | |
| 45 | return $this->render('front/portfolio.html.twig', [ |
| 46 | 'albums' => $albums, |
| 47 | 'album' => $album, |
| 48 | 'medias' => $medias, |
| 49 | 'total' => $total, |
| 50 | 'page' => $page, |
| 51 | ]); |
| 52 | } |
| 53 | } |