Gestion des dernières recherches et la la liste avec enregistrement en session

This commit is contained in:
Michael RICOIS 2011-05-26 13:14:06 +00:00
parent 8ac1684444
commit 5e932e9c1b
6 changed files with 189 additions and 152 deletions

View File

@ -14,7 +14,6 @@ resources.frontController.plugins.Menu = "Application_Controller_Plugin_Menu"
resources.frontController.plugins.Pdf = "Application_Controller_Plugin_Pdf"
resources.frontController.plugins.Pdf = "Application_Controller_Plugin_Xml"
resources.frontController.plugins.Cgu = "Application_Controller_Plugin_Cgu"
resources.frontController.plugins.Historique = "Application_Controller_Plugin_Historique"
resources.layout.layout = "main"
resources.layout.layoutPath = APPLICATION_PATH "/views/default"
resources.view.basePath = APPLICATION_PATH "/views/default"

View File

@ -8,6 +8,8 @@ class RechercheController extends Zend_Controller_Action
if(isset($_SESSION['recherche']['giant']))
unset($_SESSION['recherche']['giant']);
require_once 'Scores/RechercheHistorique.php';
$this->view->headLink()->appendStylesheet('/themes/default/styles/recherche.css', 'all');
}
@ -16,6 +18,9 @@ class RechercheController extends Zend_Controller_Action
$this->_forward('entreprise');
}
/**
* Affiche le formulaire de recherche entreprise
*/
public function entrepriseAction()
{
$request = $this->getRequest();
@ -27,6 +32,9 @@ class RechercheController extends Zend_Controller_Action
$this->view->form = $form;
}
/**
* Affiche le formulaire de recherche dirigeants
*/
public function dirigeantAction()
{
$this->view->headTitle()->append('Recherche Dirigeant');
@ -35,9 +43,12 @@ class RechercheController extends Zend_Controller_Action
$this->view->assign('form', $form);
}
/**
* Affiche le formulaire de recherche annonces
* Enter description here ...
*/
public function annonceAction()
{
$this->view->headTitle()->append('Recherche Annonce');
}
@ -53,8 +64,8 @@ class RechercheController extends Zend_Controller_Action
public function listAction()
{
$this->view->headTitle()->append('Liste des dernières recherches');
$session = new Zend_Session_Namespace('Historique');
$this->view->assign('historique', $session->historique);
$rechercheSession = new RechercheHistorique();
$this->view->assign('historique', $rechercheSession->liste());
}
public function enqueteAction()
@ -79,7 +90,7 @@ class RechercheController extends Zend_Controller_Action
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/configuration.ini', 'path');
$path = realpath($config->data).'/'.$config->log;
$fp = fopen($path.'/enquetes.csv', 'a');
fwrite($fp, date('Y/m/d H:i:s').' - '.print_r($form->getValues(),true).print_r($tabInfo,true)."\n");
fwrite($fp, date('Y/m/d H:i:s').' - '.print_r($form->getValues(),true)."\n");
fclose($fp);
$message = "Détail de la demande d'investigation<br/>";
foreach($form->getValues() as $key => $value) {
@ -112,6 +123,9 @@ class RechercheController extends Zend_Controller_Action
}
}
/**
* Affiche les résultats d'une recherche
*/
public function listeAction()
{
$request = $this->getRequest();
@ -122,7 +136,21 @@ class RechercheController extends Zend_Controller_Action
if( !empty($pays) )
$this->_forward('index', 'giant');
$type = $request->getParam('type');
$type = $request->getParam('type', '');
$rechercheParams = new RechercheHistorique();
//Si le formulaire a été soumis alors on enregistre en session et on redirige
if ($request->isPost() && !empty($type)) {
$rechercheParams->save($type, $params);
$this->_redirect('recherche/liste');
}
$page = $request->getParam('page', 1);
$recherche = $rechercheParams->item(0);
$type = $recherche['type'];
$params = $recherche['params'];
//Criteres recherche entreprise
if ($type=='ent'){
@ -138,7 +166,7 @@ class RechercheController extends Zend_Controller_Action
}
$libVoie = preg_replace('/[^0-9A-Z]/', ' ', strtoupper($params['voie']));
$cpVille = preg_replace('/ +/',' ',
preg_replace('/[^0-9A-Z]/', ' ', strtoupper($formR['cpVille'])));
preg_replace('/[^0-9A-Z]/', ' ', strtoupper($params['cpVille'])));
if (preg_match("/^([0-9]{2,5})([\D]*)/i", $cpVille, $matches)) {
$cp = trim($matches[1]);
@ -148,6 +176,8 @@ class RechercheController extends Zend_Controller_Action
$ville = trim($cpVille);
}
// Zend_Registry::get('firebug')->info('CP'); Zend_Registry::get('firebug')->info($cp);
$criteres = array();
$criteres['identifiant'] = $params['siret'];
$criteres['raisonSociale'] = $raisonSociale;
@ -202,8 +232,8 @@ class RechercheController extends Zend_Controller_Action
require_once 'Scores/WsScores.php';
$ws = new WsScores();
//@todo : Set position
$reponse = $ws->rechercheEntreprise($type, $criteres, 0);
$position = $page-1;
$reponse = $ws->rechercheEntreprise($type, $criteres, $position);
Zend_Registry::get('firebug')->info($reponse);
if ($reponse !== false) {
@ -219,7 +249,6 @@ class RechercheController extends Zend_Controller_Action
$nbReponses = $reponse->results->nbReponses;
$nbReponsesTotal = $reponse->results->nbReponsesTotal;
if ($nbReponses < $nbReponsesTotal) {
$position = 0;
$totPage = ceil($nbReponsesTotal/$nbReponses);
$curPage = ceil($position/$nbReponses)+1;
} else {

View File

@ -1,32 +1,70 @@
<div id="center">
<div>
<?php if(!empty($this->historique)):?>
<?php foreach($this->historique as $key => $historique):?>
<?php $i = 0;?>
<h2><?php echo $key;?></h2>
<?php foreach ($historique as $valeur):?>
<ul style="padding-left:30px;">
<li>RAISON SOCIALE :
<?php echo $valeur['raisonSociale']?><br />
<?php if (!empty($valeur['siret'])):?>
- <a href="<?php echo $this->url(array('controller' => 'identite', 'action' => 'fiche',
'siret'=> $valeur['siret']
), 'default', true);?>">Afficher la fiche d'identité consultée </a><br />
<?php else:?>
- <a href="<?php echo $this->url(array('controller' => 'recherche', 'action' => 'liste',
'type'=> $valeur['type'], 'raisonSociale' => $valeur['raisonSociale'],
'siret' => $valeur['siret'], 'numero' => $valeur['numero'],
'voie' => $valeur['voie'], $valeur['cpVille'],
'telFax' => $valeur['telFax'], 'naf' => $valeur['naf'],
'pays' => $valeur['pays']
), 'default', true);?>">Lancer la recherche</a><br />
<?php endif;?>
- <a href="<?php echo $this->url();?>">Afficher le formulaire</a></li>
</ul>
<br />
<?php $i++?>
<?php endforeach;?>
<?php endforeach;?>
<?php endif;?>
<?php if (count($this->historique)>0) {?>
<div class="paragraph">
<?php foreach($this->historique as $histo) {?>
<li>
<?php
switch($histo['type']){
case 'ent':
?>
<p><u>RECHERCHE ENTREPRISE :</u></p>
<?php if (isset($histo['consult'])) {?>
<a href="<?=$this->url(array(
'controller' => 'identite',
'action' => 'fiche',
'siret' => $histo['consult']['siret'],
'id' => $histo['consult']['id'],
))?>">Afficher la fiche identite consulter</a>
<?php }?>
<a href="<?=$this->url(array_merge(
array('controller' => 'recherche', 'action' => 'list'),
$histo['params'])
)?>">Lancer la recherche</a>
<a href="<?=$this->url(array_merge(
array('controller' => 'recherche', 'action' => 'entreprise',
$histo['params'])
))?>">Afficher le formulaire</a>
<?php
break;
case 'dir':
?>
<p><u>RECHERCHE DIRIGEANT :</u></p>
<?php if (isset($histo['consult'])) {?>
<a href="<?=$this->url(array(
'controller' => 'identite',
'action' => 'fiche',
'siret' => $histo['consult']['siret'],
'id' => $histo['consult']['id'],
))?>">Afficher la fiche identite consulter</a>
<?php }?>
<a href="<?=$this->url(array_merge(
array('controller' => 'recherche', 'action' => 'list'),
$histo['params'])
)?>">Lancer la recherche</a>
<a href="<?=$this->url(array_merge(
array('controller' => 'recherche', 'action' => 'dirigeant',
$histo['params'])
))?>">Afficher le formulaire</a>
<?php
break;
}
?>
</li>
<?php }?>
</div>
<?php } else {?>
<div class="paragraph">
Aucune recherche enregistrée.
</div>
<?php }?>
</div>

