@@ -6,8 +6,8 @@ |
||
6 | 6 | use AppBundle\Exception\InvalidSort; |
7 | 7 | use AppBundle\Utils\ElectionManager; |
8 | 8 | use AppBundle\Utils\PollManager; |
9 | -use Pagerfanta\Adapter\ArrayAdapter; |
|
10 | 9 | use PagerFanta\Exception\Exception; |
10 | +use Pagerfanta\Adapter\ArrayAdapter; |
|
11 | 11 | use Pagerfanta\Pagerfanta; |
12 | 12 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
13 | 13 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
@@ -17,76 +17,76 @@ |
||
17 | 17 | |
18 | 18 | class VoteController extends Controller |
19 | 19 | { |
20 | - private $electionManager; |
|
21 | - private $pollManager; |
|
20 | + private $electionManager; |
|
21 | + private $pollManager; |
|
22 | 22 | |
23 | - /** |
|
24 | - * VoteController constructor. |
|
25 | - * |
|
26 | - * @param \AppBundle\Utils\PollManager $pollManager |
|
27 | - * @param \AppBundle\Utils\ElectionManager $electionManager |
|
28 | - */ |
|
29 | - public function __construct(PollManager $pollManager, ElectionManager $electionManager) |
|
30 | - { |
|
31 | - $this->pollManager = $pollManager; |
|
32 | - $this->electionManager = $electionManager; |
|
33 | - } |
|
23 | + /** |
|
24 | + * VoteController constructor. |
|
25 | + * |
|
26 | + * @param \AppBundle\Utils\PollManager $pollManager |
|
27 | + * @param \AppBundle\Utils\ElectionManager $electionManager |
|
28 | + */ |
|
29 | + public function __construct(PollManager $pollManager, ElectionManager $electionManager) |
|
30 | + { |
|
31 | + $this->pollManager = $pollManager; |
|
32 | + $this->electionManager = $electionManager; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * @Route("/polls", name="polls_list") |
|
37 | - * @param \Symfony\Component\HttpFoundation\Request $request |
|
38 | - * |
|
39 | - * @return \Symfony\Component\HttpFoundation\Response |
|
40 | - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
|
41 | - */ |
|
42 | - public function listAction(Request $request): Response |
|
43 | - { |
|
44 | - try { |
|
45 | - $sort = $request->request->has('sort') ? $sort = $request->get('sort') : null; |
|
46 | - $polls = $this->pollManager->getPolls($sort); |
|
47 | - $current = $this->pollManager->getPolls($sort, true); |
|
48 | - } catch ( InvalidSort $e ) { |
|
49 | - throw new NotFoundHttpException('This is an invalid sorting method'); |
|
50 | - } |
|
35 | + /** |
|
36 | + * @Route("/polls", name="polls_list") |
|
37 | + * @param \Symfony\Component\HttpFoundation\Request $request |
|
38 | + * |
|
39 | + * @return \Symfony\Component\HttpFoundation\Response |
|
40 | + * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
|
41 | + */ |
|
42 | + public function listAction(Request $request): Response |
|
43 | + { |
|
44 | + try { |
|
45 | + $sort = $request->request->has('sort') ? $sort = $request->get('sort') : null; |
|
46 | + $polls = $this->pollManager->getPolls($sort); |
|
47 | + $current = $this->pollManager->getPolls($sort, true); |
|
48 | + } catch ( InvalidSort $e ) { |
|
49 | + throw new NotFoundHttpException('This is an invalid sorting method'); |
|
50 | + } |
|
51 | 51 | |
52 | - $pollsPaginated = $this->paginate($request, $polls); |
|
52 | + $pollsPaginated = $this->paginate($request, $polls); |
|
53 | 53 | |
54 | - return $this->render('default/index.html.twig', ['polls' => $pollsPaginated, 'current' => $current]); |
|
55 | - } |
|
54 | + return $this->render('default/index.html.twig', ['polls' => $pollsPaginated, 'current' => $current]); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Get pagination object of Polls. |
|
59 | - * |
|
60 | - * @param Request $request |
|
61 | - * |
|
62 | - * @param array $items |
|
63 | - * |
|
64 | - * @return \Pagerfanta\Pagerfanta |
|
65 | - * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
|
66 | - */ |
|
67 | - protected function paginate(Request $request, array $items): Pagerfanta |
|
68 | - { |
|
69 | - $paginator = new Pagerfanta(new ArrayAdapter($items)); |
|
57 | + /** |
|
58 | + * Get pagination object of Polls. |
|
59 | + * |
|
60 | + * @param Request $request |
|
61 | + * |
|
62 | + * @param array $items |
|
63 | + * |
|
64 | + * @return \Pagerfanta\Pagerfanta |
|
65 | + * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
|
66 | + */ |
|
67 | + protected function paginate(Request $request, array $items): Pagerfanta |
|
68 | + { |
|
69 | + $paginator = new Pagerfanta(new ArrayAdapter($items)); |
|
70 | 70 | |
71 | - $paginator->setMaxPerPage(20); |
|
71 | + $paginator->setMaxPerPage(20); |
|
72 | 72 | |
73 | - try { |
|
74 | - $paginator->setCurrentPage($request->query->get('page', 1), false, true); |
|
75 | - } catch (Exception $e) { |
|
76 | - throw new NotFoundHttpException('Page not found'); |
|
77 | - } |
|
73 | + try { |
|
74 | + $paginator->setCurrentPage($request->query->get('page', 1), false, true); |
|
75 | + } catch (Exception $e) { |
|
76 | + throw new NotFoundHttpException('Page not found'); |
|
77 | + } |
|
78 | 78 | |
79 | - return $paginator; |
|
80 | - } |
|
79 | + return $paginator; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @Route("/poll/{id}", name="poll_view") |
|
84 | - * @param \Symfony\Component\HttpFoundation\Request $request |
|
85 | - * @param \AppBundle\Entity\Poll $poll |
|
86 | - * |
|
87 | - * @return \Symfony\Component\HttpFoundation\Response |
|
88 | - */ |
|
89 | - public function viewAction(Request $request, Poll $poll): Response |
|
90 | - { |
|
91 | - } |
|
82 | + /** |
|
83 | + * @Route("/poll/{id}", name="poll_view") |
|
84 | + * @param \Symfony\Component\HttpFoundation\Request $request |
|
85 | + * @param \AppBundle\Entity\Poll $poll |
|
86 | + * |
|
87 | + * @return \Symfony\Component\HttpFoundation\Response |
|
88 | + */ |
|
89 | + public function viewAction(Request $request, Poll $poll): Response |
|
90 | + { |
|
91 | + } |
|
92 | 92 | } |
@@ -45,7 +45,7 @@ |
||
45 | 45 | $sort = $request->request->has('sort') ? $sort = $request->get('sort') : null; |
46 | 46 | $polls = $this->pollManager->getPolls($sort); |
47 | 47 | $current = $this->pollManager->getPolls($sort, true); |
48 | - } catch ( InvalidSort $e ) { |
|
48 | + } catch (InvalidSort $e) { |
|
49 | 49 | throw new NotFoundHttpException('This is an invalid sorting method'); |
50 | 50 | } |
51 | 51 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | namespace AppBundle\Utils; |
4 | 4 | |
5 | 5 | use AppBundle\Entity\{ |
6 | - Choice, Poll, PollType |
|
6 | + Choice, Poll, PollType |
|
7 | 7 | }; |
8 | 8 | use Doctrine\Common\Persistence\ManagerRegistry; |
9 | 9 | |
@@ -12,28 +12,28 @@ discard block |
||
12 | 12 | protected $doctrineRegistry; |
13 | 13 | protected $electionManager; |
14 | 14 | |
15 | - /** |
|
16 | - * Constructor. |
|
17 | - * |
|
18 | - * @param \Doctrine\Common\Persistence\ManagerRegistry $doctrineRegistry |
|
19 | - * @param \AppBundle\Utils\ElectionManager $electionManager |
|
20 | - */ |
|
21 | - public function __construct(ManagerRegistry $doctrineRegistry, ElectionManager $electionManager) |
|
15 | + /** |
|
16 | + * Constructor. |
|
17 | + * |
|
18 | + * @param \Doctrine\Common\Persistence\ManagerRegistry $doctrineRegistry |
|
19 | + * @param \AppBundle\Utils\ElectionManager $electionManager |
|
20 | + */ |
|
21 | + public function __construct(ManagerRegistry $doctrineRegistry, ElectionManager $electionManager) |
|
22 | 22 | { |
23 | 23 | $this->doctrineRegistry = $doctrineRegistry; |
24 | 24 | $this->electionManager = $electionManager; |
25 | 25 | } |
26 | 26 | |
27 | - public function getPolls($sort, boolean $current = false): array |
|
28 | - { |
|
29 | - // TODO: Implement sorts and getting polls from db |
|
27 | + public function getPolls($sort, boolean $current = false): array |
|
28 | + { |
|
29 | + // TODO: Implement sorts and getting polls from db |
|
30 | 30 | |
31 | - if ($current) { |
|
32 | - return $this->getCurrentPolls(); |
|
33 | - } |
|
31 | + if ($current) { |
|
32 | + return $this->getCurrentPolls(); |
|
33 | + } |
|
34 | 34 | |
35 | - return []; |
|
36 | - } |
|
35 | + return []; |
|
36 | + } |
|
37 | 37 | |
38 | 38 | /** |
39 | 39 | * Get an array of current polls (objects). |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function getCurrentPolls(): array |
44 | 44 | { |
45 | - $currentPolls = $this->doctrineRegistry->getManager()->getRepository('AppBundle:Poll')->findByActive(true); |
|
45 | + $currentPolls = $this->doctrineRegistry->getManager()->getRepository('AppBundle:Poll')->findByActive(true); |
|
46 | 46 | |
47 | 47 | return $currentPolls; |
48 | 48 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | */ |
67 | 67 | public function getAllPolls(): array |
68 | 68 | { |
69 | - $polls = $this->doctrineRegistry->getManager()->getRepository('AppBundle:Poll')->findAll(); |
|
69 | + $polls = $this->doctrineRegistry->getManager()->getRepository('AppBundle:Poll')->findAll(); |
|
70 | 70 | |
71 | 71 | return $polls; |
72 | 72 | } |
@@ -86,13 +86,13 @@ discard block |
||
86 | 86 | return []; |
87 | 87 | } |
88 | 88 | |
89 | - /** |
|
90 | - * Get the result of the poll (in terms of a choice). |
|
91 | - * |
|
92 | - * @param Poll $poll |
|
93 | - * |
|
94 | - * @return \AppBundle\Entity\Choice |
|
95 | - */ |
|
89 | + /** |
|
90 | + * Get the result of the poll (in terms of a choice). |
|
91 | + * |
|
92 | + * @param Poll $poll |
|
93 | + * |
|
94 | + * @return \AppBundle\Entity\Choice |
|
95 | + */ |
|
96 | 96 | public function getPollResult(Poll $poll): Choice |
97 | 97 | { |
98 | 98 | // If election then call Election Manager |
@@ -108,14 +108,14 @@ discard block |
||
108 | 108 | |
109 | 109 | public function markPollClosed(Poll $poll) |
110 | 110 | { |
111 | - $poll->setActive(false); |
|
112 | - $result = $this->generateResult($poll); |
|
111 | + $poll->setActive(false); |
|
112 | + $result = $this->generateResult($poll); |
|
113 | 113 | |
114 | - return $result; |
|
114 | + return $result; |
|
115 | 115 | } |
116 | 116 | |
117 | - public function generateResult(Poll $poll) |
|
118 | - { |
|
117 | + public function generateResult(Poll $poll) |
|
118 | + { |
|
119 | 119 | |
120 | 120 | } |
121 | 121 | } |
@@ -115,12 +115,12 @@ discard block |
||
115 | 115 | * |
116 | 116 | * @return string |
117 | 117 | */ |
118 | - public function getName(): string |
|
119 | - { |
|
120 | - return $this->name; |
|
121 | - } |
|
118 | + public function getName(): string |
|
119 | + { |
|
120 | + return $this->name; |
|
121 | + } |
|
122 | 122 | |
123 | - /** |
|
123 | + /** |
|
124 | 124 | * Set name. |
125 | 125 | * |
126 | 126 | * @param string $name |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | * |
140 | 140 | * @return \DateTime |
141 | 141 | */ |
142 | - public function getStart(): DateTime |
|
142 | + public function getStart(): DateTime |
|
143 | 143 | { |
144 | - return $this->start; |
|
144 | + return $this->start; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | * |
164 | 164 | * @return string |
165 | 165 | */ |
166 | - public function getDescription(): string |
|
166 | + public function getDescription(): string |
|
167 | 167 | { |
168 | - return $this->description; |
|
168 | + return $this->description; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -187,9 +187,9 @@ discard block |
||
187 | 187 | * |
188 | 188 | * @return \AppBundle\Entity\User |
189 | 189 | */ |
190 | - public function getCreator(): \AppBundle\Entity\User |
|
190 | + public function getCreator(): \AppBundle\Entity\User |
|
191 | 191 | { |
192 | - return $this->creator; |
|
192 | + return $this->creator; |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
@@ -279,12 +279,12 @@ discard block |
||
279 | 279 | * |
280 | 280 | * @return \AppBundle\Entity\PollType |
281 | 281 | */ |
282 | - public function getPollType() |
|
283 | - { |
|
284 | - return $this->pollType; |
|
285 | - } |
|
282 | + public function getPollType() |
|
283 | + { |
|
284 | + return $this->pollType; |
|
285 | + } |
|
286 | 286 | |
287 | - /** |
|
287 | + /** |
|
288 | 288 | * Set pollType. |
289 | 289 | * |
290 | 290 | * @param \AppBundle\Entity\PollType $pollType |
@@ -303,9 +303,9 @@ discard block |
||
303 | 303 | * |
304 | 304 | * @return bool |
305 | 305 | */ |
306 | - public function getActive(): bool |
|
306 | + public function getActive(): bool |
|
307 | 307 | { |
308 | - return $this->active; |
|
308 | + return $this->active; |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | /** |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @return \DateTime |
85 | 85 | */ |
86 | - public function getTime(): DateTime |
|
87 | - { |
|
88 | - return $this->time; |
|
89 | - } |
|
86 | + public function getTime(): DateTime |
|
87 | + { |
|
88 | + return $this->time; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
91 | + /** |
|
92 | 92 | * Set time. |
93 | 93 | * |
94 | 94 | * @param \DateTime $time |
@@ -107,9 +107,9 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @return \AppBundle\Entity\Poll |
109 | 109 | */ |
110 | - public function getPoll(): \AppBundle\Entity\Poll |
|
110 | + public function getPoll(): \AppBundle\Entity\Poll |
|
111 | 111 | { |
112 | - return $this->poll; |
|
112 | + return $this->poll; |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @return \AppBundle\Entity\User |
133 | 133 | */ |
134 | - public function getCaster(): \AppBundle\Entity\User |
|
134 | + public function getCaster(): \AppBundle\Entity\User |
|
135 | 135 | { |
136 | - return $this->caster; |
|
136 | + return $this->caster; |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -155,9 +155,9 @@ discard block |
||
155 | 155 | * |
156 | 156 | * @return \AppBundle\Entity\Choice |
157 | 157 | */ |
158 | - public function getChoice(): \AppBundle\Entity\Choice |
|
158 | + public function getChoice(): \AppBundle\Entity\Choice |
|
159 | 159 | { |
160 | - return $this->choice; |
|
160 | + return $this->choice; |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | * |
180 | 180 | * @return int |
181 | 181 | */ |
182 | - public function getWeight(): int |
|
182 | + public function getWeight(): int |
|
183 | 183 | { |
184 | - return $this->weight; |
|
184 | + return $this->weight; |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | /** |