odea/application/controllers/GestionController.php

371 lines
9.6 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-05-22 06:10:32 +00:00
/**
* Display all links
*/
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-05-22 06:10:32 +00:00
/**
* Define fields for extraction to user
*/
2012-02-24 09:54:21 +00:00
public function profiladdAction()
{
$request = $this->getRequest();
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
//Get default profil
$profilClientM = new Application_Model_CustomerParams();
$profilClient = $profilClientM->find($request->getParam('idClient'));
2012-02-24 09:54:21 +00:00
//Sauvegarde du formulaire
if ( $request->isPost() ){
2012-03-06 15:02:50 +00:00
$params = $request->getParams();
2012-05-02 19:06:36 +00:00
if ($params['reference']=='default') {
$params['criteres'] = json_decode($profilClient->current()->criteres,true);
2012-03-06 15:02:50 +00:00
}
2012-05-02 19:06:36 +00:00
$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;
2012-05-02 19:06:36 +00:00
}
}
$data = array(
'idClient' => $params['idClient'],
'service' => $params['service'],
'login' => $params['login'],
'reference' => $params['reference'],
'criteres' => json_encode($params['criteres']),
'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é");
$this->view->assign('disableForm', true);
2012-03-06 15:02:50 +00:00
} else {
$this->view->assign('message', "Erreur lors de la sauvegarde");
2012-05-02 19:06:36 +00:00
}
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-05-22 06:10:32 +00:00
/**
* 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',
2012-06-19 15:18:52 +00:00
"DATE_FORMAT(e.dateAdded, '%Y/%m/%d %H:%i:%s') AS dateAdded",
'e.fichier'
2012-05-22 06:10:32 +00:00
))
->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.' &');
}
/**
2012-06-01 10:30:44 +00:00
* Extract only SIRETs from database
2012-05-22 06:10:32 +00:00
* @todo : To csv file
*/
2012-06-01 10:30:44 +00:00
public function extractAction()
2012-05-22 06:10:32 +00:00
{
$id = $this->getRequest()->getParam('id');
$table = new Application_Model_EnrichissementIdentifiants();
2012-06-01 10:30:44 +00:00
$sql = $table->select()->where('idComptage = ?', $id);
2012-05-22 06:10:32 +00:00
$result = $table->fetchRow($sql);
if(!empty($result)) {
$result = $result->toArray();
$sirets = json_decode($result['identifiants'], true);
2012-06-01 10:30:44 +00:00
$content = '';
2012-05-22 06:10:32 +00:00
foreach($sirets as $siret) {
2012-06-01 10:30:44 +00:00
$content.= $siret.",";
}
$this->view->assign('content', $content);
2012-05-22 06:10:32 +00:00
}else {
2012-06-01 10:30:44 +00:00
$this->view->assign('message', 'Aucune commande d\'enrichissement sur ce comptage');
}
2012-05-22 06:10:32 +00:00
}
/**
* List criteres and the last count
*/
public function ciblagesAction()
2012-04-12 08:07:35 +00:00
{
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
/**
* List customers
*/
public function customerparamsAction()
{
//@todo : what's in database
$customersM = new Application_Model_CustomerParams();
$sql = $customersM->select()
->from($customersM,array('idClient', 'service' , 'dateContrat', 'periodContrat'))
->order('dateAdded DESC')
->group('idClient');
$customers = $customersM->fetchAll($sql)->toArray();
//List login
$customerlist = array();
$profilsM = new Application_Model_EnrichissementProfils();
foreach($customers as $item) {
$sql = $profilsM->select()
->from($profilsM, array('login'))
->where('idClient=?',$item['idClient']);
$result = $profilsM->fetchAll($sql)->toArray();
$logins = array();
if (count($result)>0) {
foreach($result as $login) {
$logins[] = $login['login'];
}
}
$item['logins'] = $logins;
$customerlist[] = $item;
}
$this->view->assign('customerlist', $customerlist);
}
/**
* List customer's params
*/
public function customerparamAction()
{
$request = $this->getRequest();
$idClient= $request->getParam('id', null);
if ($idClient !== null) {
$paramsM = new Application_Model_CustomerParams();
$params = $paramsM->find($idClient);
$infos = null;
if ($params->count()>0){
$infos = $params->toArray();
}
$this->view->assign('infos',$infos[0]);
$loginsM = new Application_Model_EnrichissementProfils();
$sql = $loginsM->select()->where('idClient = ?', $idClient);
$logins = $loginsM->fetchAll($sql)->toArray();
$this->view->assign('logins', $logins);
}
}
public function customerparamaddAction()
{
//Fields
require_once 'Scores/Enrichissement.php';
$fieldsM = new Enrichissement();
$allFields = $fieldsM->getFields();
$this->view->assign('fields', $allFields);
$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 ($value=='' && $key!='service') {
$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;
}
}
$checkValues = array(
'filterRNCS' => 0,
'licenceINSEE' => 0,
'immediatExtract' => 0,
);
foreach ($checkValues as $key => $value) {
if (!array_key_exists($key, $params)) {
$params[$key] = $value;
}
}
$data = array(
'idClient' => $params['idClient'],
'service' => $params['service'],
'filterRNCS' => $params['filterRNCS'],
'licenceINSEE' => $params['licenceINSEE'],
'immediatExtract' => $params['immediatExtract'],
'dateContrat' => $params['dateContrat'],
'periodContrat' => $params['periodContrat'],
'periodPaiement' => $params['periodPaiement'],
'priceLine' => $params['priceLine'],
'forfait' => $params['forfait'],
'limitLines' => $params['limitLines'],
'limitFiles' => $params['limitFiles'],
'criteres' => json_encode($params['criteres']),
'dataInsee' => $dataInsee,
'dateAdded' => date('Y-m-d H:i:s'),
);
$customerParamsM = new Application_Model_CustomerParams();
if ( $customerParamsM->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");
}
}
}
2012-02-22 17:08:39 +00:00
}