@@ -6,50 +6,50 @@ |
||
| 6 | 6 | |
| 7 | 7 | class VoteHandler |
| 8 | 8 | { |
| 9 | - protected $election; |
|
| 10 | - protected $ballots; |
|
| 11 | - |
|
| 12 | - /** |
|
| 13 | - * Constructor |
|
| 14 | - * |
|
| 15 | - * @param Election $election |
|
| 16 | - */ |
|
| 17 | - public function __construct(Election $election) |
|
| 18 | - { |
|
| 19 | - $this->election = $election; |
|
| 20 | - $this->ballots = $this->election->getBallots(); |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - public function step($step) |
|
| 24 | - { |
|
| 25 | - foreach ($this->ballots as $i => $ballot) |
|
| 26 | - { |
|
| 27 | - $weight = $ballot->getWeight(); |
|
| 28 | - $candidate = $ballot->getNextPreference(); |
|
| 29 | - $election->getCandidate($candidate->getId())->addVotes($weight); |
|
| 30 | - $ballot->setLastUsedLevel(($step - 1)); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - $candidates = $election->getActiveCandidates(); |
|
| 34 | - |
|
| 35 | - foreach ($candidates as $i => $candidate) { |
|
| 36 | - if ($candidate->getVotes() >= $this->getQuota()) |
|
| 37 | - { |
|
| 38 | - $candidate->setState(Candidate::ELECTED); |
|
| 39 | - $surplus = $candidate->getVotes() - $quota; |
|
| 40 | - |
|
| 41 | - $this->transferVotes($surplus, $candidate); |
|
| 42 | - } |
|
| 43 | - } |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - protected function transferVotes(float $votes, Candidate $candidate) |
|
| 47 | - { |
|
| 48 | - |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - public function getQuota() |
|
| 52 | - { |
|
| 53 | - return floor(($election->getNumBallots() / ($election->getNumSeats() + 1)) + 1); |
|
| 54 | - } |
|
| 9 | + protected $election; |
|
| 10 | + protected $ballots; |
|
| 11 | + |
|
| 12 | + /** |
|
| 13 | + * Constructor |
|
| 14 | + * |
|
| 15 | + * @param Election $election |
|
| 16 | + */ |
|
| 17 | + public function __construct(Election $election) |
|
| 18 | + { |
|
| 19 | + $this->election = $election; |
|
| 20 | + $this->ballots = $this->election->getBallots(); |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + public function step($step) |
|
| 24 | + { |
|
| 25 | + foreach ($this->ballots as $i => $ballot) |
|
| 26 | + { |
|
| 27 | + $weight = $ballot->getWeight(); |
|
| 28 | + $candidate = $ballot->getNextPreference(); |
|
| 29 | + $election->getCandidate($candidate->getId())->addVotes($weight); |
|
| 30 | + $ballot->setLastUsedLevel(($step - 1)); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + $candidates = $election->getActiveCandidates(); |
|
| 34 | + |
|
| 35 | + foreach ($candidates as $i => $candidate) { |
|
| 36 | + if ($candidate->getVotes() >= $this->getQuota()) |
|
| 37 | + { |
|
| 38 | + $candidate->setState(Candidate::ELECTED); |
|
| 39 | + $surplus = $candidate->getVotes() - $quota; |
|
| 40 | + |
|
| 41 | + $this->transferVotes($surplus, $candidate); |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + protected function transferVotes(float $votes, Candidate $candidate) |
|
| 47 | + { |
|
| 48 | + |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + public function getQuota() |
|
| 52 | + { |
|
| 53 | + return floor(($election->getNumBallots() / ($election->getNumSeats() + 1)) + 1); |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | if (empty($this->ranking[$level])) |
| 120 | 120 | { |
| 121 | - return null; |
|
| 121 | + return null; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | return $this->ranking[$level]; |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | |
| 131 | 131 | if (empty($this->ranking[$level])) |
| 132 | 132 | { |
| 133 | - return null; |
|
| 133 | + return null; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | return $this->ranking[$level]; |