1 | <?php |
||
5 | class Election |
||
6 | { |
||
7 | /** |
||
8 | * Count of candidates in election. |
||
9 | * |
||
10 | * @var int |
||
11 | */ |
||
12 | protected $candidateCount; |
||
13 | |||
14 | /** |
||
15 | * Count of number of seats/winners. |
||
16 | * |
||
17 | * @var int |
||
18 | */ |
||
19 | protected $winnersCount; |
||
20 | |||
21 | /** |
||
22 | * Array of candidates competing in election. |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | protected $candidates; |
||
27 | |||
28 | /** |
||
29 | * Array of ballots cast in election. |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $ballots; |
||
34 | |||
35 | /** |
||
36 | * Constructor. |
||
37 | * |
||
38 | * @param array $candidates Array of candidates competing |
||
39 | * @param array $ballots Array of all ballots cast in election |
||
40 | * @param int $winnersCount Number of winners to allocate |
||
41 | */ |
||
42 | 6 | public function __construct(array $candidates, array $ballots, int $winnersCount = 2) |
|
49 | |||
50 | /** |
||
51 | * Get a specific candidate object by their ID. |
||
52 | * |
||
53 | * @param int $id ID of the candidate to get |
||
54 | * |
||
55 | * @return \Michaelc\Voting\STV\Candidate |
||
56 | */ |
||
57 | 2 | public function getCandidate(int $id): Candidate |
|
61 | |||
62 | /** |
||
63 | * Get a count of candidates competing. |
||
64 | * |
||
65 | * @return int |
||
66 | */ |
||
67 | 4 | public function getCandidateCount(): int |
|
71 | |||
72 | /** |
||
73 | * Get an array of candidates still running (not elected or defeated). |
||
74 | * |
||
75 | * @return \Michaelc\Voting\STV\Candidate[] |
||
76 | */ |
||
77 | 3 | public function getActiveCandidates(): array |
|
81 | |||
82 | 2 | public function getActiveCandidateIds(): array |
|
94 | |||
95 | /** |
||
96 | * Get an array of candidates elected. |
||
97 | * |
||
98 | * @return \Michaelc\Voting\STV\Candidate[] |
||
99 | */ |
||
100 | 2 | public function getElectedCandidates(): array |
|
104 | |||
105 | /** |
||
106 | * Get an array of candidates defeated. |
||
107 | * |
||
108 | * @return \Michaelc\Voting\STV\Candidate[] |
||
109 | */ |
||
110 | 2 | public function getDefeatedCandidates(): array |
|
114 | |||
115 | /** |
||
116 | * Get all candidates of a specific state. |
||
117 | * |
||
118 | * @param int $state A candidate state (See Candidate constants) |
||
119 | * |
||
120 | * @return \Michaelc\Voting\STV\Candidate[] |
||
121 | */ |
||
122 | 3 | public function getStateCandidates(int $state): array |
|
134 | |||
135 | /** |
||
136 | * Get a count of candidates still running (not elected or defeated). |
||
137 | * |
||
138 | * @return int |
||
139 | */ |
||
140 | 2 | public function getActiveCandidateCount(): int |
|
144 | |||
145 | /** |
||
146 | * Get an array of candidate ids. |
||
147 | * |
||
148 | * @return int[] |
||
149 | */ |
||
150 | 3 | public function getCandidateIds(): array |
|
160 | |||
161 | /** |
||
162 | * Gets the value of winnersCount. |
||
163 | * |
||
164 | * @return int |
||
165 | */ |
||
166 | 4 | public function getWinnersCount(): int |
|
170 | |||
171 | /** |
||
172 | * Gets the value of candidates. |
||
173 | * |
||
174 | * @return array |
||
175 | */ |
||
176 | 3 | public function getCandidates(): array |
|
180 | |||
181 | /** |
||
182 | * Gets the value of ballots. |
||
183 | * |
||
184 | * @return array |
||
185 | */ |
||
186 | 3 | public function getBallots(): array |
|
190 | |||
191 | /** |
||
192 | * Get the number of ballots. |
||
193 | * |
||
194 | * @return int |
||
195 | */ |
||
196 | 3 | public function getNumBallots(): int |
|
200 | |||
201 | /** |
||
202 | * Get status of all candidates. |
||
203 | * |
||
204 | * @return array |
||
205 | */ |
||
206 | 1 | public function getCandidatesStatus(): array |
|
224 | } |
||
225 |