Suppression dernier objet

This commit is contained in:
Michael RICOIS 2012-05-16 15:52:34 +00:00
parent ff681eaa64
commit d139dc886f
8 changed files with 252 additions and 313 deletions

View File

@ -75,8 +75,60 @@ class ComptageController extends Zend_Controller_Action
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$request = $this->getRequest();
$object = new Object_Comptage();
$object->saveComptage($request->getParam('ref', ''));
$ref = $request->getParam('ref', '');
if (empty($ref)) {
echo json_encode(array(
'error'=>1,
'msg'=> "Référence non définie !"));
} else {
//Session
$fields = new Scores_Fields();
$criteres = $fields->getCriteres();
$resultat = $fields->getNb('total');
$nbInsee = $fields->getNb('insee');
//Informations utilisateur
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
//Enregistrement des critères
$criteresM = new Application_Model_Criteres();
$data = array(
'idClient' => $user->idClient,
'login' => $user->username,
'reference' => $ref,
'criteres' => json_encode($criteres),
'parent' => 0,
'dateAjout' => date('Y-m-d H:i:s'),
);
$id = $criteresM->insert($data);
if ($id){
//Enregistrement des valeurs du comptage
$comptageM = new Application_Model_Comptages();
$data = array(
'idDefinition' => $id,
'resultat' => $resultat,
'uniteInsee' => $nbInsee,
'dateAjout' => date('Y-m-d H:i:s'),
);
if ($comptageM->insert($data)) {
echo json_encode(array(
'error'=>0,
'msg'=> "Vos critères ont été sauvegardés sous la référence $ref",
'id' => $id));
} else {
echo json_encode(array(
'error'=>1,
'msg'=> "Erreur lors de l'enregistrement"));
}
} else {
echo json_encode(array(
'error'=>1,
'msg'=> "Erreur lors de l'enregistrement"));
}
}
}
public function updateAction()
@ -117,13 +169,20 @@ class ComptageController extends Zend_Controller_Action
$this->view->result = $result;
}
/**
* Get a preview of data to extract
*/
public function previsualisationAction()
{
$this->_helper->layout()->disableLayout();
$request = $this->getRequest();
$object = new Object_Comptage();
$sirets = $object->count(null, null, true);
$fields = new Scores_Fields();
//Comptage
require_once 'Scores/Ciblage.php';
$ciblage = new Ciblage($fields->getValues());
$sirets = $ciblage->execute(true, 10);
$dbConfig = Zend_Registry::get('configuration')->databases;
try {

View File

@ -9,21 +9,125 @@ class DashboardController extends Zend_Controller_Action
public function indexAction()
{
$object = new Object_Dashboard();
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
$this->view->comptages = $object->index();
$this->view->enrichissements = $object->enrichissements();
$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);
$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;
}
$this->view->comptages = $results;
$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('criteres' => 'criteres'), 'i.idCriteres = criteres.id',
array('')
)
->where('criteres.idClient = ?', $user->idClient)
->where('criteres.login = ?', $user->username)
->where('i.idCriteres = ?', $idComptage);
$this->view->enrichissements = $enrichissements->fetchAll($sql);
}
public function ciblagesAction()
{
$object = new Object_Dashboard();
$request = $this->getRequest();
$assigns = $object->ciblage($request->getParam('page', 1));
$this->view->ciblages = $assigns['ciblages'];
$this->view->nbCiblage = $assigns['nbCiblage'];
$request = $this->getRequest();
$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;
}
public function ciblageAction()
@ -119,6 +223,7 @@ class DashboardController extends Zend_Controller_Action
//Criteres => Comptages (last) => enrichissement_identifiants => enrichissement_commandes
$enrichissementsM = new Application_Model_EnrichissementIdentifiants();
// Pending
$sql = $enrichissementsM->select()
->setIntegrityCheck(false)
->from(

View File

@ -18,11 +18,30 @@ class GestionController extends Zend_Controller_Action
}
/**
* 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);
@ -88,14 +107,34 @@ class GestionController extends Zend_Controller_Action
$this->view->assign('fields', $allFields);
}
public function profildelAction(){}
/**
* Mark profil as deleted
*/
public function profildelAction()
{
}
public function comptagesAction()
{
$table = new Application_Model_Comptages();
$sql = $table->select()
->order('dateAjout DESC');
$this->view->comptages = $table->fetchAll($sql)->toArray();
$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;
}
public function enrichissementsAction()
@ -115,7 +154,7 @@ class GestionController extends Zend_Controller_Action
$result = $table->fetchRow($sql);
if(!empty($result)) {
$result = $result->toArray();
$sirets = json_decode($result['identifiants']);
$sirets = json_decode($result['identifiants'], true);
foreach($sirets as $siret) {
echo $siret."\n";
}

View File

@ -12,11 +12,11 @@
</tr>
<?php foreach($this->comptages as $comptage): ?>
<tr>
<td><?php echo $comptage['id']; ?></td>
<td><?php echo $comptage['dateAjout']; ?></td>
<td></td>
<td><?php echo $comptage['resultat']; ?></td>
<td><?php echo $comptage['uniteInsee']; ?></td>
<td><?=$comptage['idDefinition']?></td>
<td><?=$comptage['dateAjout']?></td>
<td><?=$comptage['reference']?></td>
<td><?=$comptage['resultat']?></td>
<td><?=$comptage['uniteInsee']?></td>
<td>
<a href="">Actualiser</a>
<a class="enrichissementref" href="<?=$this->url(array('controller'=> 'enrichissement','action'=>'reference', 'id'=>$comptage['idDefinition']))?>">Enrichissement</a>

View File

@ -1,5 +1,13 @@
<div id="dashboard">
<div>
<form method="post" action="<?=$this->url(array('controller'=>'gestion', 'action'=>'profils'), null, true)?>">
IdClient : <input type="text" name="idClient" /> - Login : <input type="text" name="login" />
<input type="submit" name="rechercher" value="Rechercher"/>
</form>
</div>
<h2>Liste des profils</h2>
<table>
<thead>
@ -10,7 +18,6 @@
<th>tarifLigne</th>
<th>dateAjout</th>
<th>dateSuppr</th>
<th>actif</th>
<th>Action</th>
</tr>
</thead>
@ -23,8 +30,13 @@
<td><?=$profil['tarifLigne']?></td>
<td><?=$profil['dateAjout']?></td>
<td><?=$profil['dateSuppr']?></td>
<td><?=$profil['actif']?></td>
<td></td>
<td>
<?php if ($profil['actif']==1) {?>
<a href="<?=$this->url(array('controller'=>'gestion', 'action'=>'profildel', 'id'=>$profil['id']))?>">Désactiver</a>
<?php } else {?>
<a href="#">Activer</a>
<?php }?>
</td>
</tr>
<?php }?>
</tbody>

