odea/application/controllers/IndexController.php
Michael RICOIS 16a517780c Formattage
2015-01-22 16:40:18 +00:00

142 lines
4.3 KiB
PHP

<?php
class IndexController extends Zend_Controller_Action
{
public function indexAction()
{
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
if ($user->customisation) {
$this->view->assign('preferences', $user->customisation);
}
}
/**
* Affichage des éléments de sélection avec leur valeurs
*/
public function criteresAction()
{
$request = $this->getRequest();
if ( $request->isXmlHttpRequest() ) {
$this->_helper->layout()->disableLayout();
}
//Informations utilisateur
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
$fields = new Scores_Ciblage_FieldList();
$sessionValue = new Scores_Ciblage_Session($fields);
//Nombre d'unités
$total = $request->getParam('total');
if ( $total !== null ) {
$this->view->dataCount = number_format($total, 0, '', ' ');
} else {
//@todo : total quand aucune sélection
$this->view->dataCount = number_format($sessionValue->getCountTotal(), 0, '', ' ');
}
$insee = $request->getParam('insee');
if ( $insee !== null ) {
$this->view->dataInsee = number_format($insee, 0, '', ' ');
} else {
if ( $user->preferences['interface']['insee'] == 1 ) {
$insee = number_format($sessionValue->getCountInsee(), 0, '', ' ');
} else {
$insee = null;
}
}
//Construction affichage des critères
$infosCriteres = array();
$allFields = $fields->getItems(true);
foreach ( $allFields as $key => $params ) {
$valueSelected = $sessionValue->getSelectedValue($key);
if ( $valueSelected !== null ) {
$resultLabel = $sessionValue->resumeLabel($key);
$infosCriteres[$key] = array(
'label' => $params['label'],
'in' => $resultLabel['in'],
'ex' => $resultLabel['ex'],
);
}
}
Zend_Registry::get('firebug')->info($infosCriteres);
$this->view->infos = $infosCriteres;
}
public function criterelistAction()
{
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
$key = $request->getParam('key');
$fields = new Scores_Ciblage_FieldList();
$sessionValue = new Scores_Ciblage_Session($fields);
$values = $sessionValue->getSelectedValue($key);
$inLabels = array();
if (count($values['in'])>0) {
foreach ($values['in'] as $value) {
$inLabels[$value] = $fields->labelValueDetail($key, $value);
}
}
$exLabels = array();
if (count($values['ex'])>0) {
foreach ($values['ex'] as $value) {
$exLabels[$value] = $fields->labelValueDetail($key, $value);
}
}
Zend_Registry::get('firebug')->info('LABEL');
Zend_Registry::get('firebug')->info($inLabels);
$this->view->critereName = $key;
$this->view->inLabels = $inLabels;
$this->view->exLabels = $exLabels;
}
public function removeAction()
{
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
$nameCritereToDelete = $request->getParam('critere');
$posInList = $request->getParam('in', false);
$posExList = $request->getParam('ex', false);
$sessionValue = new Scores_Ciblage_Session();
if ($posInList!==false) {
$sessionValue->unsetSelectedValue($nameCritereToDelete, $posInList);
} elseif ($posExList!==false) {
$sessionValue->unsetSelectedValue($nameCritereToDelete, $posInList, true);
} else {
$sessionValue->unsetSelected($nameCritereToDelete);
}
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
//Comptage
$ciblage = new Scores_Ciblage_Engine($sessionValue->getSelectedValues(), $user->globalRNCS);
$total = $ciblage->execute();
$sessionValue->setCountTotal($total);
if ($user->preferences['interface']['insee']==1) {
$insee = $ciblage->calculRedevanceInsee();
} else {
$insee = null;
}
$sessionValue->setCountInsee($insee);
$sessionValue->setCritereSession();
$this->_redirect('/');
}
}