public function testCanHaveInscritsAndVotantsAndExprimes() { $voteInfo = new VoteInfo(1000, 500, 250); $this->assertEquals(1000, $voteInfo->getInscrits()); $this->assertEquals(500, $voteInfo->getVotants()); $this->assertEquals(250, $voteInfo->getExprimes()); }
/** * Récupérer les VoteInfo (exprimés votants etc.) d'une échéance sur * un territoire. Avec des vrais morceaux de mise en cache inside. * * @param Echeance $echeance [description] * @param [type] $territoire [description] * * @return [type] [description] */ public function getVoteInfo(Echeance $echeance, $territoire) { if (is_array($territoire) || $territoire instanceof \ArrayAccess || $territoire instanceof \IteratorAggregate) { $exprimes = 0; $votants = 0; $inscrits = 0; foreach ($territoire as $division) { $voteInfoVO = $this->getVoteInfo($echeance, $division); if ($voteInfoVO) { $exprimes += $voteInfoVO->getExprimes(); $votants += $voteInfoVO->getVotants(); $inscrits += $voteInfoVO->getInscrits(); } } if (!$exprimes && !$votants && !$inscrits) { return new VoteInfo(null, null, null); } $voteInfo = new VoteInfo($inscrits, $votants, $exprimes); } if (isset($this->cache['getVoteInfo'][$echeance]) && isset($this->cache['getVoteInfo'][$echeance][$territoire])) { return $this->cache['getVoteInfo'][$echeance][$territoire]; } if (!isset($voteInfo) || !$voteInfo || !$voteInfo->getExprimes()) { $voteInfo = $this->doVoteInfoQuery($echeance, $territoire); } if (!$voteInfo || !$voteInfo->getExprimes()) { if ($territoire instanceof Region) { $voteInfo = $this->doVoteInfoRegionQuery($echeance, $territoire); } if ($territoire instanceof Departement) { $voteInfo = $this->doVoteInfoDepartementQuery($echeance, $territoire); } if ($territoire instanceof CirconscriptionEuropeenne) { $voteInfo = $this->doVoteInfoCircoEuroQuery($echeance, $territoire); } if ($territoire instanceof Pays) { $voteInfo = $this->getVoteInfo($echeance, $territoire->getCirconscriptionsEuropeennes()); } } if (!isset($this->cache['getVoteInfo'][$echeance])) { $this->cache['getVoteInfo'][$echeance] = new \SplObjectStorage(); } $this->cache['getVoteInfo'][$echeance][$territoire] = $voteInfo; return $voteInfo; }