|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace AppBundle\Controller; |
|
4
|
|
|
|
|
5
|
|
|
use Pagerfanta\Adapter\ArrayAdapter; |
|
6
|
|
|
use Pagerfanta\Adapter\DoctrineORMAdapter; |
|
7
|
|
|
use Pagerfanta\Pagerfanta; |
|
8
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
|
9
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
10
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; |
|
11
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
|
12
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
13
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
14
|
|
|
use AppBundle\Entity\Poll; |
|
15
|
|
|
|
|
16
|
|
|
class VoteController extends Controller |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @Route("/poll", name="polls_list") |
|
20
|
|
|
*/ |
|
21
|
1 |
|
public function listAction(Request $request): Response |
|
22
|
|
|
{ |
|
23
|
1 |
|
$polls = $this->getPolls($request); |
|
24
|
1 |
|
$current = $this->getCurrentPolls(); |
|
25
|
|
|
|
|
26
|
1 |
|
return $this->render('default/index.html.twig', ['polls' => $polls, 'current' => $current]); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Get an array of current polls (objects) |
|
31
|
|
|
* |
|
32
|
|
|
* @return array |
|
33
|
|
|
*/ |
|
34
|
1 |
|
protected function getCurrentPolls(): array |
|
35
|
|
|
{ |
|
36
|
1 |
|
$currentPolls = $this->getDoctrine() |
|
|
|
|
|
|
37
|
1 |
|
->getRepository('AppBundle:Poll') |
|
38
|
1 |
|
->findByActive(true); |
|
39
|
|
|
|
|
40
|
1 |
|
return $currentPolls; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Get pagination object of Polls |
|
45
|
|
|
* |
|
46
|
|
|
* @param Request $request |
|
47
|
|
|
* @return Pagerfanta |
|
48
|
|
|
*/ |
|
49
|
1 |
|
protected function getPolls(Request $request): Pagerfanta |
|
50
|
|
|
{ |
|
51
|
1 |
|
$polls = $this->getDoctrine() |
|
52
|
1 |
|
->getRepository('AppBundle:Poll') |
|
53
|
1 |
|
->findAll(); |
|
54
|
1 |
|
$paginator = new Pagerfanta(new ArrayAdapter($polls)); |
|
55
|
1 |
|
$paginator->setMaxPerPage(20); |
|
56
|
1 |
|
$paginator->setCurrentPage($request->query->get('page', 1), false, true); |
|
57
|
|
|
|
|
58
|
1 |
|
return $paginator; |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.