enrichissement/library/Metier/sphinx2/SDmotor.class.php

822 lines
33 KiB
PHP
Raw Normal View History

2012-01-13 14:35:11 +01:00
<?php
require_once realpath(dirname(__FILE__)).'/sequence.php';
require_once realpath(dirname(__FILE__)).'/configuration.php';
Class SDmotor
{
protected $sphinx;
protected $formR;
protected $index;
protected $criteresLetters;
protected $limits;
protected $sequancesArray;
protected $pertinance;
protected $acronyme;
protected $NumberResults;
protected $MaxResults;
public function __construct()
{
$this->limits['total_time'] = 0;
$this->limits['actif'] = false;
}
public function _initForm($formR)
{
$formulaire = array();
$ok = false;
switch($this->index) {
case 'ent':
foreach($formR as $name => $form) {
if($name != 'controller' and $name != 'action' and $name != 'module' and $name != 'Envoyer') {
$formulaire[$name] = (empty($form))?'':$form;
}
}
foreach($formulaire as $name => $form) {
if(array_key_exists($name, ConfigurationEnt::$app_form) and !empty($formulaire[$name]))
$array[$name] = $form;
}
$this->formR = $array;
break;
case 'dir':
foreach($formR as $name => $form) {
if($name != 'controller' and $name != 'action' and $name != 'module' and $name != 'Envoyer') {
$formulaire[$name] = (empty($form))?'':$form;
}
}
$this->formR = $formulaire;
break;
case 'act':
foreach($formR as $name => $form) {
if($name != 'controller' and $name != 'action' and $name != 'module' and $name != 'Envoyer') {
$formulaire[$name] = (empty($form))?'':$form;
}
}
$this->formR = $formulaire;
break;
case 'ciblage':
break;
}
}
public function databaseJO()
{
switch($this->index)
{
case 'ent':
$db = new mysqli(ConfigurationEnt::$mysql_host, ConfigurationEnt::$mysql_user, ConfigurationEnt::$mysql_password, ConfigurationEnt::$mysql_database);
break;
case 'dir':
$db = new mysqli(ConfigurationDir::$mysql_host, ConfigurationDir::$mysql_user, ConfigurationDir::$mysql_password, ConfigurationDir::$mysql_database);
break;
case 'act':
$db = new mysqli(ConfigurationAct::$mysql_host, ConfigurationAct::$mysql_user, ConfigurationAct::$mysql_password, ConfigurationAct::$mysql_database);
break;
case 'ciblage':
$db = new mysqli(ConfigurationCiblage::$mysql_host, ConfigurationCiblage::$mysql_user, ConfigurationCiblage::$mysql_password, ConfigurationCiblage::$mysql_database);
break;
}
if (mysqli_connect_error()) {
return;
}
$db->query("SET NAMES 'utf8';");
return $db;
}
public function search()
{
$pass = 0;
$quorum = array();
switch($this->index) {
case 'ent':
$this->sphinx->SetLimits(intval($this->deb), intval($this->NumberResults), intval($this->MaxResults));
if(!empty($this->formR['raisonSociale'])) $this->formR['raisonSociale'] = $this->formatRaisonSociale($this->formR['raisonSociale']);
$this->sphinx->SetSortMode(ConfigurationEnt::$sphinx_sort, 'sirenValide DESC, rang DESC, actif DESC, siege DESC');
$this->sphinx->SetMatchMode(ConfigurationEnt::$sphinx_match);
if(!empty($this->formR['Voie'])) $this->formR['Voie'] = $this->formatAdress ($this->formR['Voie']);
$resSphinx = $this->SPH_MATCH_();
break;
case 'dir':
$this->sphinx->SetLimits(intval($this->deb), intval($this->NumberResults), intval($this->MaxResults));
$this->sphinx->SetSortMode(ConfigurationDir::$sphinx_sort, 'actif DESC');
$this->sphinx->SetMatchMode(ConfigurationDir::$sphinx_match);
$resSphinx = $this->SPH_MATCH_();
break;
case 'act':
$this->sphinx->SetLimits(intval($this->deb), $this->NumberResults, $this->MaxResults);
$this->sphinx->SetSortMode(ConfigurationAct::$sphinx_sort, 'actif DESC');
$this->sphinx->SetMatchMode(ConfigurationAct::$sphinx_match);
$resSphinx = $this->SPH_MATCH_();
break;
case 'ciblage' :
$this->sphinx->SetLimits(intval($this->deb), ConfigurationCiblage::$nb_results, ConfigurationCiblage::$max_results);
break;
}
if($resSphinx['matches'] > 0){$this->setTime($resSphinx['time']);}
return ($this->getResponse($resSphinx));
}
public function SPH_MATCH_()
{
$sequenceS = new Sequence();
$Word = new Words();
$ref = $Word->refSequence;
$sequence = $sequenceS->sequence;
$link = $sequenceS->link;
$this->sequancesArray = array();
switch($this->index)
{
case 'ent':
$i = 0;
$valeur = $this->detectedSequance();
do {
$this->sequancesArray[] = $sequence[$link[$valeur]['id'][$i]];
$this->criteresLetters = $sequence[$link[$valeur]['id'][$i]];
$sequances = explode('.', $sequence[$link[$valeur]['id'][$i]]);
$quorum = $this->countQorum();
$quorumRue = $this->countQorumR();
if(in_array('S', $sequances)) {
do {
$countRef = 0;
do {
if($link[$valeur][$ref[$countRef]])
{
if(in_array('R', $sequances))
{
do {
$this->constructQuerySequance($sequence[$link[$valeur]['id'][$i]], array((($quorum==$this->countQorum())?false:$quorum), (($quorumRue==$this->countQorumR())?false:$quorumRue)), $ref[$countRef]);
$result = $this->sphinx->RunQueries();
if($this->constructRaisonSocialeRequest($sequence[$link[$valeur]['id'][$i]], array($quorum, false), $ref[$countRef])) {
$result = $this->sphinx->RunQueries();
if(!empty($result)) {
foreach($result as $res) {
if($res['total'] > 0) {$result = $res;}
}
}
}
$quorumRue--;
} while(($result['total'] < 1) && $quorumRue > 0);
} else {
$this->constructQuerySequance($sequence[$link[$valeur]['id'][$i]], array($quorum, false), $ref[$countRef]);
if($this->constructRaisonSocialeRequest($sequence[$link[$valeur]['id'][$i]], array($quorum, false), $ref[$countRef])) {
$result = $this->sphinx->RunQueries();
if(!empty($result)) {
foreach($result as $res) {
if($res['total'] > 0) {$result = $res;}
}
}
}
}
}
$countRef++;
} while (($result['total'] < 1) && $countRef < count($ref));
$quorum--;
} while (($result['total'] < 1) && $quorum > 0);
} elseif (in_array('R', $sequances)) {
$qv = count(explode(' ', trim($this->formR['Voie'])));
$quorumVille = $qv;
do {
$this->constructQuerySequance($sequence[$link[$valeur]['id'][$i]], array(false, false), null);
$result = $this->sphinx->Query($this->RequestAdress($sequence[$link[$valeur]['id'][$i]], array('R', $qv)), $this->index);
$qv--;
} while($result['total'] < 1 and $qv > 0);
} else {
$this->constructQuerySequance($sequence[$link[$valeur]['id'][$i]], array(false, false), null);
$result = $this->sphinx->Query($this->RequestAdress($sequence[$link[$valeur]['id'][$i]]), $this->index);
}
$i++;
} while (($result['total'] < 1) && $i < count($link[$valeur]['id']));
break;
case 'dir':
$request = $this->constructQuerySequance(null, null, null, null);
$result = $this->sphinx->Query($request, $this->index);
break;
case 'act':
$quorum = count(explode(' ', $this->formR['actNomRs']));
while($result['total'] == 0 and $quorum != 0) {
$request = $this->constructQuerySequance(null, $quorum--, false);
$result = $this->sphinx->Query($request, $this->index);
}
break;
}
return ($result);
}
public function HistoSearch()
{
if(!empty($this->formR['annee1']))
$this->sphinx->setFilter('annee1', array($this->formR['annee1']));
$resSphinx = $this->sphinx->Query($this->formR['recherche'], $this->index);
return ($this->getResponse($resSphinx));
}
public function formatRaisonSociale($rs, $double = false)
{
$words = new Words();
$request = '';
$wordformRS = $words->wordformRS;
$array = explode(' ', $rs);
if(!empty($this->formR['raisonSociale']))
{
foreach($array as $item)
{
$item = str_replace('\'', ' ', $item);
if((strlen($item) > ConfigurationEnt::$app_maxSizeWord and !in_array(strtoupper($item), $wordformRS) and $this->index == 'ent') or strlen($item) > ConfigurationEnt::$app_maxSizeWord and count($array) == 1) {
if($double)
$request .= preg_replace('/(?:([^*])\1)\1*/', '$1', $item).' ';
else
$request .= $item.' ';
} else {
$request .= $item.' ';
}
}
$requets = mb_strtoupper(strtr(str_replace("'", ' ', $this->formR['raisonSociale']), 'ÉÈÊË', 'EEEEE'), 'UTF-8');
return ($requets);
}
}
public function formatCP($cp)
{
$matches = '';
$arrayChamp = explode(' ', trim($cp));
$str = false;
for($i=0; $i < count($arrayChamp); $i++)
{
if(preg_match('/^[0-9]{1,}$/', $cp, $matches))
{
if (strlen($matches[0]) == 1 and $matches[0] < 10) {
$matches[0] = '0'.$matches[0];
}
$size = strlen($matches[0]);
switch($this->index) {
case 'ent':
if(substr($matches[0], 0, 2) > 95 ) {
$this->sphinx->setFilter('adr_dep', array((int)substr($matches[0], 0, 3)));
} else if (substr($matches[0], 0, 2) == 20) {
$this->sphinx->setFilter('adr_dep', array(200));
} else {
$this->sphinx->setFilter('adr_dep', array((int)(substr($cp, 0, 2))));
}
if($size == 5) {
$this->sphinx->setFilter('adr_cp', array(intval($matches[0])));
}
break;
case 'dir':
if(substr($matches[0], 0, 2) > 95 ) {
$this->sphinx->setFilter('adr_dep', array((int)substr($matches[0], 0, 3)));
} else if (substr($matches[0], 0, 2) == 20) {
$this->sphinx->setFilter('adr_dep', array(200));
} else {
$this->sphinx->setFilter('adr_dep', array((int)(substr($cp, 0, 2))));
}
if($size == 5) {
$this->sphinx->setFilter('adr_cp', array(intval($matches[0])));
}
break;
case 'act':
if(substr($matches[0], 0, 2) > 95 ) {
$this->sphinx->setFilter('adr_dep', array((int)substr($matches[0], 0, 3)));
} else if (substr($matches[0], 0, 2) == 20) {
$this->sphinx->setFilter('adr_dep', array(200));
} else {
$this->sphinx->setFilter('adr_dep', array((int)(substr($cp, 0, 2))));
}
if($size == 5) {
$this->sphinx->setFilter('adr_cp', array(intval($matches[0])));
}
break;
case 'ciblage':
break;
default:
}
}
else {
switch($this->index) {
case 'ent':
$str .= $arrayChamp[$i];
break;
case 'dir':
$str .= ' @naissance_lieu "'.$arrayChamp[$i].'"';
break;
case 'act':
$str .= $arrayChamp[$i];
break;
case 'ciblage':
break;
}
}
}
return ($str);
}
public function FiltreDateDeNaissance()
{
if(!empty($this->formR['dirDateNaissMM'])) {
if($this->formR['dirDateNaissMM'] > 0 and $this->formR['dirDateNaissMM'] < 12) {
if(($this->formR['dirDateNaissMM'] % 2) != 0 )
{
if($this->formR['dirDateNaissJJ'] > 0 and $this->formR['dirDateNaissJJ'] < 31) {
$this->sphinx->setFilter('naiss_jour', array($this->formR[dirDateNaissJJ]));
}
} else {
if($this->formR['dirDateNaissJJ'] > 0 and $this->formR['dirDateNaissJJ'] < 29) {
$this->sphinx->setFilter('naiss_jour', array($this->formR[dirDateNaissJJ]));
}
}
}
} else {
if(!empty($this->formR['dirDateNaissJJ'])) {
$this->sphinx->setFilter('naiss_jour', array($this->formR[dirDateNaissJJ]));
}
}
if($this->formR['dirDateNaissAAAA'] > 0 and $this->formR['dirDateNaissAAAA'] < date('Y')) {
$this->sphinx->setFilter('naiss_annee', array($this->formR[dirDateNaissAAAA]));
}
}
public function removeSmallWord($rs)
{
$words = new Words();
$wordformRS = $words->wordformRS;
$array = explode(' ', $rs);
if(count($array) > 1) {
foreach($array as $item) {
if(strlen($item) > 1 and !in_array(strtoupper($item), $wordformRS)) {
$request .= $item.' ';
} else if (strlen($item) == 1) {
$this->acronyme .= $item;
}
}
}
return ((empty($request))?$rs:$request);
}
public function formatAdress($adress)
{
$words = new Words();
$adrRef = $words->adrRef;
$adr = explode(' ', $adress);
foreach($adr as $item) {
if(!empty($adrRef)) {
if(!in_array($item, $adrRef)) {
$request .= $item.' ';
}
}
}
return ($request);
}
public function countQorum()
{
$i=0;
$val = explode(' ', $this->formR['raisonSociale']);
foreach($val as $item) {
if(empty($item))
unset($val[$i]);
$i++;
}
return (count($val));
}
public function countQorumR()
{
$i=0;
$val = explode(' ', $this->formR['Voie']);
foreach($val as $item) {
if(empty($item))
unset($val[$i]);
$i++;
}
return (count($val));
}
public function detectedSequance()
{
$sequance = "";
foreach($this->formR as $name => $form) {
if($name != 'SPH_MATCH' and !empty($this->formR[$name])) {
$sequance .= '.'.ConfigurationEnt::$app_form[$name];
$values .= $name.', ';
}
}
$sequance = substr($sequance,1);
if($sequance == 'S.S') {return 'S';}
return ($sequance);
}
protected function RequestAdress($sequances, $quorum = false)
{
$request = '';
$adresse = '@adresse "';
$ville = '@ville "';
$naf = '@ape_etab "';
if(!is_array($sequances))$sequances = explode('.', $sequances);
if(in_array('V', $sequances)) {$request .= $ville.str_replace('-', ' ', $this->formR['Ville']).'" '.(($quorum and $quorum[0] == 'V')?'/'.$quorum[1]:null);}
if(in_array('F', $sequances)) {$request .= $naf.$this->formR['naf'].'"';}
if(in_array('R', $sequances)) {$request .= $adresse.$this->formR['Voie'].'" '.(($quorum and $quorum[0] == 'R')?'/'.$quorum[1]:null);}
return ($request);
}
protected function constructRaisonSocialeRequest($sequances, $quorum, $seq)
{
$request = '@nom ';
$diff = explode('.', $sequances);
switch($seq)
{
case 'quorum':
$this->sphinx->AddQuery($request.' "'.$this->formR['raisonSociale'].'" ~10 '.(($quorum[0] >= 1)?'/'.$quorum[0]:' '.$this->RequestAdress($diff)));
return (true);
case 'space':
$req = $request.'"'.str_replace(' ', '', $this->formatRaisonSociale($this->formR['raisonSociale'])).'" '.$this->RequestAdress($diff).' | ';
$req .= $request.'"'.str_replace(' ', '', $this->formatRaisonSociale($this->formR['raisonSociale'], true)).'" '.$this->RequestAdress($diff);
$this->sphinx->AddQuery($req);
return (true);
case 'double':
if(strlen($this->formR[$name]) > 5) {
$req = $request.'"'.$this->formatRaisonSociale($this->formR['raisonSociale'], true).'" '.$this->RequestAdress($diff).' | ';
$req .= $request.'"'.$this->formatRaisonSociale($this->formR['raisonSociale'], true).'" '.(($quorum[0] >= 1)?'/'.$quorum[0]:'').' '.$this->RequestAdress($diff);
$this->sphinx->AddQuery($req);
return (true);
}
return (true);
case 'points':
$this->sphinx->AddQuery($request.'"'.str_replace('.', '', $this->formR['raisonSociale']).'" '.$this->RequestAdress($diff));
return (true);
case 'acrony':
if(!empty($this->acronyme) and strlen($this->acronyme) > 2) {
$this->sphinx->AddQuery($request.'"'.$this->acronyme.' '.$this->formatRaisonSociale($this->formR['raisonSociale']).'"/'.$quorum[0].' '.$this->RequestAdress($diff));
}
return (true);
case 'split':
for($count=0;$count < 2; $count++)
{
$rs = (($i == 0)?trim($this->formR['raisonSociale']):str_replace('.', '', trim($this->formR['raisonSociale'])));
$precedent = '';
$request .= '(';
if(count(explode(' ', $rs)) == 1) {
for($i=0; $i < strlen($rs); $i++) {
$precedent .= $rs[$i];
$request .= ' "'.$precedent.' '.substr($rs, $i+1).'"'.(($i+1 != strlen($rs))?' ':'');
if($i+1 < strlen($rs))
$request .= ' | ';
}
}
$request .= ($count == 0)?') |':')';
$this->sphinx->AddQuery($request.' '.$this->RequestAdress($diff));
}
return (true);
default:
$this->sphinx->AddQuery($request.'"'.$this->formatRaisonSociale($this->formR['raisonSociale']).'" '.$this->RequestAdress($diff));
return (true);
}
return (false);
}
protected function constructQuerySequance($sequances, $quorum, $seq)
{
$request = "";
$this->sphinx->ResetFilters();
switch($this->index) {
case 'ent':
$diff = explode('.', $sequances);
foreach(ConfigurationEnt::$app_form as $name => $crit)
{
if(in_array($crit, $diff)) {
switch($name)
{
case 'cpVille':
$str = $this->formatCP($this->formR[$name]);
if($str != false) {$this->sphinx->AddQuery($adresse.$str);}
break;
case 'siren':
if(strlen($this->formR[$name]) == 14) {
$this->sphinx->setFilter('siren', array(substr($this->formR[$name], 0, 9)));
$this->sphinx->setfilter('nic', array(substr($this->formR[$name], 9)));
} else if (strlen($this->fomrR[$name]) == 9) {
$this->sphinx->setFilter('siren', array($this->formR[$name]));
}
break;
case 'numeroVoie':
$this->sphinx->setFilter('adr_num', array($this->formR[$name]));
break;
default:
$request .= $this->formR[$name].' ';
}
}
}
if($adresse != '@adresse "') {$request = $request .' '.$adresse.'"'. (($quorum[1]!=false)?'/'.$quorum[1]:'');}
if($ville != '@ville "')$request = $request .' '.$ville.'"';
if($naf != '@ape_etab "')$request .= ' '.$naf.'"';
break;
case 'dir':
foreach($this->formR as $name => $valeur) {
switch($name) {
case 'nom':
if(!empty($this->formR[$name]))
$request .= '@nom "'.$this->formR[$name].'" ';
break;
case 'prenom':
if(!empty($this->formR[$name]))
$request .= '@prenom "'.$this->formR[$name].'" ';
break;
case 'dirDateNaissJJ':
if(!empty($this->formR[$name]))
$this->sphinx->setFilter('naiss_jour', array(intval($this->formR[$name])));
break;
case 'dirDateNaissMM':
if(!empty($this->formR[$name]))
$this->sphinx->setFilter('naiss_mois', array(intval($this->formR[$name])));
break;
case 'dirDateNaissAAAA':
if(!empty($this->formR[$name]))
$this->sphinx->setFilter('naiss_annee', array(intval($this->formR[$name])));
break;
case 'cpVille':
if(!empty($this->formR[$name]))
$this->formatCP($this->formR[$name]);
break;
case 'Ville':
if(!empty($this->formR[$name]))
$request .= ' @ville "'.$this->formR[$name].'"';
break;
}
}
break;
case 'act':
foreach($this->formR as $name => $valeur) {
switch($name) {
case 'actNomRs':
if(!empty($this->formR[$name])) {
$request .= '@RaisonSociale "'.strtolower($this->formR[$name]).'"';
if(isset($quorum)) {
$request .= ' /'.$quorum;
}
}
break;
case 'cpVille':
if(!empty($this->formR[$name]))
$this->formatCP($this->formR[$name]);
break;
case 'pays':
if(!empty($this->formR[$name]))
$request .= '@Pays "'.$this->formR[$name].'"';
break;
case 'pctMin':
case 'pctMax':
if(!empty($this->formR['pcMin']) and (!empty($this->formR['pcMax']))) {
$this->sphinx->setFilterRange('pcMin', intval($this->formR['pcMin']), intval($this->formR['pcMax']));
} else if (!empty($this->formR['pcMax']) and empty($this->formR['pcMin'])) {
$this->sphinx->setFilterRange('pcMin', 0, intval($this->formR['pcMax']));
} else if (!empty($this->formR['pcMin']) and empty($this->formR['pcMax'])) {
$this->sphinx->setFilterRange('pcMin', intval($this->formR['pcMin']), 100);
}
break;
}
}
break;
case 'ciblage':
break;
default:
}
return ($request);
}
protected function levenshteinCrit($crit)
{
$pertinance = 0;
$weight = array('I' => 10, 'S' => 9, 'D' => 6, 'L' => 4, 'V' => 5, 'N' => 2, 'R' => 3);
$crit = explode('.', $crit);
for($i=0; $i < count($crit); $i++) {
$pertinance += $weight[$crit[$i]];
}
return ($pertinance);
}
protected function checkParamsRS($rs)
{
if(strlen($rs) > 3)
return (false);
else
return (true);
}
protected function getPertinence($formR, $mySql)
{
$formR = strtoupper($formR);
$mySql = strtoupper($mySql);
$array = explode(' ', $mySql);
$array2 = explode(' ', $formR);
for($i = 0;$i < count($array2); $i++) {
if(in_array($array2[$i], $array)) {
$size += levenshtein($formR, $mySql);
}
}
return (($size)?$size:100);
}
public function getResponse($resSphinx)
{
$i= 0;
$response = array();
switch($this->index) {
case 'ent':
$sql = 'SELECT id, rang, raisonSociale, CONCAT(siren, nic) AS siret, rang, siren, nic, siege, raisonSociale,
sigle, enseigne, (siren > 200) AS sirenValide, adr_num, adr_typeVoie, adr_libVoie, adr_comp, adr_cp,
adr_ville, tel, fax, cj, actif, ape_etab, ape_entrep, identite_pre FROM etablissements WHERE id IN (';
foreach($resSphinx['matches'] as $elements) {
$sql .= $elements['id'];
if($i+1 < count($resSphinx['matches']))
$sql .= ', ';
$i++;
}
$sql .= ") ORDER BY sirenValide DESC, rang DESC, actif DESC, siege DESC";
break;
case 'dir':
$sql = 'SELECT d.id as iddirigeant, e.id, e.raisonSociale, 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, ape_entrep, d.nom, d.prenom, l.libelle AS fonction_lib from dirigeants d, etablissements e, bodacc_fonctions l WHERE d.id IN (';
foreach($resSphinx['matches'] as $elements) {
$sql .= $elements['id'];
if($i+1 < count($resSphinx['matches']))
$sql .= ', ';
$i++;
}
$sql .= ' ) AND d.siren=e.siren and d.fonction_code=l.codeFct AND e.siege=1 GROUP BY d.siren, d.id ORDER BY e.rang DESC, e.actif DESC, e.siege DESC, e.id ASC';
break;
case 'act':
$sql = 'SELECT DISTINCT e.siren, l.id AS lienId, l.actif AS lienActif, l.source, l.Pmin, l.PpPm, l.id2, '.
'l.Siren2, l.RaisonSociale as nomRS, l.Pays, '.
'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, '.
'e.id, CONCAT(siren,nic) AS siret, siren, nic, siege, e.raisonSociale, sigle, '.
'enseigne, adr_num, adr_typeVoie, adr_libVoie, adr_comp, adr_cp, adr_ville, '.
'tel, fax, cj, e.actif, ape_etab, ape_entrep, e.rang '.
'FROM liens l, etablissements e '.
'WHERE l.id IN (';
foreach($resSphinx['matches'] as $elements) {
$sql .= $elements['id'];
if($i+1 < count($resSphinx['matches']))
$sql .= ', ';
$i++;
}
$sql .= ") AND l.Siren1=e.siren AND siege=1 AND e.actif=1 ORDER BY e.rang DESC";
break;
case 'Histo' :
$sql = 'SELECT Histo as Loc, id, nomFichier, annee1, bod, texte FROM bodacc_cor WHERE id IN ( ';
foreach($resSphinx['matches'] as $elements) {
$sql .= $elements['id'];
if($i+1 < count($resSphinx['matches']))
$sql .= ', ';
$i++;
}
$sql .= ')';
break;
}
$i = 0;
$db = $this->databaseJO();
$result = $db->query($sql);
while($row = mysqli_fetch_assoc($result)) {
if($this->index != 'Histo') {
$response['reponses'][$i]['id'] = $row['id'];
$response['reponses'][$i]['Siret'] = $row['siret'];
$response['reponses'][$i]['Siren'] = $row['siren'];
$response['reponses'][$i]['Nic'] = $row['nic'];
$response['reponses'][$i]['Siege'] = $row['siege'];
$response['reponses'][$i]['Nom'] = $row['raisonSociale'];
$response['reponses'][$i]['Nom2'] = '';
$response['reponses'][$i]['Adresse'] = $row['adr_num'].' '.$row['adr_typeVoie'].' '.$row['adr_libVoie'];
$response['reponses'][$i]['Adresse2'] = $row['adr_comp'];
$response['reponses'][$i]['CP'] = $row['adr_cp'];
$response['reponses'][$i]['Ville'] = $row['adr_ville'];
$response['reponses'][$i]['Tel'] = $row['tel'];
$response['reponses'][$i]['Fax'] = $row['fax'];
$response['reponses'][$i]['FJ'] = $row['cj'];
$response['reponses'][$i]['Actif'] = $row['actif'];
$response['reponses'][$i]['NafEtab'] = $row['ape_etab'];
$response['reponses'][$i]['NafEnt'] = $row['ape_entrep'];
}
switch($this->index) {
case 'ent':
$pertinence = $this->getPertinence($this->formR['raisonSociale'], $row['raisonSociale']);
$response['reponses'][$i]['Pertinence'] = $pertinence;
$response['reponses'][$i]['rang'] = $row['rang'];
if(ConfigurationEnt::$debug)
$response['reponses'][$i]['RequeteIndexation'] = array('Raison Sociale' => str_replace('\'', ' ', $row['raisonSociale']),
'Enseigne' => str_replace('\'', ' ', $row['enseigne']),
'Sigle' => str_replace('\'', ' ', $row['sigle']),
'Identite Pre' => ((array_count_values(explode(' ', str_replace('\'', ' ', $row['identite_pre']))) > 1)?explode('-', $row['identite_pre']):explode(' ', str_replace('\'', ' ', $row['identite_pre']))),
'Formulaire' => str_replace('\'', ' ', mb_strtoupper(strtr($this->formR['raisonSociale'], 'ÉÈÊË', 'EEEEE'), 'UTF-8'))
);
break;
case 'act':
$response['reponses'][$i]['ActNomRs'] = $row['nomRS'];
$response['reponses'][$i]['ActPays'] = $row['Pays'];
$response['reponses'][$i]['ActDateLien'] = $row['dateLien'];
$response['reponses'][$i]['ActActif'] = $row['actif'];
$response['reponses'][$i]['ActPmin'] = $row['Pmin'];
if(ConfigurationAct::$debug)
$response['reponses'][$i]['RequeteIndexation'] = array('Raison Sociale' => str_replace('\'', ' ', strtoupper($row['nomRS'])),
'Formulaire' => str_replace('\'', ' ', strtoupper($this->formR['actNomRs'])),
);
break;
case 'dir':
$response['reponses'][$i]['DirRs'] = '';
$response['reponses'][$i]['DirNom'] = $row['nom'];
$response['reponses'][$i]['DirPrenom'] = $row['prenom'];
$response['reponses'][$i]['DirNomUsage'] = '';
$response['reponses'][$i]['DirDateEffet'] = '';
$response['reponses'][$i]['DirFonction'] = $row['fonction_lib'];
$response['reponses'][$i]['DirDepart'] = '';
$response['reponses'][$i]['iddirigeant'] = $row['iddirigeant'];
break;
case 'Histo':
$response['reponses'][$i]['Localisation'] = $row['Loc'];
$response['reponses'][$i]['Fichier'] = $row['nomFichier'];
$response['reponses'][$i]['Annee'] = $row['annee'];
$response['reponses'][$i]['Code'] = $row['bod'];
$response['reponses'][$i]['Texte'] = $row['texte'];
$response['reponses'][$i]['id'] = $row['id'];
$response['reponses'][$i]['Pertinence'] = $resSphinx[$row['id']]['weight'];
break;
}
$i++;
}
$response['criteres'] = $this->criteresLetters;
$response['nbReponsesTotal'] = $resSphinx['total'];
$response['duree'] = $this->limits['total_time'];
$response['nbReponses'] = count($response['reponses']);
return ($response);
}
public function setForm($form) {
$this->formR = $form;
}
public function setSphinx($sphinx) {
$this->sphinx = $sphinx;
}
public function execute($sphinx) {
$this->sphinx = $sphinx;
return $this->search();
}
public function setTime($time) {
if($this->limits['total_time'])
$this->limits['total_time'] += $time;
}
public function setDeb($deb) {
$this->deb = $deb;
}
public function setIndex($index) {
$this->index = $index;
}
public function getSequances() {
return ($this->sequancesArray);
}
public function setNumberResults($NumberResults) {
$this->NumberResults = $NumberResults;
}
public function setMaxResults($MaxResults) {
$this->MaxResults = $MaxResults;
}
/***************************************************************************************************************/
}
?>