odea/application/controllers/GestionController.php

166 lines
4.0 KiB
PHP
Raw Normal View History

2012-02-22 17:08:39 +00:00
<?php
class GestionController extends Zend_Controller_Action
{
public function preDispatch()
{
}
2012-05-02 19:06:36 +00:00
2012-02-24 09:54:21 +00:00
public function init()
{
2012-04-12 08:07:35 +00:00
$this->view->headLink()->appendStylesheet('/themes/default/styles/dashboard.css', 'all');
$this->view->headScript()->appendFile('/themes/default/scripts/dashboard.js', 'text/javascript');
2012-02-24 09:54:21 +00:00
}
2012-05-02 19:06:36 +00:00
2012-02-22 17:08:39 +00:00
public function indexAction()
{
2012-05-02 19:06:36 +00:00
2012-02-22 17:08:39 +00:00
}
2012-05-02 19:06:36 +00:00
2012-05-16 15:52:34 +00:00
/**
* Display profils to get data
* Filter with login and idClient
*
*/
2012-02-22 17:08:39 +00:00
public function profilsAction()
{
2012-05-16 15:52:34 +00:00
$request = $this->getRequest();
$login = $request->getParam('login', '');
$idClient = $request->getParam('idClient', null);
2012-05-02 19:06:36 +00:00
$profilsM = new Application_Model_EnrichissementProfils();
2012-05-16 15:52:34 +00:00
2012-02-24 09:54:21 +00:00
$sql = $profilsM->select()
->from($profilsM, array('id', 'idClient', 'login', 'reference', 'tarifLigne', 'dateAjout', 'dateSuppr', 'actif'));
2012-05-16 15:52:34 +00:00
if ( !empty($login) ) {
$sql->where('login = ?', $login.'%');
}
if ( $idClient!=null ) {
$sql->where('idClient = ?', $idClient);
}
2012-02-24 09:54:21 +00:00
$profils = $profilsM->fetchAll($sql);
2012-05-02 19:06:36 +00:00
2012-02-24 09:54:21 +00:00
$this->view->assign('profils', $profils);
2012-02-22 17:08:39 +00:00
}
2012-05-02 19:06:36 +00:00
2012-02-22 17:08:39 +00:00
public function profilAction(){}
2012-05-02 19:06:36 +00:00
2012-02-24 09:54:21 +00:00
public function profiladdAction()
{
$request = $this->getRequest();
//Sauvegarde du formulaire
2012-03-07 09:01:38 +00:00
if ( $request->isPost() && $request->getParam('submit')=='Enregistrer' ){
2012-03-06 15:02:50 +00:00
$params = $request->getParams();
2012-05-02 19:06:36 +00:00
2012-03-06 15:02:50 +00:00
//Vérifier le formulaire
$errForm = 0;
foreach ( $params as $key => $value ) {
if (empty($value)) {
$errForm++;
}
}
if (!$errForm) {
2012-03-06 16:24:28 +00:00
$dataInsee = 0;
2012-03-07 09:01:38 +00:00
// Est ce qu'il existe une donnée insee
2012-03-06 16:24:28 +00:00
require_once 'Scores/Enrichissement.php';
$fieldsM = new Enrichissement();
$fields = $fieldsM->getFields();
foreach ( $fields as $key => $val) {
2012-03-07 09:01:38 +00:00
if ( array_key_exists('insee', $val) && $val['insee']===true) {
2012-03-06 16:24:28 +00:00
$dateInsee = 1;
break;
}
2012-05-02 19:06:36 +00:00
}
2012-03-06 15:02:50 +00:00
$data = array(
'idClient' => $params['idClient'],
'login' => $params['login'],
'reference' => $params['reference'],
'criteres' => json_encode($params['criteres']),
'tarifLigne' => $params['tarifLigne'],
2012-03-06 16:24:28 +00:00
'dataInsee' => $dataInsee,
2012-03-06 15:02:50 +00:00
'dateAjout' => date('Y-m-d H:i:s'),
'actif' => 1,
);
2012-05-02 19:06:36 +00:00
$profilM = new Application_Model_EnrichissementProfils();
2012-03-06 15:02:50 +00:00
if ( $profilM->insert($data) ){
2012-05-02 19:06:36 +00:00
$this->view->assign('message', "Profil enregistré");
2012-03-06 15:02:50 +00:00
} else {
2012-05-02 19:06:36 +00:00
$this->view->assign('message', "Erreur lors de la sauvegarde");
}
2012-03-06 15:02:50 +00:00
} else {
2012-05-02 19:06:36 +00:00
$this->view->assign('message', "Erreur lors de la saisie");
}
2012-02-24 09:54:21 +00:00
}
2012-05-02 19:06:36 +00:00
2012-02-24 09:54:21 +00:00
//Affichage du formulaire
require_once 'Scores/Enrichissement.php';
$fieldsM = new Enrichissement();
2012-05-02 19:06:36 +00:00
$allFields = $fieldsM->getFields();
$this->view->assign('fields', $allFields);
2012-02-24 09:54:21 +00:00
}
2012-05-02 19:06:36 +00:00
2012-05-16 15:52:34 +00:00
/**
* Mark profil as deleted
*/
public function profildelAction()
{
}
2012-05-02 19:06:36 +00:00
2012-04-12 08:07:35 +00:00
public function comptagesAction()
{
2012-05-16 15:52:34 +00:00
$comptagesM = new Application_Model_Comptages();
$sql = $comptagesM->select()->setIntegrityCheck(false)
->from('comptages', array(
'comptages.idDefinition',
'comptages.resultat',
'comptages.uniteInsee',
"DATE_FORMAT(comptages.dateAjout, '%Y/%m/%d %H:%i:%s') as dateAjout"
))
->join('criteres', 'comptages.idDefinition = criteres.id', array('criteres.reference'))
->order('comptages.dateAjout DESC')
->group('criteres.id');
$comptages = $comptagesM->fetchAll($sql)->toArray();
Zend_Registry::get('firebug')->info($comptages);
$this->view->comptages = $comptages;
2012-04-12 08:07:35 +00:00
}
2012-05-02 19:06:36 +00:00
2012-04-12 08:07:35 +00:00
public function enrichissementsAction()
{
2012-05-02 19:06:36 +00:00
$table = new Application_Model_EnrichissementIdentifiants();
2012-04-12 08:07:35 +00:00
$sql = $table->select()
->order('dateAdded DESC');
$this->view->enrichissements = $table->fetchAll($sql)->toArray();
}
public function extractAction()
{
$id = $this->getRequest()->getParam('id');
2012-05-02 19:06:36 +00:00
$table = new Application_Model_EnrichissementIdentifiants();
2012-04-12 08:07:35 +00:00
$sql = $table->select()
->where('idComptage = ?', $id);
$result = $table->fetchRow($sql);
if(!empty($result)) {
$result = $result->toArray();
2012-05-16 15:52:34 +00:00
$sirets = json_decode($result['identifiants'], true);
2012-04-12 08:07:35 +00:00
foreach($sirets as $siret) {
echo $siret."\n";
}
}else {
echo 'Aucune commande d\'enrichissement sur ce comptage';
}
exit;
}
2012-02-22 17:08:39 +00:00
}