Nettoyage + Doctrine
This commit is contained in:
parent
553daa922a
commit
81a4903082
@ -1,27 +1,40 @@
|
|||||||
<?php
|
<?php
|
||||||
|
require_once 'framework/common/curl.php';
|
||||||
|
|
||||||
class Metier_Partenaires_MQualibat
|
class Metier_Partenaires_MQualibat
|
||||||
{
|
{
|
||||||
private $referer ='';
|
protected $iBodacc;
|
||||||
private $body = '';
|
protected $iInsee;
|
||||||
private $header = '';
|
|
||||||
private $cookie = '';
|
|
||||||
private $codeRetour = 0;
|
|
||||||
private $accesDist=true;
|
|
||||||
private $iDb;
|
|
||||||
private $iBodacc;
|
|
||||||
private $iInsee;
|
|
||||||
|
|
||||||
public $enCache=false;
|
/**
|
||||||
public $force=false;
|
* PDO Connection with Doctrine
|
||||||
public $annee=0;
|
* @var \Doctrine\DBAL\Connection
|
||||||
|
*/
|
||||||
|
protected $conn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Logger
|
||||||
|
* @var \Monolog\Logger
|
||||||
|
*/
|
||||||
|
protected $logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable remote
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
protected $remote = false;
|
protected $remote = false;
|
||||||
|
|
||||||
public function __construct($accesDist = true)
|
/**
|
||||||
|
* MQualibat
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->accesDist = $accesDist;
|
$this->conn = Zend_Registry::get('doctrine');
|
||||||
$this->iDb = new Metier_Util_Db();
|
|
||||||
|
if (Zend_Registry::isRegistered('logger')) {
|
||||||
|
$this->logger = Zend_Registry::get('logger');
|
||||||
|
}
|
||||||
|
|
||||||
$this->iBodacc = new Metier_Bodacc_MBodacc();
|
$this->iBodacc = new Metier_Bodacc_MBodacc();
|
||||||
$this->iInsee = new Metier_Insee_MInsee();
|
$this->iInsee = new Metier_Insee_MInsee();
|
||||||
}
|
}
|
||||||
@ -77,23 +90,40 @@ class Metier_Partenaires_MQualibat
|
|||||||
|
|
||||||
public function getMaxQualibat()
|
public function getMaxQualibat()
|
||||||
{
|
{
|
||||||
$ret = $this->iDb->select('sdv1.qualibat', 'MAX(id) AS id', '1', false, MYSQL_ASSOC);
|
$sql = "SELECT MAX(id) AS id FROM sdv1.qualibat";
|
||||||
return $ret[0]['id'];
|
try {
|
||||||
|
$stmt = $this->conn->executeQuery($sql);
|
||||||
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
||||||
|
if ($this->logger !== null) {
|
||||||
|
$this->logger->error($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||||
|
|
||||||
|
return $result->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTabQualibatManquants()
|
public function getTabQualibatManquants()
|
||||||
{
|
{
|
||||||
$tabRet = $tabQualibatCalc = $tabQualibatBase = array();
|
$tabRet = $tabQualibatCalc = $tabQualibatBase = array();
|
||||||
|
|
||||||
// Liste des Qualibat Calculés
|
// Liste des Qualibat Calculés
|
||||||
$maxQualibat = $this->getMaxQualibat();
|
$maxQualibat = $this->getMaxQualibat();
|
||||||
for ($i=1; $i<=$maxQualibat; $i++) {
|
for ($i=1; $i<=$maxQualibat; $i++) {
|
||||||
$tabQualibatCalc[]=$i;
|
$tabQualibatCalc[] = $i;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Liste des Qualibat en base
|
// Liste des Qualibat en base
|
||||||
$ret = $this->iDb->select('sdv1.qualibat', 'id', '1 ORDER BY id ASC', false, MYSQL_ASSOC);
|
$sql = "SELECT id FROM sdv1.qualibat ORDER BY id ASC";
|
||||||
foreach ($ret as $i=>$res) {
|
try {
|
||||||
$tabQualibatBase[]=$res['id'];
|
$stmt = $this->conn->executeQuery($sql);
|
||||||
|
while ($result = $stmt->fetch(PDO::FETCH_OBJ)) {
|
||||||
|
$tabQualibatBase[] = $result->id;
|
||||||
|
}
|
||||||
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
||||||
|
if ($this->logger !== null) {
|
||||||
|
$this->logger->error($e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return array_diff($tabQualibatCalc, $tabQualibatBase);
|
return array_diff($tabQualibatCalc, $tabQualibatBase);
|
||||||
@ -109,34 +139,56 @@ class Metier_Partenaires_MQualibat
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = $this->iDb->select(
|
$sql = "SELECT siren, actif, id, nom, adresse, cp, ville, tel, fax, email, web, eff, teff,
|
||||||
'sdv1.qualibat', 'siren, actif, id, nom, adresse, cp, ville, tel, fax, email, web,
|
ca, tca, libFJ, nace, dateFondation, dateDeb, dateFin, dateInsert
|
||||||
eff, teff, ca, tca, libFJ, nace, dateFondation, dateDeb, dateFin, dateInsert',
|
FROM sdv1.qualibat WHERE $strWhere";
|
||||||
$strWhere, false, MYSQL_ASSOC);
|
try {
|
||||||
|
$stmt = $this->conn->executeQuery($sql);
|
||||||
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
||||||
|
if ($this->logger !== null) {
|
||||||
|
$this->logger->error($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// In database
|
// In database
|
||||||
if (!$this->force && count($ret) > 0) {
|
if ($this->remote === false && $stmt->rowCount() > 0) {
|
||||||
$this->enCache=true;
|
$tabRet = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||||
$tabRet = $ret[0];//array();
|
|
||||||
|
|
||||||
// Ajout des qualifications
|
// Ajout des qualifications
|
||||||
$ret = $this->iDb->select(
|
$sql = "SELECT code, periodQualif, niveauQualif, mentions, nomQualif, dateAttrib, dateEch
|
||||||
'sdv1.qualibatqualif', 'code, periodQualif, niveauQualif, mentions, nomQualif, dateAttrib, dateEch',
|
FROM sdv1.qualibatqualif WHERE $strWhere";
|
||||||
$strWhere, false, MYSQL_ASSOC);
|
try {
|
||||||
foreach ($ret as $i => $tabTmp) {
|
$stmt = $this->conn->executeQuery($sql);
|
||||||
$tabRet['qualifications'][] = $tabTmp;
|
if ($stmt->rowCount() > 0) {
|
||||||
|
while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||||
|
$tabRet['qualifications'][] = $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
||||||
|
if ($this->logger !== null) {
|
||||||
|
$this->logger->error($e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ajout des dirigeants
|
// Ajout des dirigeants
|
||||||
$ret = $this->iDb->select(
|
$sql = "SELECT civNomPrenom, civilite, nom, prenom, fonction
|
||||||
'sdv1.qualibatdir', 'civNomPrenom, civilite, nom, prenom, fonction',
|
FROM sdv1.qualibatdir WHERE $strWhere";
|
||||||
$strWhere, false, MYSQL_ASSOC);
|
try {
|
||||||
foreach ($ret as $i => $tabTmp) {
|
$stmt = $this->conn->executeQuery($sql);
|
||||||
$tabRet['dirigeants'][] = $tabTmp;
|
if ($stmt->rowCount() > 0) {
|
||||||
|
while ($result = $stmt->fetch(\PDO::FETCH_ASSOC)) {
|
||||||
|
$tabRet['dirigeants'][] = $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
||||||
|
if ($this->logger !== null) {
|
||||||
|
$this->logger->error($e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WebSite
|
// WebSite
|
||||||
elseif ($this->accesDist == true) {
|
if ($this->remote === true) {
|
||||||
$this->enCache = false;
|
|
||||||
$url = 'http://www.qualibat.com/Views/EntreprisesRechercheDetail.aspx?id='.$idQualibat;
|
$url = 'http://www.qualibat.com/Views/EntreprisesRechercheDetail.aspx?id='.$idQualibat;
|
||||||
$page = getUrl($url, '', '', '', false, '', '', 3);
|
$page = getUrl($url, '', '', '', false, '', '', 3);
|
||||||
if ($page['code'] != 200) {
|
if ($page['code'] != 200) {
|
||||||
@ -258,10 +310,10 @@ class Metier_Partenaires_MQualibat
|
|||||||
foreach ($matches[1] as $i => $nom) {
|
foreach ($matches[1] as $i => $nom) {
|
||||||
$strNom = trim($nom);
|
$strNom = trim($nom);
|
||||||
switch (strtoupper(substr($strNom, 0, 6))) {
|
switch (strtoupper(substr($strNom, 0, 6))) {
|
||||||
case 'MONSIE': $civ='M'; $pDeb=8; break;
|
case 'MONSIE': $civ='M'; $pDeb=8; break;
|
||||||
case 'MADAME': $civ='MME'; $pDeb=6; break;
|
case 'MADAME': $civ='MME'; $pDeb=6; break;
|
||||||
case 'MADEMO': $civ='MLLE';$pDeb=12; break;
|
case 'MADEMO': $civ='MLLE'; $pDeb=12; break;
|
||||||
default: $civ=''; $pDeb=0; break;
|
default: $civ=''; $pDeb=0; break;
|
||||||
}
|
}
|
||||||
$libFonction = ucwords(strtolower(trim($matches[2][$i])));
|
$libFonction = ucwords(strtolower(trim($matches[2][$i])));
|
||||||
$tabRet['dirigeants'][$i] = array(
|
$tabRet['dirigeants'][$i] = array(
|
||||||
@ -282,8 +334,19 @@ class Metier_Partenaires_MQualibat
|
|||||||
'dateDeb' => @$tabDateAttrib[0],
|
'dateDeb' => @$tabDateAttrib[0],
|
||||||
'dateFin' => @$tabDateFin[0]));
|
'dateFin' => @$tabDateFin[0]));
|
||||||
unset($tabInsert['qualifications']);
|
unset($tabInsert['qualifications']);
|
||||||
if (!$this->iDb->insert('sdv1.qualibat', $tabInsert)) {
|
|
||||||
$this->iDb->update('sdv1.qualibat', $tabInsert, "id=$idQualibat");
|
$sql = "SELECT id FROM sdv1.qualibat WHERE id=$idQualibat";
|
||||||
|
try {
|
||||||
|
$stmt = $this->conn->executeQuery($sql);
|
||||||
|
if ($stmt->rowCount() > 0) {
|
||||||
|
$this->conn->update('sdv1.qualibat', $tabInsert, array('id' => $idQualibat));
|
||||||
|
} else {
|
||||||
|
$this->conn->insert('sdv1.qualibat', $tabInsert);
|
||||||
|
}
|
||||||
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
||||||
|
if ($this->logger !== null) {
|
||||||
|
$this->logger->error($e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Insertion des qualifications **/
|
/** Insertion des qualifications **/
|
||||||
@ -292,8 +355,24 @@ class Metier_Partenaires_MQualibat
|
|||||||
$tabInsert['id'] = $idQualibat;
|
$tabInsert['id'] = $idQualibat;
|
||||||
$tabInsert['siren'] = $siren;
|
$tabInsert['siren'] = $siren;
|
||||||
$tabInsert['dateInsert'] = date('YmdHis');
|
$tabInsert['dateInsert'] = date('YmdHis');
|
||||||
if (!$this->iDb->insert('sdv1.qualibatqualif', $tabInsert)) {
|
|
||||||
$this->iDb->update('sdv1.qualibatqualif', $tabInsert, "id=$idQualibat AND code='".$tabInsert['code']."' AND periodQualif='".$tabInsert['periodQualif']."'");
|
$sql = "SELECT id FROM sdv1.qualibatqualif
|
||||||
|
WHERE id=$idQualibat AND code='".$tabInsert['code']."' AND periodQualif='".$tabInsert['periodQualif']."'";
|
||||||
|
try {
|
||||||
|
$stmt = $this->conn->executeQuery($sql);
|
||||||
|
if ($stmt->rowCount() > 0) {
|
||||||
|
$this->conn->update('sdv1.qualibatqualif', $tabInsert, array(
|
||||||
|
'id' => $idQualibat,
|
||||||
|
'code' => $tabInsert['code'],
|
||||||
|
'periodQualif' => $tabInsert['periodQualif'],
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
$this->conn->insert('sdv1.qualibatqualif', $tabInsert);
|
||||||
|
}
|
||||||
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
||||||
|
if ($this->logger !== null) {
|
||||||
|
$this->logger->error($e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -304,29 +383,66 @@ class Metier_Partenaires_MQualibat
|
|||||||
$tabInsert['id'] = $idQualibat;
|
$tabInsert['id'] = $idQualibat;
|
||||||
$tabInsert['siren'] = $siren;
|
$tabInsert['siren'] = $siren;
|
||||||
$tabInsert['dateInsert'] = date('YmdHis');
|
$tabInsert['dateInsert'] = date('YmdHis');
|
||||||
if (!$this->iDb->insert('sdv1.qualibatdir', $tabInsert)) {
|
|
||||||
$this->iDb->update('sdv1.qualibatdir', $tabInsert, "id=$idQualibat AND civNomPrenom='".addslashes($tabInsert['civNomPrenom'])."' AND fonction='".addslashes($tabInsert['fonction'])."'");
|
$sql = "SELECT id FROM sdv1.qualibatdir
|
||||||
|
WHERE id=$idQualibat AND civNomPrenom='".addslashes($tabInsert['civNomPrenom'])."' AND fonction='".addslashes($tabInsert['fonction'])."'";
|
||||||
|
try {
|
||||||
|
$stmt = $this->conn->executeQuery($sql);
|
||||||
|
if ($stmt->rowCount() > 0) {
|
||||||
|
$this->conn->update('sdv1.qualibatdir', $tabInsert, array(
|
||||||
|
'id' => $idQualibat,
|
||||||
|
'civNomPrenom' => $tabInsert['civNomPrenom'],
|
||||||
|
'fonction' => $tabInsert['fonction'],
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
$this->conn->insert('sdv1.qualibatdir', $tabInsert);
|
||||||
|
}
|
||||||
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
||||||
|
if ($this->logger !== null) {
|
||||||
|
$this->logger->error($e->getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
unset($tabRet['dirigeants'][$i]['civNomPrenom']);
|
unset($tabRet['dirigeants'][$i]['civNomPrenom']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $tabRet;
|
return $tabRet;
|
||||||
} else {
|
} else {
|
||||||
$tabInsert = array(
|
$tabInsert = array(
|
||||||
'actif' => 0,
|
'actif' => 0,
|
||||||
'id' => $idQualibat,
|
'id' => $idQualibat,
|
||||||
'idQualibatAttribue' => 0,
|
'idQualibatAttribue' => 0,
|
||||||
'dateInsert' => date('YmdHis')
|
'dateInsert' => date('YmdHis')
|
||||||
);
|
);
|
||||||
$this->erreur = 'Numéro Qualibat inexistant';
|
$this->erreur = 'Numéro Qualibat inexistant';
|
||||||
|
|
||||||
// On enregistre ce numéro comme non attribué si < au dernier numéro attribué
|
// On enregistre ce numéro comme non attribué si < au dernier numéro attribué
|
||||||
if ($idQualibat < $this->getMaxQualibat()) {
|
if ($idQualibat < $this->getMaxQualibat()) {
|
||||||
$this->iDb->insert('sdv1.qualibat', $tabInsert);
|
try {
|
||||||
|
$stmt = $this->conn->insert('sdv1.qualibat', $tabInsert);
|
||||||
|
} catch (\Doctrine\DBAL\DBALException $e) {
|
||||||
|
if ($this->logger !== null) {
|
||||||
|
$this->logger->error($e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Get Remote Infos
|
||||||
|
* @param unknown $id
|
||||||
|
*/
|
||||||
|
protected function getRemote($id)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user