142 lines
2.9 KiB
PHP
142 lines
2.9 KiB
PHP
<?php
|
|
class SessionCiblage
|
|
{
|
|
protected $valeur;
|
|
protected $total = null;
|
|
protected $insee = null;
|
|
|
|
public function __construct()
|
|
{
|
|
$session = new Zend_Session_Namespace('ciblage');
|
|
$this->valeur = empty($session->ciblage) ? array() : $session->ciblage;
|
|
if (isset($this->valeur['NB']['total'])){ $this->total = $this->valeur['NB']['total']; }
|
|
if (isset($this->valeur['NB']['insee'])){ $this->insee = $this->valeur['NB']['insee']; }
|
|
if (isset($this->valeur['NB'])){ unset($this->valeur['NB']); }
|
|
}
|
|
|
|
/**
|
|
* Enregistre les informations dans la session
|
|
*/
|
|
protected function setSession()
|
|
{
|
|
$session = new Zend_Session_Namespace('ciblage');
|
|
$this->valeur['NB']['total'] = $this->total;
|
|
$this->valeur['NB']['insee'] = $this->insee;
|
|
$session->ciblage = $this->valeur;
|
|
}
|
|
|
|
/**
|
|
* Enregistre un critère et sa valeur
|
|
* @param unknown_type $key
|
|
* @param unknown_type $value
|
|
*/
|
|
public function setCritere($key, $value)
|
|
{
|
|
$this->valeur[$key] = $value;
|
|
$this->setSession();
|
|
}
|
|
|
|
/**
|
|
* Définir les critères en une fois
|
|
* @param array $criteres
|
|
*/
|
|
public function setCriteres($criteres)
|
|
{
|
|
$this->valeur = $criteres;
|
|
$this->setSession();
|
|
}
|
|
|
|
/**
|
|
* Désactivation d'un critère
|
|
* @param unknown_type $key
|
|
*/
|
|
public function unsetCritere($key)
|
|
{
|
|
if(key_exists($key, $this->valeur)) {
|
|
unset($this->valeur[$key]);
|
|
$this->setSession();
|
|
}
|
|
}
|
|
|
|
public function unsetCritereValue($key, $valeur) {
|
|
if(key_exists($key, $this->valeur)) {
|
|
$don = explode(',', $this->valeur[$key]);
|
|
foreach ($don as $val) {
|
|
if($val == $valeur)
|
|
$don[key($don)] = '';
|
|
else
|
|
$new[] = $val;
|
|
}
|
|
if(count($new)>0)
|
|
{
|
|
$don = implode(',', $new);
|
|
if(!empty($don))
|
|
$this->valeur[$key] = $don;
|
|
} else {
|
|
unset($this->valeur[$key]);
|
|
}
|
|
$this->setSession();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Récupération de la valeur d'un critère
|
|
* @param unknown_type $key
|
|
*/
|
|
public function getCritere($key)
|
|
{
|
|
if(array_key_exists($key, $this->valeur)) {
|
|
return $this->valeur[$key];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Récupération des critères et de leurs valeurs
|
|
*/
|
|
public function getCriteres()
|
|
{
|
|
return $this->valeur;
|
|
}
|
|
|
|
/**
|
|
* Définit un élément de comptage
|
|
* @param unknown_type $element
|
|
* @param unknown_type $nb
|
|
*/
|
|
public function setNb($element, $nb)
|
|
{
|
|
$this->{$element} = $nb;
|
|
$this->setSession();
|
|
}
|
|
|
|
/**
|
|
* Récupére la valeur d'un élément de comptage
|
|
* @param unknown_type $element
|
|
*/
|
|
public function getNb($element)
|
|
{
|
|
return $this->{$element};
|
|
}
|
|
|
|
public function resetFamille($famille)
|
|
{
|
|
require_once('Field.php');
|
|
$fields = new Fields(null);
|
|
$reference = $fields->getByFamille($famille);
|
|
foreach($this->valeur as $name => $valeur) {
|
|
if($name != 'null') {
|
|
if(array_key_exists($name, $reference)) {
|
|
unset($this->valeur[$name]);
|
|
}
|
|
}
|
|
}
|
|
$this->setSession();
|
|
}
|
|
|
|
public function clearCiblage()
|
|
{
|
|
Zend_Session::namespaceUnset('ciblage');
|
|
}
|
|
|
|
} |