// Add two participating candidates from $election1
$election2->addCandidate($election1->getCandidateObjectByName('Debussy'));
$election2->addCandidate($myLutoCandidate);
// And, I can change again theirs name. The new name is now applied in the two elections and their votes. If namesake in another election, an exception is throw.
$myLutoCandidate->setName('W.Lutoslawski');
// Have a look on $myLutoCandidate history
$myLutoCandidate->getHistory();
// Have a look to a vote from $election1. The candidate name have changed.
$myVote4->getContextualVote($election1, true);
// In what elections, this candidates have a part ?
$myLutoCandidate->getLinks();
// Get his the two Election objects
$myLutoCandidate->countLinks();
// Or just count it. return (int) 2.
# The same vote applied to multiple elections.
$myNewVote = new Vote(array(1 => $election1->getCandidateObjectByName('Debussy'), 2 => $election2->getCandidateObjectByName('A'), 3 => $election1->getCandidateObjectByName('Olivier Messiaen'), 4 => $election2->getCandidateObjectByName('B'), 5 => $election1->getCandidateObjectByName('Koechlin'), 6 => $election1->getCandidateObjectByName('W.Lutoslawski'), 7 => new Candidate('Another candidate'), 8 => $election1->getCandidateObjectByName('Caplet'), 9 => $election2->getCandidateObjectByName('C')));
// Add it on election 1 and 2
$election1->addVote($myNewVote);
$election2->addVote($myNewVote);
// Check ranking
$myNewVote->getRanking();
// Here you get the original 9 ranks.
// Check ranking
$myNewVote->getContextualVote($election1);
// Here you get the vote applicable to $election 1
$myNewVote->getContextualVote($election2);
// Here you get the vote applicable to $election 2
// In what election, this candidates have a part ?
$myNewVote->getLinks();
// Get Condorcet objects
$myNewVote->countLinks();
예제 #2
0
# -B- Change your mind ?
$election1->removeCandidate('A');
$election1->removeCandidate($myAutomaticCandidate);
// Lutoslawski change his name
$myLutoCandidate->setName('Wiltod Lutoslawski');
# Done !
# What was his old names?
$myLutoCandidate->getHistory();
// return the full history with timestamp of this Candidate naming
# -C- Check your candidate list, if you forget it
$election1->getCandidatesList();
// Return an array pupulate by each Candidate objet
$election1->getCandidatesList(true);
// 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 :