|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Controller\Wander; |
|
4
|
|
|
|
|
5
|
|
|
use App\Entity\Wander; |
|
6
|
|
|
use App\Repository\ImageRepository; |
|
7
|
|
|
use App\Repository\WanderRepository; |
|
8
|
|
|
use App\Service\SettingsService; |
|
9
|
|
|
use Knp\Component\Pager\Paginator; |
|
10
|
|
|
use Knp\Component\Pager\PaginatorInterface; |
|
11
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
14
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
15
|
|
|
use Symfony\Component\Routing\RouterInterface; |
|
16
|
|
|
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; |
|
17
|
|
|
|
|
18
|
|
|
class WanderController extends AbstractController |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @Route( |
|
22
|
|
|
* "/wanders.{_format}", |
|
23
|
|
|
* name="wanders_index", |
|
24
|
|
|
* methods={"GET"}, |
|
25
|
|
|
* format="html", |
|
26
|
|
|
* requirements={ |
|
27
|
|
|
* "_format": "html" |
|
28
|
|
|
* }, |
|
29
|
|
|
* condition="'application/json' not in request.getAcceptableContentTypes()" |
|
30
|
|
|
* ) |
|
31
|
|
|
*/ |
|
32
|
|
|
public function index( |
|
33
|
|
|
Request $request, |
|
34
|
|
|
WanderRepository $wanderRepository, |
|
35
|
|
|
PaginatorInterface $paginator |
|
36
|
|
|
): Response |
|
37
|
|
|
{ |
|
38
|
|
|
$qb = $wanderRepository->wandersWithImageCountQueryBuilder(); |
|
39
|
|
|
$query = $qb->getQuery(); |
|
40
|
|
|
$pagination = $paginator->paginate( |
|
41
|
|
|
$query, |
|
42
|
|
|
$request->query->getInt('page', 1), |
|
43
|
|
|
20 // Items per page |
|
44
|
|
|
); |
|
45
|
|
|
|
|
46
|
|
|
return $this->render('wander/index.html.twig', [ |
|
47
|
|
|
'pagination' => $pagination |
|
48
|
|
|
]); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @Route( |
|
53
|
|
|
* "/wanders/{id}", |
|
54
|
|
|
* name="wanders_show", |
|
55
|
|
|
* methods={"GET"}, |
|
56
|
|
|
* condition="'application/json' not in request.getAcceptableContentTypes()" |
|
57
|
|
|
* ) |
|
58
|
|
|
*/ |
|
59
|
|
|
public function show( |
|
60
|
|
|
Request $request, |
|
61
|
|
|
Wander $wander, |
|
62
|
|
|
WanderRepository $wanderRepository, |
|
63
|
|
|
ImageRepository $imageRepository, |
|
64
|
|
|
PaginatorInterface $paginator): Response |
|
65
|
|
|
{ |
|
66
|
|
|
$prev = $wanderRepository->findPrev($wander); |
|
67
|
|
|
$next = $wanderRepository->findNext($wander); |
|
68
|
|
|
|
|
69
|
|
|
$paginatorQuery = $imageRepository->getPaginatorQueryBuilder($wander)->getQuery(); |
|
70
|
|
|
|
|
71
|
|
|
$pagination = $paginator->paginate( |
|
72
|
|
|
$paginatorQuery, |
|
73
|
|
|
$request->query->getInt('page', 1), |
|
74
|
|
|
20, // Per page |
|
75
|
|
|
); |
|
76
|
|
|
|
|
77
|
|
|
return $this->render('wander/show.html.twig', [ |
|
78
|
|
|
'wander' => $wander, |
|
79
|
|
|
'image_pagination' => $pagination, |
|
80
|
|
|
'prev' => $prev, |
|
81
|
|
|
'next' => $next |
|
82
|
|
|
]); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* |
|
87
|
|
|
* RSS, etc. feeds |
|
88
|
|
|
* |
|
89
|
|
|
* @Route( |
|
90
|
|
|
* "/feed.{!_format}", |
|
91
|
|
|
* name="feed", |
|
92
|
|
|
* methods={"GET"}, |
|
93
|
|
|
* format="rss2", |
|
94
|
|
|
* requirements={ |
|
95
|
|
|
* "_format": "rss2|atom" |
|
96
|
|
|
* } |
|
97
|
|
|
* ) |
|
98
|
|
|
*/ |
|
99
|
|
|
public function feed(Request $request, WanderRepository $wanderRepository): Response |
|
100
|
|
|
{ |
|
101
|
|
|
$qb = $wanderRepository |
|
102
|
|
|
->standardQueryBuilder() |
|
103
|
|
|
->setMaxResults(20); |
|
104
|
|
|
|
|
105
|
|
|
$wanders = $qb->getQuery()->getResult(); |
|
106
|
|
|
$format = $request->getRequestFormat(); |
|
107
|
|
|
|
|
108
|
|
|
return $this->render('wander/feed.' . $format . '.twig', [ |
|
109
|
|
|
'wanders' => $wanders |
|
110
|
|
|
]); |
|
111
|
|
|
} |
|
112
|
|
|
} |