View File

@ -1,85 +0,0 @@
<?php
class Object_Comptage
{
public function saveComptage($ref)
{
if (empty($ref)) {
echo json_encode(array(
'error'=>1,
'msg'=> "Référence non définie !"));
} else {
//Session
$fields = new Scores_Fields();
$criteres = $fields->getCriteres();
$resultat = $fields->getNb('total');
$nbInsee = $fields->getNb('insee');
//Informations utilisateur
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
//Enregistrement des critères
$criteresM = new Application_Model_Criteres();
$data = array(
'idClient' => $user->idClient,
'login' => $user->username,
'reference' => $ref,
'criteres' => json_encode($criteres),
'parent' => 0,
'dateAjout' => date('Y-m-d H:i:s'),
);
$id = $criteresM->insert($data);
if ($id){
//Enregistrement des valeurs du comptage
$comptageM = new Application_Model_Comptages();
$data = array(
'idDefinition' => $id,
'resultat' => $resultat,
'uniteInsee' => $nbInsee,
'dateAjout' => date('Y-m-d H:i:s'),
);
if ($comptageM->insert($data)) {
echo json_encode(array(
'error'=>0,
'msg'=> "Vos critères ont été sauvegardés sous la référence $ref",
'id' => $id));
} else {
echo json_encode(array(
'error'=>1,
'msg'=> "Erreur lors de l'enregistrement"));
}
} else {
echo json_encode(array(
'error'=>1,
'msg'=> "Erreur lors de l'enregistrement"));
}
}
}
public function count($key, $valeur, $need = false)
{
$fields = new Scores_Fields();
//Comptage
require_once 'Scores/Ciblage.php';
$ciblage = new Ciblage($fields->getValues());
if($need) {
return $ciblage->execute(true, 10);
}
$total = $ciblage->execute();
$insee = $ciblage->calculRedevanceInsee();
$fields->setNb('total', $total);
$fields->setNb('insee', $insee);
//@todo : Ajouter les critères sous forme json_encode
//Retour comptage, unité Insee
$result = array(
'count' => number_format($total, 0, '', ' '),
'insee' => number_format($insee, 0, '', ' ')
);
return (json_encode($result));
}
}

