/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $election = new Election();
     $candidates = [1 => new Candidate('Bjørnar Moxnes'), 2 => new Candidate('Kari Elisabeth Kaski'), 3 => new Candidate('Lan Marie Nguyen Berg'), 4 => new Candidate('Abid Raja'), 5 => new Candidate('Per Sandberg')];
     foreach ($candidates as $candidate) {
         $election->addCandidate($candidate);
     }
     $votes = [[$candidates[1], $candidates[3], $candidates[2]], [$candidates[1], $candidates[3], $candidates[4]], [$candidates[1], $candidates[2], $candidates[4]], [$candidates[1], $candidates[2]], [$candidates[1], $candidates[2], $candidates[4]], [$candidates[5]], [$candidates[1], $candidates[2], $candidates[5]], [$candidates[1], $candidates[5]], [$candidates[1]], [$candidates[1]], [$candidates[2], $candidates[1], $candidates[3], $candidates[4]], [$candidates[2], $candidates[3], $candidates[4], $candidates[1], $candidates[5]], [$candidates[5], $candidates[4], $candidates[3]]];
     foreach ($votes as $vote) {
         $election->addVote($vote);
     }
     $result = $election->getResult('RankedPairs');
     Condorcet::format($result);
 }
declare (strict_types=1);
use Condorcet\Condorcet;
use Condorcet\Election;
ini_set('xdebug.var_display_max_depth', '-1');
ini_set('xdebug.var_display_max_children', '-1');
ini_set('xdebug.var_display_max_data', '-1');
ini_set('display_errors', '1');
error_reporting(E_ALL);
// Exeptions Handler
function exception_handler($exception)
{
    trigger_error($exception, E_USER_ERROR);
}
set_exception_handler('exception_handler');
require_once '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '__CondorcetAutoload.php';
$election = new Election();
// Inluding Data
require_once 'vote_data' . DIRECTORY_SEPARATOR . 'ComplexeVoteConf.php';
define('TEST_NAME', 'Condorcet Global Example');
// View :
?>
<!doctype html>
 <html>
 <head>
 	<meta charset="UTF-8">
 	<title><?php 
echo TEST_NAME;
?>
</title>

 	<style>
Exemple #3
0
 protected function makeUserResult(Election $election) : array
 {
     $userResult = [];
     foreach ($this->_Result as $key => $value) {
         if (is_array($value)) {
             foreach ($value as $candidate_key) {
                 $userResult[$key][] = $election->getCandidateId($candidate_key);
             }
         } elseif (is_null($value)) {
             $userResult[$key] = null;
         } else {
             $userResult[$key][] = $election->getCandidateId($value);
         }
     }
     foreach ($userResult as $key => $value) {
         if (is_null($value)) {
             $userResult[$key] = null;
         }
     }
     return $userResult;
 }
<?php

declare (strict_types=1);
/* NO INTERFACE here, see html examples for it */
# Quick tour of the main features of Condorcet PHP
// I - Install
use Condorcet\Condorcet;
use Condorcet\Election;
use Condorcet\Candidate;
use Condorcet\Vote;
$firstPart = '';
/* THE FOLLOWING CODE IS LIVE FOLLOWING THE FIRST PART EXPRESSED IN THE PREVIOUS FILE "1. Overview.php" */
require_once '1. Overview.php';
// VI - Play with Condorcet objects (Advanced)
// Create a second election
$election2 = new Election();
// Create three candidate : 'A', 'B' and 'C'
for ($i = 0; $i < 3; $i++) {
    $election2->addCandidate();
}
# Same candidate in multiple elections
// 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 ?
<?php

declare (strict_types=1);
/* NO INTERFACE here, see html examples for it */
# Quick tour of the main features of Condorcet PHP
// I - Install
use Condorcet\Condorcet;
use Condorcet\Election;
use Condorcet\Candidate;
use Condorcet\Vote;
require_once '../__CondorcetAutoload.php';
$start_time = microtime(TRUE);
// II - Create Election
$election1 = new Election();
// III - Manage Candidate
# -A- Add candidates
// A string
$election1->addCandidate('Debussy');
$election1->addCandidate('Caplet');
$election1->addCandidate('A');
$myLutoCandidate = $election1->addCandidate('Lutoslawski');
// Return the Condorcet\Candidate object.
// Automatic name
$myAutomaticCandidate = $election1->addCandidate();
// Return an automatic Condorcet\Candidate
$myAutomaticCandidate->getName();
// return 'B'. Because we have already register the A candidate above.
// An objet
$myMessiaenCandidate = new Candidate('Olivier Messiaen');
$election1->addCandidate($myMessiaenCandidate);
$election1->addCandidate(new Candidate('Ligeti'));
declare (strict_types=1);
use Condorcet\Condorcet;
use Condorcet\Election;
ini_set('xdebug.var_display_max_depth', '-1');
ini_set('xdebug.var_display_max_children', '-1');
ini_set('xdebug.var_display_max_data', '-1');
ini_set('display_errors', '1');
error_reporting(E_ALL);
// Exeptions Handler
function exception_handler($exception)
{
    trigger_error($exception, E_USER_ERROR);
}
set_exception_handler('exception_handler');
require_once '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '__CondorcetAutoload.php';
$election = new Election();
// Inluding Data
require_once 'vote_data' . DIRECTORY_SEPARATOR . 'BasicVoteConf.php';
define('TEST_NAME', 'Condorcet Bonus Example');
// View :
?>
<!doctype html>
 <html>
 <head>
 	<meta charset="UTF-8">
 	<title><?php 
echo TEST_NAME;
?>
</title>

 	<style>
<?php

/* NO INTERFACE here, see html examples for it */
# Quick tour of the main features of Condorcet PHP
// I - Install
use Condorcet\Condorcet;
use Condorcet\Election;
use Condorcet\Candidate;
use Condorcet\Vote;
use Condorcet\DataManager\DataHandlerDrivers\PdoHandlerDriver;
require_once '../../__CondorcetAutoload.php';
$start_time = microtime(TRUE);
// II - Create Election
$myElection = new Election();
$myElection->addCandidate(new Candidate('A'));
$myElection->addCandidate(new Candidate('B'));
$myElection->addCandidate(new Candidate('C'));
$myElection->addCandidate(new Candidate('D'));
$myElection->addCandidate(new Candidate('E'));
$myElection->addCandidate(new Candidate('F'));
// II - Setup external drivers
/* We will use PDO SQLITE, but can be MySQL or else */
unlink(__DIR__ . '/bdd.sqlite');
$pdo_object = new \PDO('sqlite:' . __DIR__ . '/bdd.sqlite');
$database_map = ['tableName' => 'Entitys', 'primaryColumnName' => 'id', 'dataColumnName' => 'data'];
$driver = new PdoHandlerDriver($pdo_object, true, $database_map);
// true = Try to create table
$myElection->setExternalDataHandler($driver);
// III - Add hundred of thousands votes
set_time_limit(60 * 5);
$howMany = 100000;