odea/application/controllers/DashboardController.php

227 lines
5.8 KiB
PHP
Raw Normal View History

2011-11-29 16:53:05 +01:00
<?php
2011-12-14 08:48:55 +01:00
/**
* Tableau de bord de gestion pour le client
* Permet de retrouver ces différents comptages et export
*
*/
2011-11-29 16:53:05 +01:00
class DashboardController extends Zend_Controller_Action
{
2012-01-05 15:31:42 +01:00
public function init()
{
$this->view->headScript()->appendFile('/themes/default/scripts/dashboard.js', 'text/javascript');
$this->view->headLink()->appendStylesheet('/themes/default/styles/dashboard.css');
2012-01-05 15:31:42 +01:00
}
2011-11-29 16:53:05 +01:00
2011-12-14 12:22:50 +01:00
/**
* Affiche le tableau de bord
*/
public function indexAction()
{
//Liste des derniers comptages
2012-01-05 14:59:50 +01:00
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
$db = Zend_Registry::get('db');
2012-01-05 14:59:50 +01:00
$criteresM = new Application_Model_Criteres($db);
$sql = $criteresM->select(true)
->columns(array('id', 'reference', 'dateAjout'))
->where("idClient = ?", $user->idClient)
->where("login = ?", $user->username)
->order('dateAjout DESC')
->limit(5);
$rows = $criteresM->fetchAll($sql);
$results = array();
$comptagesM = new Application_Model_Comptages($db);
foreach($rows->toArray() as $item)
{
$info = array(
'id' => $item['id'],
'reference' => $item['reference'],
'dateCriteres' => $item['dateAjout'],
);
//Recherche des comptages
$sql = $comptagesM->select(true)
->columns(array('resultat', 'uniteInsee', 'dateAjout'))
->where('idDefinition = ?', $item['id'])
->order('dateAjout DESC')->limit(1);
$comptage = $comptagesM->fetchAll($sql)->toArray();
if (count($comptage)>0){
$info['resultat'] = $comptage[0]['resultat'];
$info['uniteInsee'] = $comptage[0]['uniteInsee'];
$info['dateComptage'] = $comptage[0]['dateAjout'];
}
$results[] = $info;
}
$this->view->assign('comptages', $results);
//Rechercher un comptage
}
2011-11-29 16:53:05 +01:00
2012-01-05 14:59:50 +01:00
public function menuAction()
{
}
2011-12-14 12:22:50 +01:00
/**
* Affiche la liste des ciblages avec pagination
2011-12-14 12:22:50 +01:00
*/
public function ciblagesAction()
2012-01-05 14:59:50 +01:00
{
$request = $this->getRequest();
2012-01-05 16:40:03 +01:00
$page = $request->getParam('page', 1);
$offset = 20;
//Liste des ciblages par paquet de n
2012-01-05 14:59:50 +01:00
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
2012-01-05 16:40:03 +01:00
2012-01-05 14:59:50 +01:00
$db = Zend_Registry::get('db');
$criteresM = new Application_Model_Criteres($db);
2012-01-05 16:40:03 +01:00
//Compter le nombre de page
2012-01-05 14:59:50 +01:00
$sql = $criteresM->select()
2012-01-05 16:40:03 +01:00
->from($criteresM, array('nb' => 'COUNT(*)'))
->where("idClient = ?", $user->idClient)
->where("login = ?", $user->username);
$count = $criteresM->fetchRow($sql);
$nbCiblage = $count->nb;
//Récupérer les informations
$position = ($page-1)*$offset+1;
$sql = $criteresM->select()
->from($criteresM, array('id', 'reference', 'dateAjout'))
->where("idClient = ?", $user->idClient)
->where("login = ?", $user->username)
2012-01-05 14:59:50 +01:00
->order('dateAjout DESC')
2012-01-05 16:40:03 +01:00
->limitPage($position, $offset);
2012-01-05 14:59:50 +01:00
$rows = $criteresM->fetchAll($sql);
$results = array();
2012-01-05 16:40:03 +01:00
$comptagesM = new Application_Model_Comptages($db);
foreach($rows->toArray() as $item)
{
$info = array(
'id' => $item['id'],
'reference' => $item['reference'],
'dateCriteres' => $item['dateAjout'],
);
2012-01-05 14:59:50 +01:00
//Recherche des comptages
2012-01-05 16:40:03 +01:00
$sql = $comptagesM->select(true)
->columns(array('resultat', 'uniteInsee', 'dateAjout'))
2012-01-05 14:59:50 +01:00
->where('idDefinition = ?', $item['id'])
->order('dateAjout DESC')->limit(1);
2012-01-05 16:40:03 +01:00
$comptage = $comptagesM->fetchAll($sql)->toArray();
2012-01-05 14:59:50 +01:00
2012-01-05 16:40:03 +01:00
if (count($comptage)>0){
$info['resultat'] = $comptage[0]['resultat'];
$info['uniteInsee'] = $comptage[0]['uniteInsee'];
$info['dateComptage'] = $comptage[0]['dateAjout'];
}
$results[] = $info;
2012-01-05 14:59:50 +01:00
}
2012-01-05 16:40:03 +01:00
$this->view->assign('ciblages', $results);
$this->view->assign('nbCiblage', $nbCiblage);
2012-01-05 14:59:50 +01:00
}
2011-12-14 12:22:50 +01:00
/**
* Affiche le détail du comptage
* comptage multiple, fichier, etc....
*/
2012-01-05 17:21:25 +01:00
public function ciblagedetailAction()
{
$request = $this->getRequest();
$id = $request->getParam('id');
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
$db = Zend_Registry::get('db');
$criteresM = new Application_Model_Criteres($db);
$sql = $criteresM->select()
->where("idClient = ?", $user->idClient)
->where("login = ?", $user->username)
->where("id = ?", $id);
$criteres = $criteresM->fetchRow($sql);
$this->view->assign('criteres', $criteres->toArray());
if ($criteres != null){
$comptagesM = new Application_Model_Comptages($db);
$sql = $comptagesM->select()
->where('idDefinition = ?', $id);
$comptages = $comptagesM->fetchAll($sql);
$this->view->assign('comptages', $comptages->toArray());
}
}
2011-12-14 12:22:50 +01:00
/**
* Recherche un comptage avec la référence ou la date
*/
2012-01-05 16:40:03 +01:00
public function rcomptageAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$request = $this->getRequest();
$q = strtolower($this->getRequest()->getParam('q', ''));
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
2012-01-05 16:40:03 +01:00
$db = Zend_Registry::get('db');
2012-01-05 16:40:03 +01:00
$criteresM = new Application_Model_Criteres($db);
$sql = $criteresM->select()
->from($criteresM, array('id', 'reference', "DATE_FORMAT(dateAjout, '%d/%m/%Y') as date"))
->where("idClient = ?", $user->idClient)
->where("login = ?", $user->username)
->where("reference LIKE ?", $q.'%');
$rows = $criteresM->fetchAll($sql);
if (count($rows)>0){
$separator = " , ";
foreach ($rows as $item) {
$output[] = array(
'label' => $item->reference . $separator . $item->date,
'value' => $item->reference,
'url' => $this->view->url(array('controller'=>'dashboard', 'action'=>'ciblagedetail', 'id'=>$item->id)),
);
}
}
echo json_encode($output);
2012-01-05 16:40:03 +01:00
}
2011-11-29 16:53:05 +01:00
2012-01-11 10:30:04 +01:00
/**
* Gestion de la configuration de l'application
*/
public function configurationAction()
{
//Préférences
//Profil extraction
}
/**
* Liste des exportations simple non lié à un ciblage
*/
public function exportsAction()
{
}
2011-11-29 16:53:05 +01:00
}