View File

@ -1,196 +0,0 @@
<?php
Class Object_Dashboard
{
public function index()
{
$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);
$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;
}
return ($results);
}
public function enrichissement($idComptage)
{
$enrichissements = new Application_Model_EnrichissementIdentifiants();
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
$sql = $enrichissements->select()
->setIntegrityCheck(false)
->from(
array('i' => 'enrichissement_identifiants'),
array('id', 'reference', 'fichier', 'nbLigneTotales', 'nbLigneTraites', 'error', 'dateAdded', 'dateStart', 'dateStop')
)
->join(
array('criteres' => 'criteres'), 'i.idCriteres = criteres.id',
array('')
)
->where('criteres.idClient = ?', $user->idClient)
->where('criteres.login = ?', $user->username)
->where('i.idCriteres = ?', $idComptage);
return ($enrichissements->fetchAll($sql));
}
public function enrichissements()
{
$enrichissementsM = new Application_Model_EnrichissementIdentifiants();
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
$sql = $enrichissementsM->select()
->setIntegrityCheck(false)
->from(
array('i' => 'enrichissement_identifiants'),
array('id', 'reference', 'fichier', 'nbLigneTotales', 'nbLigneTraites', 'error', 'dateAdded', 'dateStart', 'dateStop')
)
->join(
array('c' => 'comptages'), 'i.idComptage = c.id',
array('')
)
->join(
array('criteres' => 'criteres'), 'i.idCriteres = criteres.id',
array('')
)
->where('criteres.idClient = ?', $user->idClient)
->where('criteres.login = ?', $user->username)
->order('dateAdded DESC');
return ($enrichissementsM->fetchAll($sql));
}
public function menu()
{
}
public function ciblage($page)
{
$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;
}
return (array('ciblages' => $results, 'nbCiblage' => $nbCiblage));
}
public function ciblagedetail($id)
{
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
$table = new Application_Model_Criteres();
$sql = $table->select()
->where('idClient = ?', $user->idClient)
->where('login = ?', $user->username)
->where('id = ?', $id);
$criteres = $table->fetchRow($sql)->toArray();
if ($criteres != null){
$comptage = new Application_Model_Comptages();
$sql = $comptage->select()
->where('idDefinition = ?', $id)->order('dateAjout DESC');
$comptages = $comptage->fetchAll($sql)->toArray();
}
return (array_merge(array('comptages' => $comptages), array('criteres' => $criteres)));
}
public function rcomptage($q)
{
$auth = Zend_Auth::getInstance();
$user = $auth->getIdentity();
$criteresM = new Application_Model_Criteres();
$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)),
);
}
}
return (json_encode($output));
}
}

View File

@ -144,20 +144,25 @@ class Ciblage
/**
*
* @param unknown_type $need
* @param boolean $need
*/
public function execute($need = false)
public function execute($need = false, $nbReturn = 0)
{
if($need) {
$return = array();
$limit = 1000;
$maxMatches = 50000;
$this->sphinx->SetLimits(0, $limit, 50000);
if ( $nbReturn > 0 ) {
$limit = $maxMatches = $nbReturn;
}
$this->sphinx->SetLimits(0, $limit, $maxMatches);
$resSphinx = $this->sphinx->Query($this->alpha, $this->index);
$total = $resSphinx['total_found'];
//
//Make an array with only the data needed
$return = $this->getSiret($resSphinx);
if ( $limit<$total ) {
@ -165,7 +170,7 @@ class Ciblage
//Get siret by $limit units for each request
for($i=1; $i<$max; $i++){
$offset = $i*$limit;
$this->sphinx->SetLimits($offset, $limit, 50000);
$this->sphinx->SetLimits($offset, $limit, $maxMatches);
$resSphinx = $this->sphinx->Query($this->alpha, $this->index);
$tmpSiret = $this->getSiret($resSphinx);
$return = array_merge($return, $tmpSiret);