Ajout de l'api + moteur
ajout des fonctions dans SessionCiblage setCritere, etc..
This commit is contained in:
parent
c68f72fcb2
commit
b4c9e13c13
@ -40,6 +40,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
|
||||
|
||||
$view->headTitle()->setSeparator(' - ');
|
||||
$view->headTitle('Odea');
|
||||
Zend_Session::start();
|
||||
}
|
||||
|
||||
protected function _initLogging()
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
require_once ('Scores/Ciblage.php');
|
||||
class CriteresController extends Zend_Controller_Action
|
||||
{
|
||||
public function indexAction(){}
|
||||
@ -6,6 +7,11 @@ class CriteresController extends Zend_Controller_Action
|
||||
public function entrepriseAction()
|
||||
{
|
||||
//$this->_helper->layout()->disableLayout();
|
||||
if($this->getRequest()->isPost()) {
|
||||
$ciblage = new Ciblage($this->getRequest()->getParams());
|
||||
$result = $ciblage->execute();
|
||||
echo "<pre>";print_r($result);exit;
|
||||
}
|
||||
}
|
||||
|
||||
public function economiqueAction()
|
||||
|
407
library/Scores/Ciblage.php
Normal file
407
library/Scores/Ciblage.php
Normal file
@ -0,0 +1,407 @@
|
||||
<?php
|
||||
require_once 'sphinxapi.php';
|
||||
require_once 'configuration.php';
|
||||
|
||||
Class Ciblage
|
||||
{
|
||||
private $sphinx;
|
||||
private $alpha = '';
|
||||
private $presentRcs = 0;
|
||||
|
||||
public function __construct($structure, $need = false)
|
||||
{
|
||||
//print_r($structure);exit;
|
||||
$this->sphinx = new SphinxClient();
|
||||
$this->sphinx->SetServer(ConfigurationCiblage::$sphinx_host, ConfigurationCiblage::$sphinx_port);
|
||||
$this->sphinx->SetMatchMode(SPH_MATCH_EXTENDED2);
|
||||
$this->sphinx->ResetFilters();
|
||||
if(!empty($structure)) {
|
||||
foreach($structure as $key => $valeur)
|
||||
{
|
||||
if (method_exists($this, $key) and isset($valeur)) {
|
||||
if(count($valeur) == 1){
|
||||
$valeur = $valeur[0];}
|
||||
$this->$key($valeur);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public function calculePriceInsee($number)
|
||||
{
|
||||
return (round(($number/100)*ConfigurationGenerique::$redevance_insee, 2));
|
||||
}
|
||||
|
||||
public function calculeRedevanceInsee()
|
||||
{
|
||||
$this->sphinx->SetFilter('presentrcs', array(0));
|
||||
$resSphinx = $this->sphinx->Query($this->alpha, ConfigurationCiblage::$index);
|
||||
return ($resSphinx['total_found']);
|
||||
}
|
||||
|
||||
public function execute($need = false)
|
||||
{
|
||||
if($need) {
|
||||
$i = 0;
|
||||
$siret = array();
|
||||
|
||||
do {
|
||||
$this->sphinx->SetLimits($i, ConfigurationCiblage::$nb_results, ConfigurationCiblage::$max_results);
|
||||
$resSphinx = $this->sphinx->Query($this->alpha, ConfigurationCiblage::$index);
|
||||
if($resSphinx['total'] > 0) {
|
||||
foreach($resSphinx['matches'] as $matches) {
|
||||
if($matches['attrs']['presentrcs'] == 0)
|
||||
$siret[] = $matches['attrs']['siren'];
|
||||
}
|
||||
$i += ConfigurationCiblage::$nb_results;
|
||||
}else
|
||||
break;
|
||||
} while($i < $resSphinx['total_found']);
|
||||
return ($resSphinx['total_found']);
|
||||
} else {
|
||||
$this->sphinx->SetLimits(0, 10000, ConfigurationCiblage::$max_results);
|
||||
$resSphinx = $this->sphinx->Query($this->alpha, ConfigurationCiblage::$index);
|
||||
}
|
||||
return ($resSphinx);
|
||||
}
|
||||
|
||||
|
||||
|
||||
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('adr_cp', 'adr_dep', 'adr_com');
|
||||
$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 siege($valeur) {
|
||||
$this->setFilter('siege', $valeur);
|
||||
}
|
||||
|
||||
protected function adr_cp($valeur) {
|
||||
$this->setAlpha('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->setAlpha('cj', $valeur);
|
||||
}
|
||||
|
||||
protected function capital($valeur) {
|
||||
$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) {
|
||||
$this->setFilterRange('teff_entrep', $valeur);
|
||||
}
|
||||
|
||||
protected function teff_etab($valeur) {
|
||||
$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) {
|
||||
$this->setFilterRange('dateCrea_etab', $valeur);
|
||||
}
|
||||
|
||||
protected function dateCrea_ent($valeur) {
|
||||
$this->setFilterRange('dateCrea_etab', $valeur);
|
||||
}
|
||||
|
||||
protected function dateImmat($valeur) {
|
||||
$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->setFilter('nbEtab', $valeur);
|
||||
}
|
||||
|
||||
protected function sirenGrp($valeur) {
|
||||
$this->setFilter('sirenGrp', $valeur);
|
||||
}
|
||||
|
||||
protected function nbActio($valeur) {
|
||||
$this->setFilterRange('nbActio', $valeur);
|
||||
}
|
||||
|
||||
protected function nbPart($valeur) {
|
||||
$this->setFilterRange('nbPart', $valeur);
|
||||
}
|
||||
|
||||
protected function bilType($valeur) {
|
||||
$this->setFilter('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->setFilter('avisCs', $valeur);
|
||||
}
|
||||
|
||||
protected function bilFS($valeur) {
|
||||
$this->setFilterRange('bilFS', $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);
|
||||
}
|
||||
}
|
||||
|
||||
Class SDLocalisation
|
||||
{
|
||||
protected $regions;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
/*
|
||||
-- Métropole --
|
||||
42 Alsace
|
||||
72 Aquitaine
|
||||
83 Auvergne
|
||||
26 Bourgogne
|
||||
53 Bretagne
|
||||
24 Centre
|
||||
21 Champagne-Ardenne
|
||||
94 Corse
|
||||
43 Franche-Comté
|
||||
11 Île-de-France
|
||||
91 Languedoc-Roussillon
|
||||
74 Limousin
|
||||
41 Lorraine
|
||||
73 Midi-Pyrénées
|
||||
31 Nord-Pas-de-Calais
|
||||
25 Basse-Normandie
|
||||
23 Haute-Normandie
|
||||
52 Pays de la Loire
|
||||
22 Picardie
|
||||
54 Poitou-Charentes
|
||||
93 Provence-Alpes-Côte d'Azur
|
||||
82 Rhône-Alpes
|
||||
-----------
|
||||
--Dom-Tom--
|
||||
01 Guadeloupe
|
||||
03 Guyane
|
||||
02 Martinique
|
||||
05 Mayotte
|
||||
04 La Réunion
|
||||
-----------
|
||||
*/
|
||||
$this->regions = array(31 => array(62, 59),
|
||||
22 => array(80, 60, 02),
|
||||
23 => array(76, 27),
|
||||
25 => array(50, 14, 61),
|
||||
53 => array(29, 22, 56, 35),
|
||||
52 => array(53, 72, 49, 44, 85),
|
||||
24 => array(28, 45, 41, 37, 36, 18),
|
||||
11 => array(78, 91, 95, 77, 92, 75, 93, 94),
|
||||
21 => array(08, 51, 10, 52),
|
||||
26 => array(89, 21, 58, 71),
|
||||
41 => array(55, 54, 88, 57),
|
||||
42 => array(67, 68),
|
||||
43 => array(70, 25, 39),
|
||||
82 => array(42, 69, 01, 74, 07, 38, 73, 26),
|
||||
26 => array(06, 63, 15, 43),
|
||||
74 => array(87, 23, 19),
|
||||
54 => array(79, 86, 17, 16),
|
||||
72 => array(33, 24, 47, 40, 64),
|
||||
73 => array(65, 32, 82, 46, 12, 81, 31, 09),
|
||||
91 => array(48, 30, 34, 11, 66),
|
||||
93 => array(05, 84, 13, 83, 04, 06),
|
||||
94 => array(200, 201)
|
||||
);
|
||||
}
|
||||
|
||||
public function getFilterByRegion($dept)
|
||||
{
|
||||
$stdClass = new stdClass();
|
||||
foreach($this->regions as $name => $departements) {
|
||||
if(in_array($dept, $departements))
|
||||
return ($departements);
|
||||
}
|
||||
return (EXIT_FAILURE);
|
||||
}
|
||||
}
|
@ -1,16 +1,56 @@
|
||||
<?php
|
||||
class SessionCiblage
|
||||
{
|
||||
protected $criteres = array();
|
||||
protected $criteres = array('siege', 'adr_cp', 'adr_dep', 'adr_com', 'tel', 'fax', 'cj', 'capital', 'ape_etab', 'ape_entrep', 'age_entrep',
|
||||
'age_etab', 'tcaexp', 'teff_entrep', 'teff_etab', 'rang', 'actifEco', 'presentRcs', 'procolHisto', 'tvaIntraValide',
|
||||
'NaceEtab', 'NaceEntrep', 'dateCrea_etab', 'dateCrea_ent', 'dateImmat', 'eff_entrep', 'eff_etab', 'rivoli', 'nbEtab',
|
||||
'sirenGrp', 'nbActio', 'nbPart', 'bilType', 'bilAnnee', 'avisCs', 'bilTca', 'bilEE', 'bilFL', 'bilFK', 'bilFR', 'bilGF', 'bilGP',
|
||||
'bilGU', 'bilGW', 'bilHD', 'bilHL', 'bilHM', 'bilHN', 'bilYP', 'bilFS', 'bilGG', 'bilGV', 'bilHI'
|
||||
);
|
||||
protected $valeur;
|
||||
|
||||
public function setCritere(){}
|
||||
public function __construct()
|
||||
{
|
||||
$session = new Zend_Session_Namespace('ciblage');
|
||||
$this->valeur = $session->ciblage;
|
||||
}
|
||||
|
||||
public function setCriteres(){}
|
||||
protected function setSession()
|
||||
{
|
||||
$session = new Zend_Session_Namespace();
|
||||
|
||||
if($session->isLocked()) {
|
||||
$session->unlock();
|
||||
$session->ciblage = $this->valeur;
|
||||
$session->lock();
|
||||
}
|
||||
}
|
||||
|
||||
public function unsetCritere(){}
|
||||
public function setCritere($key, $value)
|
||||
{
|
||||
if(in_array($key, $this->criteres)) {
|
||||
$this->valeur[$key] = $value;
|
||||
$session = new Zend_Session_Namespace();
|
||||
$this->setSession();
|
||||
}
|
||||
}
|
||||
|
||||
public function getCritere(){}
|
||||
public function setCriteres($criteres){}
|
||||
|
||||
public function getCriteres(){}
|
||||
public function unsetCritere($key)
|
||||
{
|
||||
if(key_exists($key, $this->valeur)) {
|
||||
unset($this->valeur[$key]);
|
||||
$this->setSession();
|
||||
}
|
||||
}
|
||||
|
||||
public function getCritere()
|
||||
{
|
||||
}
|
||||
|
||||
public function getCriteres()
|
||||
{
|
||||
/* @todo provisoir... prévoir une verification*/
|
||||
}
|
||||
}
|
33
library/Scores/configuration.php
Normal file
33
library/Scores/configuration.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
define('MYSQL_HOST', '192.168.78.230');
|
||||
define('MYSQL_USER', 'sphinx');
|
||||
define('MYSQL_PASS', 'indexer');
|
||||
define('MYSQL_DEFAULT_DB', 'jo');
|
||||
|
||||
Class ConfigurationGenerique
|
||||
{
|
||||
public static $debug = true;
|
||||
public static $redevance_insee = 3.295;
|
||||
public static $api = '2.0.2';
|
||||
public function __construct(){set_limit(0);}
|
||||
}
|
||||
|
||||
Class ConfigurationCiblage extends ConfigurationGenerique
|
||||
{
|
||||
public static $index = 'ciblage';
|
||||
|
||||
public static $nb_results = 5000;
|
||||
public static $max_results = 500000;
|
||||
|
||||
public static $mysql_host = MYSQL_HOST;
|
||||
public static $mysql_user = MYSQL_USER;
|
||||
public static $mysql_password = MYSQL_PASS;
|
||||
public static $mysql_database = MYSQL_DEFAULT_DB;
|
||||
|
||||
|
||||
public static $sphinx_host = '192.168.78.252';
|
||||
public static $sphinx_port = 3312;
|
||||
public static $sphinx_match = SPH_MATCH_EXTENDED2;
|
||||
public static $sphinx_sort = SPH_SORT_EXTENDED;
|
||||
}
|
1712
library/Scores/sphinxapi.php
Executable file
1712
library/Scores/sphinxapi.php
Executable file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user