|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Controller\Image; |
|
4
|
|
|
|
|
5
|
|
|
use App\Entity\Image; |
|
6
|
|
|
use App\Repository\ImageRepository; |
|
7
|
|
|
use Knp\Component\Pager\PaginatorInterface; |
|
8
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
11
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @Route("/image", name="image_") |
|
15
|
|
|
*/ |
|
16
|
|
|
class ImageController extends AbstractController |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @Route("/{id}", name="show", methods={"GET"}) |
|
20
|
|
|
*/ |
|
21
|
|
|
public function show(Image $image, ImageRepository $imageRepository): Response |
|
22
|
|
|
{ |
|
23
|
|
|
$prev = $imageRepository->findPrev($image); |
|
24
|
|
|
$next = $imageRepository->findNext($image); |
|
25
|
|
|
return $this->render('image/show.html.twig', [ |
|
26
|
|
|
'image' => $image, |
|
27
|
|
|
'prev' => $prev, |
|
28
|
|
|
'next' => $next |
|
29
|
|
|
]); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @Route("", name="index", methods={"GET"}) |
|
34
|
|
|
*/ |
|
35
|
|
|
public function index( |
|
36
|
|
|
Request $request, |
|
37
|
|
|
ImageRepository $imageRepository, |
|
38
|
|
|
PaginatorInterface $paginator |
|
39
|
|
|
): Response { |
|
40
|
|
|
$qb = $imageRepository->getPaginatorQueryBuilder(); |
|
41
|
|
|
// TODO: Add many interesting parameters, etc. |
|
42
|
|
|
$query = $qb->getQuery(); |
|
43
|
|
|
|
|
44
|
|
|
$pagination = $paginator->paginate( |
|
45
|
|
|
$query, |
|
46
|
|
|
$request->query->getInt('page', 1), |
|
47
|
|
|
20 |
|
48
|
|
|
); |
|
49
|
|
|
|
|
50
|
|
|
return $this->render('image/index.html.twig', [ |
|
51
|
|
|
'image_pagination' => $pagination |
|
52
|
|
|
]); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @Route( |
|
57
|
|
|
* "/rated/{rating}", |
|
58
|
|
|
* name="rated", |
|
59
|
|
|
* methods={"GET"}, |
|
60
|
|
|
* requirements={"rating"="\d+"} |
|
61
|
|
|
* ) |
|
62
|
|
|
*/ |
|
63
|
|
|
public function rated( |
|
64
|
|
|
Request $request, |
|
65
|
|
|
ImageRepository $imageRepository, |
|
66
|
|
|
PaginatorInterface $paginator, |
|
67
|
|
|
int $rating |
|
68
|
|
|
): Response { |
|
69
|
|
|
$qb = $imageRepository->getPaginatorQueryBuilder(); |
|
70
|
|
|
$qb |
|
71
|
|
|
->andWhere('i.rating = :rating') |
|
72
|
|
|
->setParameter('rating', $rating); |
|
73
|
|
|
|
|
74
|
|
|
$query = $qb->getQuery(); |
|
75
|
|
|
|
|
76
|
|
|
$pagination = $paginator->paginate( |
|
77
|
|
|
$query, |
|
78
|
|
|
$request->query->getInt('page', 1), |
|
79
|
|
|
20 |
|
80
|
|
|
); |
|
81
|
|
|
|
|
82
|
|
|
return $this->render('image/index.html.twig', [ |
|
83
|
|
|
'image_pagination' => $pagination |
|
84
|
|
|
]); |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|