protected function registerVote(Vote $vote, $tag = null) : Vote { // Vote identifiant $vote->addTags($tag); // Register try { $vote->registerLink($this); $this->_Votes[] = $vote; } catch (CondorcetException $e) { // Security : Check if vote object not already register throw new CondorcetException(6, 'Vote object already registred'); } return $vote; }
// Return an array pupulate by each Candidate name as String. // OK, I need my Debussy (want his candidate object) $myDebussyCandidate = $election1->getCandidateObjectByName('Debussy'); // IV - Votes # -A- Add Votes $myVote1 = $election1->addVote(array(1 => 'Debussy', 2 => ['Caplet', 'Olivier Messiaen'], 3 => 'Ligeti', 4 => ['Wiltod Lutoslawski', 'Koechlin'])); // Return the new Vote object $myVote2 = new Vote(array(1 => 'Debussy', 2 => 'Caplet', 3 => 'Olivier Messiaen', 4 => 'Koechlin', 5 => 'Wiltod Lutoslawski', 6 => 'Ligeti')); $election1->addVote($myVote2); $myVote3 = $election1->addVote('Debussy > Olivier Messiaen = Ligeti > Caplet'); // Last rank rank will be automatically deducted. A vote can not be expressed on a limited number of candidates. Non-expressed candidates are presumed to last Exaequo // Off course, you can vote by candidate object. Which is recommended. Or mix the two methods. $myVote4 = $election1->addVote(array($election1->getCandidateObjectByName('Ligeti'), $myLutoCandidate, [$myMessiaenCandidate, 'Koechlin'])); // Finishing with another really nice example. $myVote5 = new Vote(array(1 => $election1->getCandidateObjectByName('Debussy'), 2 => $election1->getCandidateObjectByName('Olivier Messiaen'), 3 => [$election1->getCandidateObjectByName('Wiltod Lutoslawski'), $election1->getCandidateObjectByName('Ligeti')], 4 => $election1->getCandidateObjectByName('Koechlin'), 5 => $election1->getCandidateObjectByName('Caplet'))); $myVote5->addTags('jusGreatVote'); $election1->addVote($myVote5); // Please note that : $election1->getCandidateObjectByName('Olivier Messiaen') === $myMessiaenCandidate; // Return TRUE // Add some nice tags to my Vote 1 & 2 & 3 (You can do this before or after add register into to the Election) $myVote1->addTags(['strangeVote', 'greatFrenchVote']); // By Array $myVote2->addTags('greatFrenchVote,chauvinismVote'); // By String $myVote3->addTags($myVote1->getTags()); // Copy & Past // Parsing Vote $election1->parseVotes("\n Ligeti > Wiltod Lutoslawski > Olivier Messiaen = Debussy > Koechlin # A comment. A a line break for the next vote.\n greatFrenchVote,chauvinismVote || Olivier Messiaen > Debussy = Caplet > Ligeti # Tags at first, vote at second, separated by '||'\n strangeVote || Caplet > Koechlin * 8 # This vote and his tag will be register 8 times.\n "); // Adding some random to this election $VoteModel = $myVote2->getRanking();