Library Update

This commit is contained in:
Michael RICOIS 2017-01-16 09:20:51 +01:00
parent 8156f83c10
commit 6f451a0240
3 changed files with 71 additions and 63 deletions

View File

@ -2081,7 +2081,7 @@ class Metier_Insee_MInsee extends Metier_Insee_Table
$tdeb = microtime(1);
}
$iTel = new Metier_Partenaires_MTel($this->iDb);
$iTel = new Metier_Partenaires_MTel();
$tmp = $iTel->getTel($siren, $nic, true, 1);
if ($this->debugtime) {

View File

@ -1,15 +1,15 @@
<?php
class Metier_Partenaires_MTel
{
public $iDb;
/**
* PDO Connection with Doctrine
* @var \Doctrine\DBAL\Connection
*/
protected $conn;
public function __construct($db = null)
public function __construct()
{
if ($db === null) {
$this->iDb = new Metier_Util_Db();
} else {
$this->iDb = $db;
}
$this->conn = Zend_Registry::get('doctrine');
}
/**
@ -24,83 +24,91 @@ class Metier_Partenaires_MTel
{
$tabRet=array();
if (strlen($siret)>9) {
if (strlen($siret) > 9) {
$nic = substr($siret, -5)*1;
$siren = round($siret/100000)*1;
} else {
$siren=$siret*1;
$siren = $siret*1;
}
if ($siren<1000) {
if ($siren < 1000) {
return $tabRet;
}
/** Si le siren est de taille < à 9, on ajoute des 0 significatifs **/
if (strlen($siren)<=9) {
if (strlen($siren) <= 9) {
$siren = str_pad($siren, 9, '0', STR_PAD_LEFT);
}
if (strlen($nic)>0) {
if (strlen($nic) > 0) {
$nic = str_pad($nic, 5, '0', STR_PAD_LEFT);
}
$strNic='';
if ($nic*1>0) {
$strNic="AND (nic=$nic OR nic=0)";
$strNic = '';
if ($nic*1 > 0) {
$strNic = "AND (nic=$nic OR nic=0)";
}
$strActif='';
if ($actif==1) {
$strActif=" AND actif=1 ";
} elseif ($actif==0) {
$strActif=" AND actif=0 ";
$strActif = '';
if ($actif == 1) {
$strActif = " AND actif=1 ";
} elseif ($actif == 0) {
$strActif = " AND actif=0 ";
}
$ret=$this->iDb->select(
'jo.telephonie',
'siren,nic,dateProvPartenaire,typeTel,infoTel,LPAD(telephone,10,0) AS telephone,actif,partenaire,idUtilisateur,dateInsert,dateInsert*1 AS dateInsertYmd,dateConfPartenaire,partenaireConf,nbConf,idUpdate,dateUpdate,dateUpdate*1 AS dateUpdateYmd',
"siren=$siren $strNic $strActif AND dateSuppr=0 ORDER BY typeTel ASC, nbConf DESC", false, MYSQL_ASSOC);
if (count($ret)>0) {
$this->enCache=true;
foreach ($ret as $tabTel) {
if ($tabTel['typeTel']=='an8' && $tabTel['infoTel']*1>0) {
$an8=$tabTel['infoTel']*1;
$retTmp=$this->iDb->select('jo.tabAn8', 'libAn8', "codAn8='$an8'", false, MYSQL_ASSOC);
$infoTel=ucfirst(strtolower($retTmp[0]['libAn8']));
$sql = "SELECT siren, nic, dateProvPartenaire, typeTel, infoTel, LPAD(telephone,10,0) AS telephone,
actif, partenaire, idUtilisateur, dateInsert, dateInsert*1 AS dateInsertYmd, dateConfPartenaire,
partenaireConf, nbConf, idUpdate, dateUpdate, dateUpdate*1 AS dateUpdateYmd
FROM jo.telephonie WHERE siren=:siren $strNic $strActif AND dateSuppr=0
ORDER BY typeTel ASC, nbConf DESC";
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('siren', $siren);
$stmt->execute();
if ($stmt->rowCount() > 0) {
$this->enCache = true;
while ($tabTel = $stmt->fetch(\PDO::FETCH_ASSOC)) {
if ($tabTel['typeTel'] == 'an8' && $tabTel['infoTel']*1 > 0) {
$an8 = $tabTel['infoTel']*1;
$an8Stmt = $this->conn->executeQuery($query);
$infoTel = '';
if ($an8Stmt->rowCount() > 0) {
$label = $an8Stmt->fetchColumn('libAn8');
$infoTel = ucfirst(strtolower($label));
}
} else {
$infoTel=$tabTel['infoTel'];
$infoTel = $tabTel['infoTel'];
}
if ($tabTel['partenaireConf']>0) {
$source=$tabTel['partenaireConf'];
if ($tabTel['partenaireConf'] > 0) {
$source = $tabTel['partenaireConf'];
} else {
$source=$tabTel['partenaire'];
$source = $tabTel['partenaire'];
}
if ($tabTel['dateUpdateYmd']>$tabTel['dateInsertYmd']) {
$dateMAJ=$tabTel['dateUpdateYmd'];
if ($tabTel['dateUpdateYmd'] > $tabTel['dateInsertYmd']) {
$dateMAJ = $tabTel['dateUpdateYmd'];
} else {
$dateMAJ=$tabTel['dateInsertYmd'];
$dateMAJ = $tabTel['dateInsertYmd'];
}
$tabR = array(
'siren'=>$siren,
'nic'=>$tabTel['nic'],
'typeTel'=>$tabTel['typeTel'],
'infoTel'=>$infoTel,
'telephone'=>$tabTel['telephone'],
'actif'=>$tabTel['actif'],
'source'=>$source,
'dateMAJ'=>$dateMAJ,
'siren' => $siren,
'nic' => $tabTel['nic'],
'typeTel' => $tabTel['typeTel'],
'infoTel' => $infoTel,
'telephone' => $tabTel['telephone'],
'actif' => $tabTel['actif'],
'source' => $source,
'dateMAJ' => $dateMAJ,
);
$tabRet[]=$tabR;
$tabRet[] = $tabR;
if ($last) {
if ($source==175 && !@isset($tabLast[$tabTel['typeTel']][1])) {
@$tabLast[$tabTel['typeTel']][1]=$tabR;
} elseif (($source==118 || $source==250 || $source==253) &&
if ($source == 175 && !@isset($tabLast[$tabTel['typeTel']][1])) {
@$tabLast[$tabTel['typeTel']][1] = $tabR;
} elseif (($source == 118 || $source == 250 || $source == 253) &&
!@isset($tabLast[$tabTel['typeTel']][2])) {
@$tabLast[$tabTel['typeTel']][2]=$tabR;
} elseif ($source<>2 && !@isset($tabLast[$tabTel['typeTel']][3])) {
@$tabLast[$tabTel['typeTel']][3]=$tabR;
} elseif ($source==2 && !@isset($tabLast[$tabTel['typeTel']][4])) {
@$tabLast[$tabTel['typeTel']][4]=$tabR;
@$tabLast[$tabTel['typeTel']][2] = $tabR;
} elseif ($source != 2 && !@isset($tabLast[$tabTel['typeTel']][3])) {
@$tabLast[$tabTel['typeTel']][3] = $tabR;
} elseif ($source == 2 && !@isset($tabLast[$tabTel['typeTel']][4])) {
@$tabLast[$tabTel['typeTel']][4] = $tabR;
}
}
}
@ -111,7 +119,7 @@ class Metier_Partenaires_MTel
if ($tabLast != null && count($tabLast) > 0) {
foreach ($tabLast as $typeTel=>$tabPriorite) {
ksort($tabPriorite);
$tabRet[]=current($tabPriorite);
$tabRet[] = current($tabPriorite);
}
}
}

View File

@ -443,27 +443,27 @@ class Metier_Sfr_Scoring
$classInsee = new Metier_Insee_MInsee();
//Values are already define ?
// Values are already define ?
if ($this->ValDateCalculIndiscore === null) {
//Vérifier la présence d'un calcul dans la table scores_surveillances
// Vérifier la présence d'un calcul dans la table scores_surveillances
$sql = "SELECT * FROM jo.scores_surveillance WHERE siren=:siren";
$stmt = $this->conn->prepare($sql);
$stmt->bindValue('siren', $siren);
$stmt->execute();
//No results
if ($stmt->rowCount() && $this->notCalculateInError) {
// No results
if ($stmt->rowCount() == 0 && $this->notCalculateInError) {
return false;
}
$result = $stmt->fetch(\PDO::FETCH_OBJ);
//No score
// No score
if (intval($result->indiScoreDate) == 0 && $this->notCalculateInError) {
return false;
}
if ($result !== null) {
if ($stmt->rowCount() > 0) {
//Indiscore - aller chercher scores dans l'historique moins de X mois
$dateUpdate = DateTime::createFromFormat('Y-m-d', substr($result->dateUpdate, 0, 10));