1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Utils; |
4
|
|
|
|
5
|
|
|
use AppBundle\Entity\{ |
6
|
|
|
Choice, Poll, PollType |
7
|
|
|
}; |
8
|
|
|
use Doctrine\Common\Persistence\ManagerRegistry; |
9
|
|
|
|
10
|
|
|
class PollManager |
11
|
|
|
{ |
12
|
|
|
protected $doctrineRegistry; |
13
|
|
|
protected $electionManager; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Constructor. |
17
|
|
|
* |
18
|
|
|
* @param \Doctrine\Common\Persistence\ManagerRegistry $doctrineRegistry |
19
|
1 |
|
* @param \AppBundle\Utils\ElectionManager $electionManager |
20
|
|
|
*/ |
21
|
1 |
|
public function __construct(ManagerRegistry $doctrineRegistry, ElectionManager $electionManager) |
22
|
1 |
|
{ |
23
|
1 |
|
$this->doctrineRegistry = $doctrineRegistry; |
24
|
1 |
|
$this->electionManager = $electionManager; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function getPolls($sort, boolean $current = false): array |
|
|
|
|
28
|
|
|
{ |
29
|
|
|
if ($current) { |
30
|
|
|
return $this->getCurrentPolls(); |
31
|
1 |
|
} |
32
|
|
|
} |
33
|
1 |
|
|
34
|
|
|
/** |
35
|
1 |
|
* Get an array of current polls (objects). |
36
|
|
|
* |
37
|
|
|
* @return array |
38
|
|
|
*/ |
39
|
|
|
public function getCurrentPolls(): array |
40
|
|
|
{ |
41
|
|
|
$currentPolls = $this->doctrineRegistry->getEntityManager()->getRepository('AppBundle:Poll')->findByActive(true); |
|
|
|
|
42
|
|
|
|
43
|
|
|
return $currentPolls; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Get an array of eligible votes. |
48
|
|
|
* |
49
|
|
|
* @param AppBundle/Entity/PollType $type |
|
|
|
|
50
|
|
|
* |
51
|
|
|
* @return array |
52
|
|
|
*/ |
53
|
|
|
public function getEligibleVoters(PollType $type): array |
|
|
|
|
54
|
|
|
{ |
55
|
1 |
|
return []; |
56
|
|
|
} |
57
|
1 |
|
|
58
|
|
|
/** |
59
|
1 |
|
* Get an array of all polls (objects). |
60
|
|
|
* |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
|
|
public function getAllPolls(): array |
64
|
|
|
{ |
65
|
|
|
$polls = $this->doctrineRegistry->getEntityManager()->getRepository('AppBundle:Poll')->findAll(); |
|
|
|
|
66
|
|
|
|
67
|
|
|
return $polls; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Get poll statistics. |
72
|
|
|
* |
73
|
|
|
* @param Poll $poll |
74
|
|
|
* |
75
|
|
|
* @return array |
76
|
|
|
*/ |
77
|
|
|
public function getPollStats(Poll $poll): array |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
// If Poll is election then reject |
80
|
|
|
|
81
|
|
|
// Get standard stats |
82
|
|
|
return []; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Get the result of the poll (in terms of a choice). |
87
|
|
|
* |
88
|
|
|
* @param Poll $poll |
89
|
|
|
* |
90
|
|
|
* @return \AppBundle\Entity\Choice |
91
|
|
|
*/ |
92
|
|
|
public function getPollResult(Poll $poll): Choice |
|
|
|
|
93
|
|
|
{ |
94
|
|
|
// If election then call Election Manager |
95
|
|
|
|
96
|
|
|
// Calculate winning choice |
97
|
|
|
return; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function getStandardPollVotes(Poll $poll): array |
|
|
|
|
101
|
|
|
{ |
102
|
|
|
return []; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
public function markPollClosed(Poll $poll) |
|
|
|
|
106
|
|
|
{ |
107
|
|
|
return; |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.