public function __construct($node, $parent) { parent::__construct($node, $parent); self::$possible_attributes = array_merge(parent::$possible_attributes, self::$possible_attributes); self::$required_attributes = array_merge(parent::$required_attributes, self::$required_attributes); self::$possible_children = array_merge(parent::$possible_children, self::$possible_children); self::$required_children = array_merge(parent::$required_children, self::$required_children); }
public static function getMultipleResults($electionId) { $total_votes = Election::getTotalVotes($electionId); $multiples = Multiple::getListWithCandidates($electionId); if (empty($multiples)) { return null; } $votes = Vote::getMultipleVotes($electionId); if (empty($votes)) { return 'No multiple chair votes recorded.'; } $total_cast_votes = array(); foreach ($votes as $v) { $key = $v['multipleId']; if (!isset($total_cast_votes[$key])) { $total_cast_votes[$key] = 0; } $total_cast_votes[$key] += $v['votes']; $sorted_votes[$key][$v['candidateId']] = $v['votes']; } foreach ($multiples as $ballot) { $ballot_row['title'] = $ballot['title']; $ballot_row['seats'] = $ballot['seatNumber']; $candidates = array(); foreach ($ballot['candidates'] as $c) { if (isset($sorted_votes[$ballot['id']][$c['id']])) { $vote = $sorted_votes[$ballot['id']][$c['id']]; $template = new \Template(); $template->setModuleTemplate('election', 'Admin/Report/Candidate.html'); $template->add('name', $c['firstName'] . ' ' . $c['lastName']); $percentage = round($vote / $total_cast_votes[$ballot['id']] * 100, 1); $template->add('vote', "{$vote} ({$percentage}%)"); $template->add('picture', $c['picture']); $candidates[$vote . '.' . $c['id']] = $template->get(); } } if (!empty($candidates)) { krsort($candidates); $ballot_row['candidates'] = implode("\n", $candidates); } else { $ballot_row['candidates'] = self::noCandidateVotes(); } $tpl['ballots'][] = $ballot_row; } $template = new \Template(); $template->addVariables($tpl); $template->setModuleTemplate('election', 'Admin/Report/Multiple.html'); return $template->get(); }
/** * @dataProvider providerForNotMultiple * @expectedException Respect\Validation\Exceptions\MultipleException */ public function testNotMultipleShouldThrowMultipleException($multipleOf, $input) { $multiple = new Multiple($multipleOf); $this->assertFalse($multiple->validate($input)); $this->assertFalse($multiple->assert($input)); }
<?php trait One { public function className() { return __CLASS__ . "<br>"; } } trait Two { public function say() { return "Hi <br>"; } } class Multiple { use One, Two; } $multiple = new Multiple(); echo $multiple->className(); echo $multiple->say();
/** * @dataProvider providerForNotMultiple * @expectedException Respect\Validation\Exceptions\MultipleException */ public function test_not_multiple_should_throw_MultipleException($multipleOf, $input) { $multiple = new Multiple($multipleOf); $this->assertFalse($multiple->validate($input)); $this->assertFalse($multiple->assert($input)); }
/** * @param array $setting * @return array */ protected function parse_args(array $setting) { return wp_parse_args(parent::parse_args($setting), ['inline' => false]); }
private static function saveMultipleResult($election_id, $multiple_result, \election\Resource\Student $student) { $db = \Database::getDB(); $tbl = $db->addTable('elect_multi_chair_vote'); foreach ($multiple_result as $vote) { // the abstained from everything if (!isset($vote['chairs'])) { continue; } $voted = array(); $multiple = Multiple::build($vote['multipleId'], new \election\Resource\Multiple()); $seatNumber = $multiple->getSeatNumber(); $voter_hash = StudentFactory::getVoteHash($vote['multipleId'], $student->getBannerId()); // Remove previous votes on this hash. We do this because we can't use the // unique index to prevent duplicates. $tbl->addFieldConditional('voterHash', $voter_hash); $db->delete(); $db->clearConditional(); $tbl->addValue('voterHash', $voter_hash); $tbl->addValue('electionId', $election_id); $tbl->addValue('multipleId', $vote['multipleId']); $count = 0; foreach ($vote['chairs'] as $candidateId) { // security against over voting. if ($count >= $seatNumber) { break; } // extra security against multiples votes for same candidate // unique index on database will prevent this as well. if (in_array($candidateId, $voted)) { continue; } $voted[] = $candidateId; $tbl->addValue('candidateId', $candidateId); $tbl->insert(); $count++; } $tbl->resetValues(); } }
/** * @param Multiple $multipleFrame * * @return AFrame */ public final function setAsMultiple(Multiple $multipleFrame) { if (!$this->_isAsMultiple) { $multipleFrame->addFrame($this); $this->_isAsMultiple = true; } return $this; }