1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Controller; |
4
|
|
|
|
5
|
|
|
use AppBundle\Entity\Poll; |
6
|
|
|
use Pagerfanta\Adapter\ArrayAdapter; |
7
|
|
|
use Pagerfanta\Pagerfanta; |
8
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
12
|
|
|
|
13
|
|
|
class VoteController extends Controller |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @Route("/poll", name="polls_list") |
17
|
|
|
*/ |
18
|
1 |
|
public function listAction(Request $request): Response |
19
|
|
|
{ |
20
|
1 |
|
$pollsManager = $this->get('app.poll_manager'); |
21
|
|
|
|
22
|
1 |
|
$polls = $this->getPolls($request); |
23
|
1 |
|
$current = $pollsManager->getCurrentPolls(); |
24
|
|
|
|
25
|
1 |
|
return $this->render('default/index.html.twig', ['polls' => $polls, 'current' => $current]); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @Route("/poll/{id}", name="poll_view") |
30
|
|
|
*/ |
31
|
|
|
public function viewAction(Request $request, Poll $poll): Response |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$pollsMetadata = $this->get('app.poll_manager'); |
|
|
|
|
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get pagination object of Polls |
38
|
|
|
* |
39
|
|
|
* @param Request $request |
40
|
|
|
* @return Pagerfanta |
41
|
|
|
*/ |
42
|
1 |
|
protected function getPolls(Request $request): Pagerfanta |
43
|
|
|
{ |
44
|
1 |
|
$polls = $this->get('app.poll_manager')->getAllPolls(); |
45
|
1 |
|
$paginator = new Pagerfanta(new ArrayAdapter($polls)); |
46
|
1 |
|
$paginator->setMaxPerPage(20); |
47
|
1 |
|
$paginator->setCurrentPage($request->query->get('page', 1), false, true); |
48
|
|
|
|
49
|
1 |
|
return $paginator; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.