View File

@ -1,35 +0,0 @@
<?php
require_once('Scores/historique.php');
class Application_Controller_Plugin_Historique extends Zend_Controller_Plugin_Abstract
{
public function formatInformations($params) {
$informations = array(
'type' => $params['type'],
'siret' => $params['siret'],
'raisonSociale' => $params['raisonSociale'],
'numero' => $params['numero'],
'voie' => $params['voie'],
'cpVille' => $params['cpVille'],
'telFax' => $params['telFax'],
'naf' => $params['naf'],
'pays' => $params['pays']
);
return ($informations);
}
public function postDispatch(Zend_Controller_Request_Abstract $request) {
$session = new Zend_Session_Namespace('Historique');
if ($request->getControllerName() == 'recherche') {
if ($request->getActionName() == 'liste') {
if ($request->isPost()) {
$session->historique['entreprise'][] = self::formatInformations($request->getParams());
}
}
} else if ($request->getControllerName() == 'identite') {
if ($request->getActionName() == 'fiche') {
$session->historique['entreprise'][count($session->historique['entreprise'])-1]['siret'] = $request->getParam('siret');
}
}
}
}

View File

@ -0,0 +1,80 @@
<?php
/**
* Gére les enregistremenst des dernières recherche dans la sessions
* On garde les dernières recherche
* Le tableau de description est le suivant dans la session :
* []['type'] = ent, dir, act, annonces, histo
* ['params'] = tableau des paramètres pour chaque type
* ['consult'] = tableau des informations lors de la consultation d'une fiche
*/
class RechercheHistorique
{
protected $index = 'recherches';
protected $listeRecherche = array();
protected $rechercheMax = 10;
protected $listParams = array(
'ent' => array('siret', 'raisonSociale', 'numero', 'voie', 'cpVille', 'telFax', 'naf', 'pays'),
'dir' => array('dirNom', 'dirPrenom', 'dirDateNaissJJ', 'dirDateNaissMM', 'dirDateNaissAAAA', 'dirCpVille'),
);
public function __construct(){
$session = new Zend_Session_Namespace($this->index);
$this->listeRecherche = $session->liste;
Zend_Registry::get('firebug')->info($this->listeRecherche);
}
public function save($type, $params)
{
//Controle des éléments
$elements = array();
foreach($params as $key => $value){
Zend_Registry::get('firebug')->info($key);
if (in_array($key, $this->listParams[$type])){
$elements[$key] = $value;
}
}
//Vérification du nombre d'éléments
if (count($this->listeRecherche)>=$this->rechercheMax){
array_shift($this->listeRecherche);
}
$this->listeRecherche[] = array(
'type' => $type,
'params' => $elements,
);
$session = new Zend_Session_Namespace($this->index);
$session->liste = $this->listeRecherche;
}
public function assignInfo($siret, $id, $raisonSociale)
{
$rindex = count($this->listeRecherche)-1;
$this->listeRecherche[$rindex]['consult'] = array(
'siret' => $siret,
'id' => $id,
'raisonSociale' => $raisonSociale,
);
$session = new Zend_Session_Namespace($this->index);
$session->liste = $this->listeRecherche;
}
/**
* Retourne la liste des éléments de la session dans le bon ordre
*/
public function liste()
{
if (count($this->listeRecherche)>0) {
return array_reverse($this->listeRecherche);
} else {
return array();
}
}
public function item($index)
{
$rindex = count($this->listeRecherche)-1-$index;
return $this->listeRecherche[$rindex];
}
}

View File

@ -1,74 +0,0 @@
<?php
Class RequestHistorique
{
public $siren;
public $raisonSociale;
public $Adress;
public $faxTel;
public $naf;
public $pays;
public $page;
}
Class Historique
{
private $lastRequest;
private $listRequest = array();
public $vide;
public function __construct()
{
//$this->lastRequest = new RequestHistorique();
$this->vide = true;
}
public function setLastRequest($parametres)
{
$this->vide = false;
$this->lastRequest = new RequestHistorique();
if (is_array($parametres)) {
$this->lastRequest->siret = $parametres['siret'];
$this->lastRequest->raisonSociale = $parametres['raisonSociale'];
$this->lastRequest->Adress = $parametres['numero'].':'.$parametres['voie'].':'.$parametres['cpVille'];
$this->lastRequest->telFax = $parametres['telFax'];
$this->lastRequest->naf = $parametres['naf'];
$this->lastRequest->pays = $parametres['pays'];
} else {
throw new Exception('"$parametres" : n\'est pas une instance de "Zend_Controller_Action"');
}
return ($this->lastRequest);
}
public function isExists()
{
if(count($this->listRequest) > 0)
return (true);
return (false);
}
public function setSiret($siret)
{
$this->lastRequest->siret = $siret;
}
public function getPage()
{
return ($this->lastRequest->page);
}
public function setListRequest($parametres)
{
$this->listRequest[] = self::setLastRequest($parametres);
}
public function getLastRequest()
{
return ($this->lastRequest);
}
public function getListRequest()
{
return ($this->listRequest);
}
}