odea/application/controllers/GestionController.php
Michael RICOIS 220641782d Redesign
2012-05-22 06:10:32 +00:00

234 lines
5.7 KiB
PHP

<?php
class GestionController extends Zend_Controller_Action
{
public function preDispatch()
{
}
public function init()
{
$this->view->headLink()->appendStylesheet('/themes/default/styles/dashboard.css', 'all');
$this->view->headScript()->appendFile('/themes/default/scripts/dashboard.js', 'text/javascript');
}
/**
* Display all links
*/
public function indexAction()
{
}
/**
* Display profils to get data
* Filter with login and idClient
*
*/
public function profilsAction()
{
$request = $this->getRequest();
$login = $request->getParam('login', '');
$idClient = $request->getParam('idClient', null);
$profilsM = new Application_Model_EnrichissementProfils();
$sql = $profilsM->select()
->from($profilsM, array('id', 'idClient', 'login', 'reference', 'tarifLigne', 'dateAjout', 'dateSuppr', 'actif'));
if ( !empty($login) ) {
$sql->where('login = ?', $login.'%');
}
if ( $idClient!=null ) {
$sql->where('idClient = ?', $idClient);
}
$profils = $profilsM->fetchAll($sql);
$this->view->assign('profils', $profils);
}
/**
* Define fields for extraction to user
*/
public function profiladdAction()
{
$request = $this->getRequest();
//Sauvegarde du formulaire
if ( $request->isPost() && $request->getParam('submit')=='Enregistrer' ){
$params = $request->getParams();
//Vérifier le formulaire
$errForm = 0;
foreach ( $params as $key => $value ) {
if (empty($value)) {
$errForm++;
}
}
if (!$errForm) {
$dataInsee = 0;
// Est ce qu'il existe une donnée insee
require_once 'Scores/Enrichissement.php';
$fieldsM = new Enrichissement();
$fields = $fieldsM->getFields();
foreach ( $fields as $key => $val) {
if ( array_key_exists('insee', $val) && $val['insee']===true) {
$dateInsee = 1;
break;
}
}
$data = array(
'idClient' => $params['idClient'],
'login' => $params['login'],
'reference' => $params['reference'],
'criteres' => json_encode($params['criteres']),
'tarifLigne' => $params['tarifLigne'],
'dataInsee' => $dataInsee,
'dateAjout' => date('Y-m-d H:i:s'),
'actif' => 1,
);
$profilM = new Application_Model_EnrichissementProfils();
if ( $profilM->insert($data) ){
$this->view->assign('message', "Profil enregistré");
} else {
$this->view->assign('message', "Erreur lors de la sauvegarde");
}
} else {
$this->view->assign('message', "Erreur lors de la saisie");
}
}
//Affichage du formulaire
require_once 'Scores/Enrichissement.php';
$fieldsM = new Enrichissement();
$allFields = $fieldsM->getFields();
$this->view->assign('fields', $allFields);
}
/**
* Mark profil as deleted
*/
public function profildelAction()
{
}
/**
* List commands which must be done
*/
public function commandesAction()
{
$request = $this->getRequest();
$commandesM = new Application_Model_EnrichissementIdentifiants();
$sql = $commandesM->select()->setIntegrityCheck(false)
->from('enrichissement_identifiants AS e', array(
'e.id',
'e.reference AS commandeReference',
'e.nbLigneTotales',
'e.uniteInsee',
"DATE_FORMAT(e.dateAdded, '%Y/%m/%d %H:%i:%s') AS dateAdded"
))
->join('criteres', 'idCriteres = criteres.id', array(
'criteres.reference AS critereReference',
'criteres.login',
))
->where('e.dateStart = ?', "0000-00-00 00:00:00")
->where('fichier = ""')
->order('e.dateAdded DESC');
$this->view->commandes = $commandesM->fetchAll($sql)->toArray();
}
/**
* List commands with a file
*/
public function enrichissementsAction()
{
$commandesM = new Application_Model_EnrichissementIdentifiants();
$sql = $commandesM->select()->setIntegrityCheck(false)
->from('enrichissement_identifiants AS e', array(
'e.id',
'e.reference AS commandeReference',
'e.nbLigneTotales',
'e.uniteInsee',
"DATE_FORMAT(e.dateAdded, '%Y/%m/%d %H:%i:%s') AS dateAdded"
))
->join('criteres', 'idCriteres = criteres.id', array(
'criteres.reference AS critereReference',
'criteres.login',
))
->where('fichier != ""')
->order('e.dateAdded DESC');
$this->view->commandes = $commandesM->fetchAll($sql)->toArray();
}
/**
* Load enrichissement batch to complete data
*/
public function enrichitAction()
{
$request = $this->getRequest();
$id = $request->getParam('id');
exec('php '.APPLICATION_PATH.'/../batch/enrichissement.php --id '.$id.' &');
}
/**
* Extract sirets from database
* @todo : To csv file
*/
public function siretscsvAction()
{
$id = $this->getRequest()->getParam('id');
$table = new Application_Model_EnrichissementIdentifiants();
$sql = $table->select()
->where('idComptage = ?', $id);
$result = $table->fetchRow($sql);
if(!empty($result)) {
$result = $result->toArray();
$sirets = json_decode($result['identifiants'], true);
foreach($sirets as $siret) {
echo $siret."\n";
}
}else {
echo 'Aucune commande d\'enrichissement sur ce comptage';
}
exit;
}
/**
* List criteres and the last count
*/
public function ciblagesAction()
{
$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;
}
}