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
|
|
|
// TODO: Implement sorts and getting polls from db |
30
|
|
|
|
31
|
1 |
|
if ($current) { |
32
|
|
|
return $this->getCurrentPolls(); |
33
|
1 |
|
} |
34
|
|
|
|
35
|
1 |
|
return []; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Get an array of current polls (objects). |
40
|
|
|
* |
41
|
|
|
* @return array |
42
|
|
|
*/ |
43
|
|
|
public function getCurrentPolls(): array |
44
|
|
|
{ |
45
|
|
|
$currentPolls = $this->doctrineRegistry->getManager()->getRepository('AppBundle:Poll')->findByActive(true); |
46
|
|
|
|
47
|
|
|
return $currentPolls; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get an array of eligible votes. |
52
|
|
|
* |
53
|
|
|
* @param AppBundle/Entity/PollType $type |
|
|
|
|
54
|
|
|
* |
55
|
1 |
|
* @return array |
56
|
|
|
*/ |
57
|
1 |
|
public function getEligibleVoters(PollType $type): array |
|
|
|
|
58
|
|
|
{ |
59
|
1 |
|
return []; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get an array of all polls (objects). |
64
|
|
|
* |
65
|
|
|
* @return array |
66
|
|
|
*/ |
67
|
|
|
public function getAllPolls(): array |
68
|
|
|
{ |
69
|
|
|
$polls = $this->doctrineRegistry->getManager()->getRepository('AppBundle:Poll')->findAll(); |
70
|
|
|
|
71
|
|
|
return $polls; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Get poll statistics. |
76
|
|
|
* |
77
|
|
|
* @param Poll $poll |
78
|
|
|
* |
79
|
|
|
* @return array |
80
|
|
|
*/ |
81
|
|
|
public function getPollStats(Poll $poll): array |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
// If Poll is election then reject |
84
|
|
|
|
85
|
|
|
// Get standard stats |
86
|
|
|
return []; |
87
|
|
|
} |
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
|
|
|
*/ |
96
|
|
|
public function getPollResult(Poll $poll): Choice |
|
|
|
|
97
|
|
|
{ |
98
|
|
|
// If election then call Election Manager |
99
|
|
|
|
100
|
|
|
// Calculate winning choice |
101
|
|
|
return; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function getStandardPollVotes(Poll $poll): array |
|
|
|
|
105
|
|
|
{ |
106
|
|
|
return []; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
public function markPollClosed(Poll $poll) |
110
|
|
|
{ |
111
|
|
|
$poll->setActive(false); |
112
|
|
|
$result = $this->generateResult($poll); |
|
|
|
|
113
|
|
|
|
114
|
|
|
return $result; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public function generateResult(Poll $poll) |
|
|
|
|
118
|
|
|
{ |
119
|
|
|
|
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.