public function getVotesList($tag = null, bool $with = true) : array { if ($tag === null) { return $this->getFullDataSet(); } else { $tag = Vote::tagsConvert($tag); if ($tag === null) { $tag = []; } $search = []; foreach ($this as $key => $value) { $noOne = true; foreach ($tag as $oneTag) { if ($oneTag === $key || in_array($oneTag, $value->getTags(), true)) { if ($with) { $search[$key] = $value; break; } else { $noOne = false; } } } if (!$with && $noOne) { $search[$key] = $value; } } return $search; } }
public function removeVote($in, bool $with = true) : array { $rem = []; if ($in instanceof Vote) { $key = $this->getVoteKey($in); if ($key !== false) { $this->_Votes[$key]->destroyLink($this); $rem[] = $this->_Votes[$key]; unset($this->_Votes[$key]); } } else { // Prepare Tags $tag = Vote::tagsConvert($in); // Deleting foreach ($this->getVotesList($tag, $with) as $key => $value) { $this->_Votes[$key]->destroyLink($this); $rem[] = $this->_Votes[$key]; unset($this->_Votes[$key]); } } return $rem; }
$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 : $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