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 int $winnersCount Number of winners to allocate |
||
39 | * @param array $candidates Array of candidates competing |
||
40 | * @param array $ballots Array of all ballots cast in election |
||
41 | */ |
||
42 | 4 | public function __construct(int $winnersCount, array $candidates, array $ballots) |
|
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 | 1 | public function getCandidate(int $id): Candidate |
|
61 | |||
62 | /** |
||
63 | * Get a count of candidates competing. |
||
64 | * |
||
65 | * @return int |
||
66 | */ |
||
67 | 2 | 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 | 2 | public function getActiveCandidates(): array |
|
81 | |||
82 | /** |
||
83 | * Get an array of candidates elected. |
||
84 | * |
||
85 | * @return \Michaelc\Voting\STV\Candidate[] |
||
86 | */ |
||
87 | 1 | public function getElectedCandidates(): array |
|
88 | { |
||
89 | 1 | return $this->getStateCandidates(Candidate::ELECTED); |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * Get an array of candidates defeated. |
||
94 | * |
||
95 | * @return \Michaelc\Voting\STV\Candidate[] |
||
96 | */ |
||
97 | 1 | public function getDefeatedCandidates(): array |
|
98 | { |
||
99 | 1 | return $this->getStateCandidates(Candidate::DEFEATED); |
|
100 | } |
||
101 | |||
102 | /** |
||
103 | * Get all candidates of a specific state. |
||
104 | * |
||
105 | * @param int $state A candidate state (See Candidate constants) |
||
106 | * |
||
107 | * @return \Michaelc\Voting\STV\Candidate[] |
||
108 | */ |
||
109 | 2 | public function getStateCandidates(int $state): array |
|
121 | |||
122 | /** |
||
123 | * Get a count of candidates still running (not elected or defeated). |
||
124 | * |
||
125 | * @return int |
||
126 | */ |
||
127 | 1 | public function getActiveCandidateCount(): int |
|
131 | |||
132 | /** |
||
133 | * Get an array of candidate ids. |
||
134 | * |
||
135 | * @return int[] |
||
136 | */ |
||
137 | 1 | public function getCandidateIds(): array |
|
138 | { |
||
139 | 1 | $candidateIds = []; |
|
140 | |||
141 | 1 | foreach ($this->candidates as $i => $candidate) { |
|
142 | 1 | $candidateIds[] = $candidate->getId(); |
|
143 | } |
||
144 | |||
145 | 1 | return $candidateIds; |
|
146 | } |
||
147 | |||
148 | /** |
||
149 | * Gets the value of winnersCount. |
||
150 | * |
||
151 | * @return int |
||
152 | */ |
||
153 | 1 | public function getWinnersCount(): int |
|
157 | |||
158 | /** |
||
159 | * Gets the value of candidates. |
||
160 | * |
||
161 | * @return array |
||
162 | */ |
||
163 | 2 | public function getCandidates(): array |
|
164 | { |
||
165 | 2 | return $this->candidates; |
|
166 | } |
||
167 | |||
168 | /** |
||
169 | * Gets the value of ballots. |
||
170 | * |
||
171 | * @return array |
||
172 | */ |
||
173 | 1 | public function getBallots(): array |
|
177 | |||
178 | /** |
||
179 | * Get the number of ballots. |
||
180 | * |
||
181 | * @return int |
||
182 | */ |
||
183 | 1 | public function getNumBallots(): int |
|
187 | |||
188 | /** |
||
189 | * Get status of all candidates. |
||
190 | * |
||
191 | * @return array |
||
192 | */ |
||
193 | public function getCandidatesStatus(): array |
||
211 | } |
||
212 |