414 lines
9.7 KiB
PHP
414 lines
9.7 KiB
PHP
<?php
|
|
require_once 'sphinxapi/sphinxapi-2.0.2.php';
|
|
|
|
Class Ciblage
|
|
{
|
|
private $sphinx;
|
|
private $alpha = '';
|
|
private $presentRcs = 0;
|
|
|
|
public $index = 'ciblage';
|
|
|
|
public $nb_results = 5000;
|
|
public $max_results = 500000;
|
|
|
|
public $mysql_host = '192.168.78.230';
|
|
public $mysql_user = 'sphinx';
|
|
public $mysql_password = 'indexer';
|
|
public $mysql_database = 'jo';
|
|
|
|
public $sphinx_host = '192.168.78.252';
|
|
public $sphinx_port = 3312;
|
|
public $sphinx_match = SPH_MATCH_EXTENDED2;
|
|
public $sphinx_sort = SPH_SORT_EXTENDED;
|
|
|
|
public function __construct($structure, $need = false)
|
|
{
|
|
$this->sphinx = new SphinxClient();
|
|
$this->sphinx->SetServer($this->sphinx_host, $this->sphinx_port);
|
|
$this->sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
|
|
$this->sphinx->ResetFilters();
|
|
foreach($structure as $key => $valeur)
|
|
{
|
|
if (method_exists($this, $key)) {
|
|
if(is_array($valeur)) {
|
|
if($valeur[0] != "" and $valeur[0] != 'tous'){
|
|
$this->$key($valeur);
|
|
}
|
|
} else {
|
|
if($valeur != 'tous' and $valeur != "")
|
|
$this->$key($valeur);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function calculRedevanceInsee()
|
|
{
|
|
$this->sphinx->SetFilter('presentrcs', array(0));
|
|
$resSphinx = $this->sphinx->Query($this->alpha, $this->index);
|
|
return ($resSphinx['total_found']);
|
|
}
|
|
|
|
public function execute($need = false)
|
|
{
|
|
if($need) {
|
|
$i = 0;
|
|
$siret = array();
|
|
|
|
do {
|
|
$this->sphinx->SetLimits($i, $this->nb_results, $this->max_results);
|
|
$resSphinx = $this->sphinx->Query($this->alpha, $this->index);
|
|
if($resSphinx['total'] > 0) {
|
|
foreach($resSphinx['matches'] as $matches) {
|
|
if($matches['attrs']['presentrcs'] == 0)
|
|
$siret[] = $matches['attrs']['siren'];
|
|
}
|
|
$i += $this->nb_results;
|
|
}else
|
|
break;
|
|
} while($i < $resSphinx['total_found']);
|
|
return ($resSphinx['total_found']);
|
|
} else {
|
|
$resSphinx = $this->sphinx->Query($this->alpha, $this->index);
|
|
}
|
|
return ($resSphinx['total_found']);
|
|
}
|
|
|
|
protected function setFilter($name, $valeur) {
|
|
if(!is_array($valeur)) {
|
|
$this->sphinx->SetFilter($name, array(intval($valeur)));
|
|
}else {
|
|
$this->sphinx->SetFilter($name, $this->transformIntval($valeur));
|
|
}
|
|
}
|
|
|
|
protected function setFilterRange($name, $valeur) {
|
|
$this->sphinx->SetFilterRange($name, intval($valeur[0]), intval($valeur[1]));
|
|
}
|
|
|
|
protected function writeRequest($name, $valeur, $or = false) {
|
|
if(!is_array($valeur)) {
|
|
if($or and !empty($this->alpha))
|
|
$this->alpha .= ' | ';
|
|
$this->alpha .= '@'.$name.' '.$valeur.' ';
|
|
} else {
|
|
$i = 0;
|
|
if($or and !empty($this->alpha))
|
|
$this->alpha .= ' | ';
|
|
foreach($valeur as $item) {
|
|
if($i != 0)
|
|
$this->alpha .= ' | ';
|
|
$this->alpha .= '@'.$name.' '.$item.' ';
|
|
$i++;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected function setAlpha($name, $valeur)
|
|
{
|
|
$or = array('bilType');
|
|
$and = array('ape_entrep', 'ape_etab', 'age_entrep', 'age_etab', 'NaceEntrep', 'NaceEtab');
|
|
|
|
if(in_array($name, $or)) {
|
|
if(!empty($valeur))
|
|
$this->writeRequest($name, $valeur, true);
|
|
} else if (in_array($name, $and)) {
|
|
if(!empty($valeur))
|
|
$this->writeRequest($name, $valeur);
|
|
}
|
|
}
|
|
|
|
protected function transformIntval($array) {
|
|
$copy = array();
|
|
foreach($array as $item => $valeur) {
|
|
$copy[$item] = intval($valeur);
|
|
}
|
|
return ($copy);
|
|
}
|
|
|
|
protected function dirNom($valeur) {
|
|
$this->setFilter('dirNom', $valeur);
|
|
}
|
|
|
|
protected function siege($valeur) {
|
|
$this->setFilter('siege', $valeur);
|
|
}
|
|
|
|
protected function adr_cp($valeur) {
|
|
$this->setFilter('adr_cp', $valeur);
|
|
}
|
|
|
|
protected function adr_dep($valeur) {
|
|
$this->setAlpha('adr_dep', $valeur);
|
|
}
|
|
|
|
protected function adr_com($valeur) {
|
|
$this->setFilter('adr_com', $valeur);
|
|
}
|
|
|
|
protected function tel($valeur) {
|
|
$this->setFilter('tel', $valeur);
|
|
}
|
|
|
|
protected function fax($valeur) {
|
|
$this->setFilter('fax', $valeur);
|
|
}
|
|
|
|
protected function cj($valeur) {
|
|
$this->setFilter('cj', $valeur);
|
|
}
|
|
|
|
protected function capital($valeur) {
|
|
if($valeur[0] != 0 or $valeur[1] != 0)
|
|
$this->setFilterRange('capital', $valeur);
|
|
}
|
|
|
|
protected function ape_etab($valeur) {
|
|
$this->setAlpha('ape_etab', $valeur);
|
|
}
|
|
|
|
protected function ape_entrep($valeur) {
|
|
$this->setAlpha('ape_entrep', $valeur);
|
|
}
|
|
|
|
protected function age_entrep($valeur) {
|
|
$this->setAlpha('age_entrep', $valeur);
|
|
}
|
|
|
|
protected function age_etab($valeur) {
|
|
$this->setAlpha('age_etab', $valeur);
|
|
}
|
|
|
|
protected function tcaexp($valeur) {
|
|
$this->setFilterRange('tcaexp', $valeur);
|
|
}
|
|
|
|
protected function teff_entrep($valeur) {
|
|
if($valeur[0] != 0 or $valeur[1] != 0)
|
|
$this->setFilterRange('teff_entrep', $valeur);
|
|
}
|
|
|
|
protected function teff_etab($valeur) {
|
|
if($valeur[0] != 0 or $valeur[1] != 0)
|
|
$this->setFilterRange('teff_etab', $valeur);
|
|
}
|
|
|
|
protected function rang($valeur) {
|
|
$this->setFilterRange('rang', $valeur);
|
|
}
|
|
|
|
protected function actifEco($valeur) {
|
|
$this->setFilter('actifEco', $valeur);
|
|
}
|
|
|
|
protected function presentRcs($valeur) {
|
|
$this->setFilter('presentRcs', $valeur);
|
|
}
|
|
|
|
protected function procolHisto($valeur) {
|
|
$this->setFilter('procolHisto', $valeur);
|
|
}
|
|
|
|
protected function tvaIntraValide($valeur) {
|
|
$this->setFilter('tvaIntraValide', $valeur);
|
|
}
|
|
|
|
protected function NaceEtab($valeur) {
|
|
$this->setAlpha('NaceEtab', $valeur);
|
|
}
|
|
|
|
protected function NaceEntrep($valeur) {
|
|
$this->setAlpha('NaceEntrep', $valeur);
|
|
}
|
|
|
|
protected function dateCrea_etab($valeur) {
|
|
if(!is_array($valeur)) {
|
|
$format = explode('/', $valeur);
|
|
$valeur = $format[2].$format[1].$format[0];
|
|
} else {
|
|
$format1 = explode('/', $valeur[0]);
|
|
$format2 = explode('/', $valeur[0]);
|
|
|
|
$valeur[0] = $format1[2].$format1[1].$format1[0];
|
|
$valeur[1] = $format2[2].$format2[1].$format2[0];
|
|
}
|
|
$this->setFilterRange('dateCrea_etab', $valeur);
|
|
|
|
}
|
|
|
|
protected function dateCrea_ent($valeur) {
|
|
if(!is_array($valeur)) {
|
|
$format = explode('/', $valeur);
|
|
$valeur = $format[2].$format[1].$format[0];
|
|
} else {
|
|
$format1 = explode('/', $valeur[0]);
|
|
$format2 = explode('/', $valeur[0]);
|
|
|
|
$valeur[0] = $format1[2].$format1[1].$format1[0];
|
|
$valeur[1] = $format2[2].$format2[1].$format2[0];
|
|
}
|
|
$this->setFilterRange('dateCrea_etab', $valeur);
|
|
}
|
|
|
|
protected function dateImmat($valeur) {
|
|
if(!is_array($valeur)) {
|
|
$format = explode('/', $valeur);
|
|
$valeur = $format[2].$format[1].$format[0];
|
|
} else {
|
|
$format1 = explode('/', $valeur[0]);
|
|
$format2 = explode('/', $valeur[0]);
|
|
|
|
$valeur[0] = $format1[2].$format1[1].$format1[0];
|
|
$valeur[1] = $format2[2].$format2[1].$format2[0];
|
|
}
|
|
$this->setFilterRange('dateImmat', $valeur);
|
|
}
|
|
|
|
protected function eff_entrep($valeur) {
|
|
$this->setFilter('eff_entrep', $valeur);
|
|
}
|
|
|
|
protected function eff_etab($valeur) {
|
|
$this->setFilter('eff_etab', $valeur);
|
|
}
|
|
|
|
protected function rivoli($valeur) {
|
|
$this->setFilter('rivoli', $valeur);
|
|
}
|
|
|
|
protected function nbEtab($valeur) {
|
|
$this->setFilterRange('nbEtab', $valeur);
|
|
}
|
|
|
|
protected function sirenGrp($valeur) {
|
|
$this->setFilter('sirenGrp', $valeur);
|
|
}
|
|
|
|
protected function nbActio($valeur) {
|
|
$this->setFilterRange('nbActio', $valeur);
|
|
}
|
|
|
|
protected function nbMPubli($valeur) {
|
|
$this->setFilterRange('nbMPubli', $valeur);
|
|
}
|
|
|
|
protected function nbPart($valeur) {
|
|
$this->setFilterRange('nbPart', $valeur);
|
|
}
|
|
|
|
protected function bilType($valeur) {
|
|
$this->setAlpha('bilType', $valeur);
|
|
}
|
|
|
|
protected function bilAnnee($valeur) {
|
|
$this->setFilter('bilAnnee', $valeur);
|
|
}
|
|
|
|
protected function bilTca($valeur) {
|
|
$this->setFilterRange('bilTca', $valeur);
|
|
}
|
|
|
|
protected function bilEE($valeur) {
|
|
$this->setFilterRange('bilEE', $valeur);
|
|
}
|
|
|
|
protected function bilFL($valeur) {
|
|
$this->setFilterRange('bilFL', $valeur);
|
|
}
|
|
|
|
protected function bilFK($valeur) {
|
|
$this->setFilterRange('bilFK', $valeur);
|
|
}
|
|
|
|
protected function bilFR($valeur) {
|
|
$this->setFilterRange('bilFR', $valeur);
|
|
}
|
|
|
|
protected function bilGF($valeur) {
|
|
$this->setFilterRange('bilGF', $valeur);
|
|
}
|
|
|
|
protected function bilGP($valeur) {
|
|
$this->setFilterRange('bilGP', $valeur);
|
|
}
|
|
|
|
protected function bilGU($valeur) {
|
|
$this->setFilterRange('bilGU', $valeur);
|
|
}
|
|
|
|
protected function bilGW($valeur) {
|
|
$this->setFilterRange('bilGW', $valeur);
|
|
}
|
|
|
|
protected function bilHD($valeur) {
|
|
$this->setFilterRange('bilHD', $valeur);
|
|
}
|
|
|
|
protected function bilHL($valeur) {
|
|
$this->setFilterRange('bilHL', $valeur);
|
|
}
|
|
|
|
protected function bilHM($valeur) {
|
|
$this->setFilterRange('bilHM', $valeur);
|
|
}
|
|
|
|
protected function bilHN($valeur) {
|
|
$this->setFilterRange('bilHN', $valeur);
|
|
}
|
|
|
|
protected function bilYP($valeur) {
|
|
$this->setFilterRange('bilYP', $valeur);
|
|
}
|
|
|
|
protected function avisCs($valeur) {
|
|
$this->setFilte('avisCs', $valeur);
|
|
}
|
|
|
|
protected function bilFS($valeur) {
|
|
$this->setFilterRange('bilFS', $valeur);
|
|
}
|
|
|
|
protected function lieuAct($valeur) {
|
|
$this->setFilter('lieuAct', $valeur);
|
|
}
|
|
|
|
protected function bilGG($valeur) {
|
|
$this->setFilterRange('bilGG', $valeur);
|
|
}
|
|
|
|
protected function bilGV($valeur) {
|
|
$this->setFilterRange('bilGV', $valeur);
|
|
}
|
|
|
|
protected function bilHI($valeur) {
|
|
$this->setFilterRange('bilHI', $valeur);
|
|
}
|
|
|
|
protected function adrDom($valeur) {
|
|
$this->setFilter('adrDom', $valeur);
|
|
}
|
|
|
|
protected function web($valeur) {
|
|
$this->setFilter('web', $valeur);
|
|
}
|
|
|
|
protected function mail($valeur) {
|
|
$this->setFilter('mail', $valeur);
|
|
}
|
|
|
|
protected function bilCloture($valeur) {
|
|
if(!is_array($valeur)) {
|
|
$format = explode('/', $valeur);
|
|
$valeur = $format[2].$format[1].$format[0];
|
|
} else {
|
|
$format1 = explode('/', $valeur[0]);
|
|
$format2 = explode('/', $valeur[0]);
|
|
|
|
$valeur[0] = $format1[2].$format1[1].$format1[0];
|
|
$valeur[1] = $format2[2].$format2[1].$format2[0];
|
|
}
|
|
//print_r($valeur);
|
|
$this->setFilterRange('bilCloture', $valeur);
|
|
}
|
|
} |