odea/application/controllers/DashboardController.php

428 lines
14 KiB
PHP
Raw Normal View History

2012-02-02 17:29:14 +00:00
<?php
2012-05-02 18:19:07 +00:00
class DashboardController extends Zend_Controller_Action
2012-02-02 17:29:14 +00:00
{
public function init()
{
2012-02-15 11:29:00 +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-02 17:29:14 +00:00
}
public function indexAction()
{
2012-05-16 15:52:34 +00:00
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
$criteresM = new Application_Model_Criteres();
$sql = $criteresM->select()
->from($criteresM, array('id', 'reference', 'dateAjout'))
->where("idClient = ?", $user->idClient)
->where("login = ?", $user->username)
->order('dateAjout DESC')
->limit(5);
$rows = $criteresM->fetchAll($sql);
2012-05-17 19:44:16 +00:00
//
2012-05-16 15:52:34 +00:00
$results = array();
$comptagesM = new Application_Model_Comptages();
foreach($rows->toArray() as $item)
{
$info = array(
'id' => $item['id'],
'reference' => $item['reference'],
'dateCriteres' => $item['dateAjout'],
);
//Recherche des comptages
$sql = $comptagesM->select()
->from($comptagesM, array('resultat', 'uniteInsee', "DATE_FORMAT(dateAjout, '%Y/%m/%d %H:%i:%s') as 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;
}
2012-05-02 18:19:07 +00:00
2012-05-16 15:52:34 +00:00
$this->view->comptages = $results;
2012-05-17 19:44:16 +00:00
//
2012-05-16 15:52:34 +00:00
$enrichissements = new Application_Model_EnrichissementIdentifiants();
$sql = $enrichissements->select()
->setIntegrityCheck(false)
->from(
array('i' => 'enrichissement_identifiants'),
array('id', 'reference', 'fichier', 'nbLigneTotales', 'nbLigneTraites', 'error', 'dateAdded', 'dateStart', 'dateStop')
)
->join(
array('c' => 'ciblage_criteres'), 'i.idCriteres = c.id',
2012-05-16 15:52:34 +00:00
array('')
)
2012-05-17 19:44:16 +00:00
->where('c.idClient = ?', $user->idClient)
->where('c.login = ?', $user->username)
->order('i.dateAdded DESC');
2012-05-16 15:52:34 +00:00
$this->view->enrichissements = $enrichissements->fetchAll($sql);
2012-05-02 18:19:07 +00:00
2012-02-02 17:29:14 +00:00
}
public function ciblagesAction()
{
2012-05-16 15:52:34 +00:00
2012-02-02 17:29:14 +00:00
$request = $this->getRequest();
2012-05-16 15:52:34 +00:00
$page = $request->getParam('page', 1);
$offset = 20;
//Liste des ciblages par paquet de n
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
$criteresM = new Application_Model_Criteres();
//Compter le nombre de page
$sql = $criteresM->select()
->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)
->order('dateAjout DESC')
->limitPage($position, $offset);
$rows = $criteresM->fetchAll($sql);
$results = array();
$comptagesM = new Application_Model_Comptages();
foreach($rows->toArray() as $item)
{
$info = array(
'id' => $item['id'],
'reference' => $item['reference'],
'dateCriteres' => $item['dateAjout'],
);
//Recherche des comptages
$sql = $comptagesM->select()
->from($comptagesM, array('resultat', 'uniteInsee', "DATE_FORMAT(dateAjout, '%d/%m/%Y %H:%i:%s') as 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->ciblages = $results;
$this->view->nbCiblage = $nbCiblage;
2012-02-02 17:29:14 +00:00
}
public function ciblageAction()
2012-02-02 17:29:14 +00:00
{
$request = $this->getRequest();
2012-05-15 11:38:51 +00:00
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
$comptageId = $request->getParam('id');
$fields = new Scores_Fields();
//Lecture des paramètres du ciblage
$criteresM = new Application_Model_Criteres();
$sql = $criteresM->select()
->where('idClient = ?', $user->idClient)
->where('login = ?', $user->username)
->where('id = ?', $comptageId);
$criteres = $criteresM->fetchRow($sql)->toArray();
2012-06-26 14:25:43 +00:00
2012-05-15 11:38:51 +00:00
$infosCriteres = array();
if ($criteres != null) {
2012-06-26 14:25:43 +00:00
$comptageRef = $criteres['reference'];
2012-05-15 11:38:51 +00:00
$decodeCriteres = json_decode($criteres['criteres'], true);
//Construction affichage des critères
foreach ( $decodeCriteres as $key => $item ) {
2012-05-22 06:10:32 +00:00
$inValue = $fields->getValueLabel($key, $item['in']);
$exValue = $fields->getValueLabel($key, $item['ex']);
2012-05-15 11:38:51 +00:00
//Add label to struct for display
$infosCriteres[] = array(
'label' => $fields->getLabel($key),
2012-05-22 06:10:32 +00:00
'in' => $inValue,
'ex' => $exValue,
2012-05-15 11:38:51 +00:00
);
}
//Lecture des comptages
$comptageM = new Application_Model_Comptages();
$sql = $comptageM->select()
->where('idDefinition = ?', $comptageId)
->order('dateAjout DESC');
$comptages = $comptageM->fetchAll($sql)->toArray();
//Lecture enrichissement existe
2012-06-26 14:25:43 +00:00
$enrichissementsM = new Application_Model_EnrichissementIdentifiants();
$sql = $enrichissementsM->select()
->where('idCriteres = ?', $comptageId);
$enrichissements = $enrichissementsM->fetchAll($sql);
2012-05-15 11:38:51 +00:00
//Affichage
2012-06-26 14:25:43 +00:00
$this->view->comptageId = $comptageId;
$this->view->comptageRef = $comptageRef;
2012-05-15 11:38:51 +00:00
$this->view->criteres = $infosCriteres;
$this->view->comptages = $comptages;
2012-06-26 14:25:43 +00:00
$this->view->enrichissements = $enrichissements;
2012-05-15 11:38:51 +00:00
}
2012-02-02 17:29:14 +00:00
}
public function rcomptageAction()
{
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
2012-05-02 18:19:07 +00:00
2012-02-02 17:29:14 +00:00
$request = $this->getRequest();
2012-02-15 10:35:07 +00:00
$q = $request->getParam('q');
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
2012-05-02 18:19:07 +00:00
2012-05-02 19:06:36 +00:00
$criteresM = new Application_Model_Criteres();
2012-02-15 10:35:07 +00:00
$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'=>'ciblage', 'id'=>$item->id)),
2012-02-15 10:35:07 +00:00
);
}
}
echo json_encode($output);
2012-02-02 17:29:14 +00:00
}
/**
* Liste des enrichissements
*/
public function enrichissementsAction()
2012-02-02 17:29:14 +00:00
{
2012-02-24 16:26:20 +00:00
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
//Criteres => Comptages (last) => enrichissement_identifiants => enrichissement_commandes
2012-05-02 19:06:36 +00:00
$enrichissementsM = new Application_Model_EnrichissementIdentifiants();
2012-02-24 15:32:15 +00:00
2012-05-16 15:52:34 +00:00
// Pending
2012-02-24 15:32:15 +00:00
$sql = $enrichissementsM->select()
->setIntegrityCheck(false)
->from(
2012-02-24 16:26:20 +00:00
array('i' => 'enrichissement_identifiants'),
array('id', 'reference', 'fichier', 'nbLigneTotales', 'nbLigneTraites', 'error', 'dateAdded', 'dateStart', 'dateStop')
2012-02-24 15:32:15 +00:00
)
2012-04-05 08:19:57 +00:00
->join(
2012-09-10 08:08:53 +00:00
array('c' => 'ciblage_comptages'), 'i.idComptage = c.id',
2012-02-24 16:26:20 +00:00
array('')
)
2012-04-05 08:19:57 +00:00
->join(
2012-09-10 08:08:53 +00:00
array('criteres' => 'ciblage_criteres'), 'i.idCriteres = criteres.id',
2012-02-24 16:26:20 +00:00
array('')
2012-02-24 17:11:41 +00:00
);
$sql->where('i.dateStop = ?', 0)
2012-02-24 16:26:20 +00:00
->where('criteres.idClient = ?', $user->idClient)
->where('criteres.login = ?', $user->username);
2012-02-24 15:32:15 +00:00
$encours = $enrichissementsM->fetchAll($sql);
2012-04-05 08:19:57 +00:00
$this->view->encours = $encours;
2012-05-02 18:19:07 +00:00
2012-04-05 08:19:57 +00:00
// Impossible de copie la varible issu d'un select car sinon elle conserve les meme propriété que sont parent
// donc les selects... donc obliger de faire deux requetes pour le moment.
$sql = $enrichissementsM->select()
->setIntegrityCheck(false)
->from(
array('i' => 'enrichissement_identifiants'),
array('id', 'reference', 'fichier', 'nbLigneTotales', 'nbLigneTraites', 'error', 'dateAdded', 'dateStart', 'dateStop')
)
->join(
2012-09-10 08:08:53 +00:00
array('c' => 'ciblage_comptages'), 'i.idComptage = c.id',
2012-04-05 08:19:57 +00:00
array('')
)
->join(
2012-09-10 08:08:53 +00:00
array('criteres' => 'ciblage_criteres'), 'i.idCriteres = criteres.id',
2012-04-05 08:19:57 +00:00
array('')
);
$sql->where('criteres.idClient = ?', $user->idClient)
->where('criteres.login = ?', $user->username)
->where('i.dateStart != ?', '0000-00-00 00:00:00');
$fini = $enrichissementsM->fetchAll($sql)->toArray();
$this->view->fini = $fini;
2012-04-12 09:25:37 +00:00
$this->view->pathfile = $config->path->data;
2012-02-02 17:29:14 +00:00
}
/**
* Détail d'un enrichissment
*/
public function enrichissementAction()
{
2012-05-02 18:19:07 +00:00
}
2012-05-25 13:24:30 +00:00
2012-05-28 12:46:52 +00:00
/**
* Display information about user's profil
*/
2012-05-25 13:24:30 +00:00
public function configurationAction()
{
//User's params
2012-05-28 15:17:18 +00:00
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
if (array_key_exists('filter', $user->preferences) && count($user->preferences['filter'])>0) {
$liste = $user->preferences['filter'];
foreach ( $liste as $name => $value ){
$this->view->assign('prefFilter'.ucfirst($name), $value);
}
}
if (array_key_exists('interface', $user->preferences) && count($user->preferences['interface'])>0) {
$liste = $user->preferences['interface'];
foreach ( $liste as $name => $value ){
$this->view->assign('prefInterface'.ucfirst($name), $value);
}
}
2012-09-10 09:34:14 +00:00
$timestamp = strtotime( $user->dateContrat );
$dateBegin = date( 'd/m/Y', $timestamp );
$timestamp = mktime(0,0,0,substr($dateBegin,3,2)+$user->periodContrat,substr($dateBegin,0,2), substr($dateBegin,6,4));
$dateEnd = date( 'd/m/Y', $timestamp );
$this->view->assign('dateBegin', $dateBegin);
$this->view->assign('dateEnd', $dateEnd);
//Customer params have an option on the RNCS filter
$this->view->assign('filterRNCS', $user->filterRNCS);
2012-09-10 09:34:14 +00:00
$this->view->assign('licenceINSEE', $user->licenceINSEE);
$this->view->assign('immediatExtract', $user->immediatExtract);
$tarifText = '';
//Tarifs
if ($user->forfait!=0) {
//Forfait de
$tarifText = 'Forfait de '.$user->forfait.' euros';
} else {
$tarifText = 'Tarif unitaire à la ligne de '.$user->priceLine.' euros';
}
//Paramètres
if ( $user->limitFiles!=0 && $user->limitLines!=0 ) {
$tarifText.= ' limité à '.$user->limitFiles.' fichiers et à '.$user->limitLines.' lignes par fichier.';
} elseif ( $user->limitFiles!=0 && $user->limitLines==0 ) {
$tarifText.= ' limité à '.$user->limitFiles.' fichiers';
} elseif ( $user->limitFiles==0 && $user->limitLines!=à ) {
$tarifText.= ' limité à '.$user->limitLines.' lignes par fichier.';
}
$this->view->assign('tarifText', $tarifText);
//List of data to extract
$profilsM = new Application_Model_EnrichissementProfils();
$sql = $profilsM->select()
->where('login = ?', $user->username)
->where('idClient = ?', $user->idClient);
$result = $profilsM->fetchRow($sql);
if ($result) {
$criteres = json_decode($result['criteres'], true);
require_once 'Scores/Enrichissement.php';
$enrichissement = new Enrichissement();
$data = $enrichissement->getFields();
$profilLabels = array();
foreach ( $data as $key => $item ) {
if (in_array($key, $criteres)) {
$profilLabels[] = $item['label'];
}
}
$profil = new stdClass();
$profil->labels = $profilLabels;
$profil->reference = $result['reference'];
$this->view->assign('profil', $profil);
}
2012-05-25 13:24:30 +00:00
}
2012-05-28 12:46:52 +00:00
/**
* Set preferences
*/
public function prefAction()
{
$this->_helper->layout()->disableLayout();
2012-02-02 17:29:14 +00:00
2012-05-28 12:46:52 +00:00
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
2012-02-02 17:29:14 +00:00
2012-05-28 12:46:52 +00:00
//Read prefs table to load actual config
$prefsM = new Application_Model_Prefs();
$userPrefs = $prefsM->find($user->username);
2012-02-02 17:29:14 +00:00
2012-05-28 12:46:52 +00:00
if ($userPrefs) {
$data = json_decode($userPrefs->current()->json, true);
2012-05-28 12:46:52 +00:00
} else {
$data = array('interface'=>array(),'filter'=>array());
2012-05-28 12:46:52 +00:00
$prefsM->insert(array('login'=>$user->username, 'json'=>json_encode($data)));
}
2012-02-02 17:29:14 +00:00
2012-05-28 12:46:52 +00:00
$request = $this->getRequest();
$sendParam = $request->getParams();
2012-02-02 17:29:14 +00:00
2012-05-28 12:46:52 +00:00
$prefsFilter = array('rncs');
$prefsInterface = array('insee');
2012-02-02 17:29:14 +00:00
2012-05-28 12:46:52 +00:00
$filter = array();
foreach ( $prefsFilter as $item ) {
2012-05-28 12:46:52 +00:00
if (array_key_exists($item, $sendParam)) {
2012-05-28 15:17:18 +00:00
$filter = array($item => $sendParam[$item]);
2012-05-28 12:46:52 +00:00
}
}
if (array_key_exists('filter', $data)) {
$filter = array_merge($data['filter'], $filter);
}
$data['filter'] = $filter;
$interface = array();
foreach ( $prefsInterface as $item ) {
2012-05-28 12:46:52 +00:00
if (array_key_exists($item, $sendParam)) {
2012-05-28 15:17:18 +00:00
$interface = array($item => $sendParam[$item]);
2012-05-28 12:46:52 +00:00
}
}
if (array_key_exists('interface', $data)) {
$interface = array_merge($data['interface'], $interface);
}
$data['interface'] = $interface;
$newjson = json_encode($data);
$nbRow = $prefsM->update(array('json'=>$newjson), "login='".$user->username."'");
//Don't forget to save new preferences in session
2012-05-28 12:46:52 +00:00
$this->view->assign('nbRow', $nbRow);
}
2012-02-02 17:29:14 +00:00
2012-05-28 12:46:52 +00:00
}