Skip to content
Snippets Groups Projects
Commit 509b76b9 authored by lecluse's avatar lecluse
Browse files

Optimisation : la liste des années courante en session

parent bc60a025
Branches
Tags
No related merge requests found
......@@ -12,6 +12,7 @@ use Application\Entity\Db\Annee as AnneeEntity;
*/
class Annee extends AbstractEntityService
{
use \Application\Traits\SessionContainerTrait;
/**
* retourne la classe des entités
......@@ -103,6 +104,9 @@ class Annee extends AbstractEntityService
*/
public function getChoixAnnees()
{
$session = $this->getSessionContainer();
if (! isset($session->choixAnnees)){
$sql = 'SELECT DISTINCT
annee_id
FROM
......@@ -114,12 +118,13 @@ class Annee extends AbstractEntityService
$stmt = $this->getEntityManager()->getConnection()->executeQuery($sql);
$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$annees = [];
$session->choixAnnees = [];
foreach( $result as $annee ){
$a = $annee['ANNEE_ID'];
$annees[$a] = $a.'-'.($a+1);
$session->choixAnnees[$a] = $a.'-'.($a+1);
}
}
return $annees;
return $session->choixAnnees;
}
}
\ No newline at end of file
<?php
namespace Application\Traits;
use Zend\Session\Container as SessionContainer;
trait SessionContainerTrait {
private $sessionContainer;
/**
*
* @return SessionContainer
*/
public function getSessionContainer()
{
if (null === $this->sessionContainer) {
$this->sessionContainer = new SessionContainer( get_class($this) );
}
return $this->sessionContainer;
}
/**
*
* @param SessionContainer $sessionContainer
* @return self
*/
public function setSessionContainer(SessionContainer $sessionContainer)
{
$this->sessionContainer = $sessionContainer;
return $this;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment