issue #0001564 : Change to search with new table

This commit is contained in:
Michael RICOIS 2013-03-05 15:14:52 +00:00
parent 43f83bc94b
commit e072675d9a
4 changed files with 234 additions and 142 deletions

View File

@ -742,7 +742,7 @@ function reponse(&$resSphinx, &$resDB, $criteres, $time, $formR, $form2crit,
for ($i = 0; $i < $resDB->num_rows; $i++) { for ($i = 0; $i < $resDB->num_rows; $i++) {
$ligne = $resDB->fetch_assoc(); $ligne = $resDB->fetch_assoc();
//file_put_contents('test.log', "\n".'i = '.$i.print_r($ligne,1), FILE_APPEND); //file_put_contents('test.log', print_r($ligne,1), FILE_APPEND);
$ret['reponses'][$i]['id'] = $ligne['id']; $ret['reponses'][$i]['id'] = $ligne['id'];
$pertinence = $pertinence_generale; $pertinence = $pertinence_generale;
@ -773,6 +773,7 @@ function reponse(&$resSphinx, &$resDB, $criteres, $time, $formR, $form2crit,
$ret['reponses'][$i]['Adresse2'] = $ligne['adr_comp']; $ret['reponses'][$i]['Adresse2'] = $ligne['adr_comp'];
$ret['reponses'][$i]['CP'] = $ligne['adr_cp']; $ret['reponses'][$i]['CP'] = $ligne['adr_cp'];
$ret['reponses'][$i]['Ville'] = $ligne['adr_ville']; $ret['reponses'][$i]['Ville'] = $ligne['adr_ville'];
$ret['reponses'][$i]['Pays'] = $ligne['pays'];
$ret['reponses'][$i]['Tel'] = $ligne['tel']; $ret['reponses'][$i]['Tel'] = $ligne['tel'];
$ret['reponses'][$i]['Fax'] = $ligne['fax']; $ret['reponses'][$i]['Fax'] = $ligne['fax'];
$ret['reponses'][$i]['FJ'] = $ligne['cj']; $ret['reponses'][$i]['FJ'] = $ligne['cj'];
@ -793,15 +794,17 @@ function reponse(&$resSphinx, &$resDB, $criteres, $time, $formR, $form2crit,
$ret['reponses'][$i]['DirDepart'] = ''; $ret['reponses'][$i]['DirDepart'] = '';
} elseif ($formR['type']=='act') { } elseif ($formR['type']=='act') {
// Actionnaire // Actionnaire
$ret['reponses'][$i]['ActNomRs'] = $ligneDir[$i]['ActNomRs']; $ret['reponses'][$i]['ActNomRs'] = $ligne['ActRaisonSociale'];
$ret['reponses'][$i]['ActPays'] = $ligneDir[$i]['ActPays']; $ret['reponses'][$i]['ActPays'] = $ligne['ActPays'];
$ret['reponses'][$i]['ActDateLien'] = $ligneDir[$i]['ActDateLien']; $ret['reponses'][$i]['ActDateLien'] = $ligne['dateLien'];
$ret['reponses'][$i]['ActActif'] = $ligneDir[$i]['ActActif']; $ret['reponses'][$i]['ActActif'] = $ligne['ActActif'];
$ret['reponses'][$i]['ActPmin'] = $ligneDir[$i]['ActPmin']; $ret['reponses'][$i]['ActPmin'] = $ligne['ActPmin'];
} }
} }
} }
//file_put_contents('test.log', print_r($ret,1), FILE_APPEND);
if ($formR['type'] == 'ent') { if ($formR['type'] == 'ent') {
$ret['pass'] = $resSphinx['pass']; $ret['pass'] = $resSphinx['pass'];
} }
@ -923,13 +926,42 @@ function rechercheDir(&$formR, $deb, $nbRep, $max)
} }
$requeteDB = $requeteDB =
"SELECT d.nom, d.prenom, d.naissance_nom, d.naissance_date, d.naissance_lieu, l.libelle AS fonction_lib,". "SELECT
" e.id, CONCAT(e.siren,e.nic) AS siret, e.siren, e.nic, e.siege, e.raisonSociale, e.sigle, e.enseigne,". d.nom,
" e.adr_num, e.adr_typeVoie, e.adr_libVoie, e.adr_comp, e.adr_cp, e.adr_ville, e.tel, e.fax, e.cj, e.actif, e.ape_etab, e.ape_entrep". d.prenom,
" FROM dirigeants d, etablissements e, bodacc_fonctions l". d.naissance_nom,
" WHERE d.fonction_code=l.codeFct AND d.id IN (".$resSphinx['matches'][0]['id']; d.naissance_date,
for ($i = 1; $i + $deb < $resSphinx['total'] && $i < $nbRep; ++$i) { d.naissance_lieu,
$requeteDB .= ",".$resSphinx['matches'][$i]['id']; l.libelle AS fonction_lib,
e.id, CONCAT(e.siren,e.nic) AS siret,
e.siren,
e.nic,
e.siege,
e.raisonSociale,
e.sigle,
e.enseigne,
e.adr_num,
e.adr_typeVoie,
e.adr_libVoie,
e.adr_comp,
e.adr_cp,
e.adr_ville,
e.tel,
e.fax,
e.cj,
e.actif,
e.ape_etab,
e.ape_entrep
FROM dirigeants d, etablissements e, bodacc_fonctions l
WHERE
d.fonction_code=l.codeFct
AND d.id IN (";
$i = 0;
foreach ($resSphinx['matches'] as $id => $element) {
if($i > 0) $requeteDB.= ',';
$requeteDB.= $element['id'];
$i++;
} }
$requeteDB .= ") AND e.id = ("; $requeteDB .= ") AND e.id = (";
$requeteDB .= "SELECT tmp.id FROM etablissements tmp "; $requeteDB .= "SELECT tmp.id FROM etablissements tmp ";
@ -1049,79 +1081,88 @@ function rechercheAct($formR, $deb, $nbRep, $max)
$pass = 0; $pass = 0;
initSphinx($sphinx, $mode, $pass, $deb, $nbRep, $max); initSphinx($sphinx, $mode, $pass, $deb, $nbRep, $max);
$Criteres = array('Siren2' => 'siren', $Criteres = array(
'Siren2' => 'siren',
'Req' => 'actNomRS', 'Req' => 'actNomRS',
'@Pays' => 'pays', '@Pays' => 'pays',
'PminNum' => 'pctMax' //'PDetention' => 'pctMax',
); );
$form2crit = array('actNomRS' => 'N', $form2crit = array(
'actNomRS' => 'N',
'pays' => 'P', 'pays' => 'P',
'pctMax' => 'M' 'pctMax' => 'M'
); );
$Requete = constructRequete($formR, $Criteres); $Requete = constructRequete($formR, $Criteres);
if(!empty($formR['pctMin']))
$sphinx->SetFilterRange('PminNum', $formR['pctMin'], 99);
if(!empty($formR['pctMax']))
$sphinx->SetFilterRange('PminNum', $formR['pctMin'], 99);
if(!empty($formR['pctMin']) and !empty($formR['pctMax']))
$sphinx->SetFilterRange('PminNum', $formR['pctMix'], $formR['pctMax']);
if(!empty($formR['pctMin']))
$sphinx->SetFilterFloatRange('PDetention', $formR['pctMin'], 99);
if(!empty($formR['pctMax']))
$sphinx->SetFilterFloatRange('PDetention', $formR['pctMin'], 99);
if(!empty($formR['pctMin']) && !empty($formR['pctMax']))
$sphinx->SetFilterFloatRange('PDetention', $formR['pctMin'], $formR['pctMax']);
$sphinxreturn = $sphinx->Query($Requete, $index); $sphinxreturn = $sphinx->Query($Requete, $index);
/*
file_put_contents('test.log', print_r($formR,1));
file_put_contents('test.log', $sphinx->GetLastError()."\n", FILE_APPEND);
file_put_contents('test.log', 'TEST='.print_r($sphinxreturn,1), FILE_APPEND);
*/
$criteres = 'NPM'; $criteres = 'NPM';
$requette = 'SELECT l.id AS lienId, l.actif AS lienActif, l.source, l.Pmin, l.PpPm, l.id2, '.
'l.Siren2, l.RaisonSociale, l.Pays, '. //@todo : Faire correspondre avec la table etablissement
'IF(l.dateUpdate>IF(l.dateInsert>l.dateLien,l.dateInsert,l.dateLien),l.dateUpdate,IF(l.dateInsert>l.dateLien,l.dateInsert,l.dateLien)) AS dateLien, '. $requette = "SELECT
'e.id, CONCAT(e.siren,e.nic) AS siret, e.siren, e.nic, e.siege, e.raisonSociale, e.sigle, e.enseigne, '. /*Liens*/
'e.adr_num, e.adr_typeVoie, e.adr_libVoie, e.adr_comp, e.adr_cp, e.adr_ville, e.tel, e.fax, e.cj, e.actif, e.ape_etab, e.ape_entrep ' . l.PDetention AS Pmin,
'FROM liens l, etablissements e '. l.MajMin,
'WHERE l.Siren1=e.siren AND e.siege=1 AND l.id IN('; l.dateEffetLien AS dateLien,
IF(l.dateUpdate>l.dateInsert,l.dateUpdate,l.dateInsert) AS date,
/*Participation*/
CONCAT(e.siren, e.nic) AS siret,
par.siren,
e.nic,
e.siege,
par.RS AS raisonSociale,
/*sigle*/
/*enseigne*/
par.actif,
par.PpPm,
par.adresse_num AS adr_num,
par.adresse_codvoie AS adr_typeVoie,
par.adresse_libvoie AS adr_libVoie,
par.adresse_comp AS adr_comp,
par.adresse_cp AS adr_cp,
par.adresse_ville AS adr_ville,
p1.libPays AS pays,
par.tel,
par.fax,
/*Actionnaire*/
act.id AS ActId,
act.actif AS ActActif,
act.RS AS ActRaisonSociale,
p2.libPays AS ActPays
FROM liens2 l, liensRef par, liensRef act, tabPays p1, tabPays p2, etablissements e
WHERE
par.id = l.idPar AND act.id = l.idAct
AND p1.codPays3 = par.adresse_pays
AND p2.codPays3 = act.adresse_pays
AND ( e.siren = par.siren OR (e.source='006' AND e.source_id=l.idPar) )
AND l.id IN (";
$i = 0; $i = 0;
//file_put_contents('test.log', print_r($sphinxreturn['matches'],1));
foreach ($sphinxreturn['matches'] as $id => $element) { foreach ($sphinxreturn['matches'] as $id => $element) {
if($i > 0) $requette.= ','; if($i > 0) $requette.= ',';
$requette.= $element['id']; $requette.= $element['id'];
$i++; $i++;
} }
$requette.= ') GROUP BY l.Siren1, l.id ORDER BY e.actif DESC, e.siege DESC, e.id ASC'; $requette.= ') ORDER BY par.actif DESC, e.siege DESC, e.nic DESC';
//file_put_contents('test.log', $requette."\n", FILE_APPEND);
$req = $gDatabaseJO->query($requette); $req = $gDatabaseJO->query($requette);
return reponse($sphinxreturn, $req, $criteres, $sphinxreturn['time'], $formR, $form2crit, $deb, array());
/*$requette2 ='SELECT id, CONCAT(siren,nic) AS siret, siren, nic, siege, '.
'raisonSociale, sigle, enseigne, adr_num, adr_typeVoie, adr_libVoie, '.
'adr_comp, adr_cp, adr_ville, tel, fax, cj, actif, ape_etab, '.
'ape_entrep FROM etablissements WHERE id IN (';
*/
$ligneAct = array();
for($i = 0; $i < $req->num_rows; $i++) {
$ligne = $req->fetch_assoc();
//file_put_contents('test.log', print_r($ligne,1)."\n", FILE_APPEND);
$ligneAct[$i] = array(
'id' => $ligne['id'],
'ActNomRs' => $ligne['RaisonSociale'],
'ActPays' => $ligne['Pays'],
'ActDateLien'=>$ligne['dateLien'],
'ActActif' => $ligne['actif'],
'ActPmin' => $ligne['Pmin'],
);
if($i > 0) $requette2.= ',';
//$requette2.= $ligne['id'];
}
//$requette2.= ') ORDER BY actif DESC, siege DESC';
//file_put_contents('test.log', $requette2."\n", FILE_APPEND);
//$req = $gDatabaseJO->query($requette2);
return reponse($sphinxreturn, $req, $criteres, $sphinxreturn['time'], $formR, $form2crit, $deb, $ligneAct);
} }
// --------------------------------------------------------------------------- // // --------------------------------------------------------------------------- //
@ -1405,7 +1446,8 @@ function rechercheEnt(&$formR, $deb, $nbRep, $max, $sirenValide = false)
} }
if ($resSphinx['total'] == 0) { if ($resSphinx['total'] == 0) {
return array('nbReponses' => 0, return array(
'nbReponses' => 0,
'nbReponsesTotal' => 0, 'nbReponsesTotal' => 0,
'duree' => $total_time, 'duree' => $total_time,
'pass' => $pass, 'pass' => $pass,
@ -1413,7 +1455,8 @@ function rechercheEnt(&$formR, $deb, $nbRep, $max, $sirenValide = false)
} }
if (DEBUG) { if (DEBUG) {
$base2form = array('adr_dep' => 'departement', $base2form = array(
'adr_dep' => 'departement',
'adr_cp' => 'localite', 'adr_cp' => 'localite',
'adr_num' => 'numVoie', 'adr_num' => 'numVoie',
'adr_libVoie' => 'voie', 'adr_libVoie' => 'voie',
@ -1423,39 +1466,64 @@ function rechercheEnt(&$formR, $deb, $nbRep, $max, $sirenValide = false)
'enseigne' => 'raisonSociale', 'enseigne' => 'raisonSociale',
'sigle' => 'raisonSociale', 'sigle' => 'raisonSociale',
'identite_pre' => 'raisonSociale'); 'identite_pre' => 'raisonSociale');
afficheDB($resSphinx, $formR, $form2crit, 'etablissements', $base2form, afficheDB($resSphinx, $formR, $form2crit, 'etablissements', $base2form, $deb, $nbRep);
$deb, $nbRep);
} }
// Reponse // Reponse
if ($gDatabaseJO == false) { if ($gDatabaseJO == false) {
return array('nbReponses' => 0, return array(
'nbReponses' => 0,
'nbReponsesTotal' => $resSphinx['total'], 'nbReponsesTotal' => $resSphinx['total'],
'duree' => $total_time, 'duree' => $total_time,
'erreur' => 'Base inaccessible'); 'erreur' => 'Base inaccessible');
} }
if (isset($resSphinx['matches']) == false) { if (isset($resSphinx['matches']) == false) {
return array('nbReponses' => 0, return array(
'nbReponses' => 0,
'nbReponsesTotal' => $resSphinx['total'], 'nbReponsesTotal' => $resSphinx['total'],
'duree' => $total_time, 'duree' => $total_time,
'erreur' => 'Aucun r&eacute;sultat'); 'erreur' => 'Aucun r&eacute;sultat');
} }
$requeteDB = 'select id, CONCAT(siren,nic) AS siret, siren, nic, siege, '. $requeteDB = 'SELECT
'raisonSociale, sigle, enseigne, adr_num, adr_typeVoie, adr_libVoie, '. id,
'adr_comp, adr_cp, adr_ville, tel, fax, cj, actif, ape_etab, '. CONCAT(siren,nic) AS siret,
'ape_entrep, (siren>200) AS sirenValide'. siren,
' from etablissements where id='.$resSphinx['matches'][0]['id']; nic,
for ($i = 1; $i + $deb < $resSphinx['total'] && $i < $nbRep; ++$i) { siege,
$requeteDB .= ' or id='.$resSphinx['matches'][$i]['id']; raisonSociale,
sigle,
enseigne,
adr_num,
adr_typeVoie,
adr_libVoie,
adr_comp,
adr_cp,
adr_ville,
libPays AS pays,
tel,
fax,
cj,
actif,
ape_etab,
ape_entrep,
(siren>200) AS sirenValide
FROM etablissements
LEFT OUTER JOIN tabPays ON adr_dep = codePaysInsee
WHERE id IN('.
$i = 0;
foreach ($resSphinx['matches'] as $id => $element) {
if($i > 0) $requeteDB.= ',';
$requeteDB.= $element['id'];
$i++;
} }
$requeteDB .= ' ORDER BY sirenValide DESC, actif DESC, siege DESC, rang DESC';
$requeteDB.= ') ORDER BY sirenValide DESC, actif DESC, siege DESC, rang DESC';
debugln(); debugln();
debugln("requeteDB='$requeteDB'"); debugln("requeteDB='$requeteDB'");
$resDB = $gDatabaseJO->query($requeteDB); $resDB = $gDatabaseJO->query($requeteDB);
return reponse($resSphinx, $resDB, $criteres, $total_time, $formR, return reponse($resSphinx, $resDB, $criteres, $total_time, $formR,$form2crit, $deb);
$form2crit, $deb);
} }
// --------------------------------------------------------------------------- // // --------------------------------------------------------------------------- //

View File

@ -1090,6 +1090,11 @@ class EntrepriseItem
*/ */
public $Ville; public $Ville;
/** Pays
* @var string
*/
public $Pays;
/** Téléphone /** Téléphone
* @var string * @var string
*/ */

View File

@ -1787,14 +1787,25 @@ class Interne extends WsScore
if (empty($maxRep)) $maxRep = 200; if (empty($maxRep)) $maxRep = 200;
if (empty($pertinence)) $pertinence = false; if (empty($pertinence)) $pertinence = false;
$mLiens = new MLiens(''); $formR = array(
// rechercheActionnaire($nom, $cpVille, $siren, $pays, $pctMin, $pctMax, $deb, $nbRep, $maxRep, $pertinence) 'type' => 'act',
$etabs = $mLiens->rechercheActionnaire($nom, $cpVille, $siren, $pays, $pctMin, $pctMax, $deb, $nbRep, $maxRep, $pertinence); 'siren' => $siren,
'actNomRS' => join(' ', array($nom, $cpVille)),
'pays' => $pays,
'pctMin' => $pctMin,
'pctMax' => $pctMax,
);
$version = defined('SPHINX_ACT_VERSION') ? SPHINX_ACT_VERSION : 1;
require_once 'Metier/sphinx/rechercheFonc.php';
$etabs = rechercheAct($formR, $deb, $nbRep, $maxRep);
$iInsee = new MInsee(); $iInsee = new MInsee();
$tabRet = array(); $tabRet = array();
foreach ($etabs['reponses'] as $etab) {
$reponses = $etabs['reponses'];
if (count($reponses)>0) {
foreach ($reponses as $etab) {
$act = new EntrepriseActItem(); $act = new EntrepriseActItem();
$act->id = $etab['id']; $act->id = $etab['id'];
$act->Pertinence = $etab['Pertinence']; $act->Pertinence = $etab['Pertinence'];
@ -1808,6 +1819,7 @@ class Interne extends WsScore
$act->Adresse2 = prepareString($etab['Adresse2']); $act->Adresse2 = prepareString($etab['Adresse2']);
$act->CP = $etab['CP']; $act->CP = $etab['CP'];
$act->Ville = prepareString($etab['Ville']); $act->Ville = prepareString($etab['Ville']);
$act->Pays = $etab['Pays'];
$act->Tel = $etab['Tel']; $act->Tel = $etab['Tel'];
$act->Fax = $etab['Fax']; $act->Fax = $etab['Fax'];
$act->FJ = $etab['FJ']; $act->FJ = $etab['FJ'];
@ -1826,6 +1838,7 @@ class Interne extends WsScore
$act->ActPmin = $etab['ActPmin']; $act->ActPmin = $etab['ActPmin'];
$tabRet[] = $act; $tabRet[] = $act;
} }
}
$output = new SearchActReturn(); $output = new SearchActReturn();
$output->nbReponses = $etabs['nbReponses']; $output->nbReponses = $etabs['nbReponses'];

View File

@ -1079,6 +1079,12 @@ class EntrepriseActItem
*/ */
public $Ville; public $Ville;
/**
* Pays
* @var string
*/
public $Pays;
/** Téléphone /** Téléphone
* @var string * @var string
*/ */