Merge branch 'doctrine-artisanat' into develop

This commit is contained in:
Michael RICOIS 2017-01-12 09:50:13 +01:00
commit 1c3ec01d3e

View File

@ -9,13 +9,22 @@ class Metier_Partenaires_MArtisanat
public $referer='';
public $libErreur='';
public $cookie='';
public $iDb;
/**
* PDO Connection with Doctrine
* @var \Doctrine\DBAL\Connection
*/
protected $conn;
/**
* Flag to get remote data
* @var string
*/
protected $remote = false;
public function __construct()
{
$this->iDb = new Metier_Util_Db();
$this->conn = Zend_Registry::get('doctrine');
}
/**
@ -26,22 +35,43 @@ class Metier_Partenaires_MArtisanat
$this->remote = true;
}
/**
* Informations artisan
* @param string $siren
* @return array
*/
public function getIdentite($siren)
{
$data = array();
$siren = $siren * 1;
$res = $this->iDb->select('jo.artisanat', 'id, siren, actif, numRM, denomination, sigle, nomCommercial, enseigne, fj, effectif, aprm, debutActivite, activite, adresse, cp, ville, cessation, radiation, nbInscriptions, nom, prenom, nomUsage, dateNaiss, lieuNaiss, natio, qualite, qualif, dateQualif, dateFctDeb, dateFctFin, IF(dateInsert>dateUpdate,dateInsert,dateUpdate) AS dateUpdate', "siren=$siren", false, MYSQL_ASSOC);
if ($this->remote) {
$data = $this->getRemoteIdentite();
} else {
if (count($res) > 0) {
$data = $res[0];
try {
$stmt = $this->conn->prepare("SELECT id, siren, actif, numRM, denomination, sigle, nomCommercial,
enseigne, fj, effectif, aprm, debutActivite, activite, adresse, cp, ville, cessation,
radiation, nbInscriptions, nom, prenom, nomUsage, dateNaiss, lieuNaiss, natio,
qualite, qualif, dateQualif, dateFctDeb, dateFctFin,
IF(dateInsert>dateUpdate,dateInsert,dateUpdate) AS dateUpdate FROM jo.artisanat
WHERE siren=:siren");
$stmt->bindValue('siren', $siren);
$stmt->execute();
if ($stmt->rowCount() > 0) {
$data = $stmt->fetch(\PDO::FETCH_ASSOC);
}
} catch (\Doctrine\DBAL\DBALException $e) {
}
}
return $data;
}
/**
* Download data from external website
* @return array
*/
public function getRemoteIdentite()
{
$url = 'http://www.cma-paris.fr/CMP/rm_recherche.php?dom=Gerer&fonction=recherche';
@ -295,12 +325,15 @@ class Metier_Partenaires_MArtisanat
}
// Insertion en base de données
$tabInsert['dateInsert'] = date('Y-m-d H:i:s');
$id = $this->iDb->insert('jo.artisanat', $tabInsert, true);
$tabInsert['id'] = $id;
foreach ($tabEtabs as $tabInsert2) {
$tabInsert2['dateInsert'] = $tabInsert['dateInsert'];
$id2 = $this->iDb->insert('jo.artisanat_etab', $tabInsert2, true);
try {
$tabInsert = array('dateInsert' => date('Y-m-d H:i:s'));
$this->conn->insert('jo.artisanat', $tabInsert);
$tabInsert['id'] = $this->conn->lastInsertId();
foreach ($tabEtabs as $etab) {
$etab['dateInsert'] = $tabInsert['dateInsert'];
$this->conn->insert('jo.artisanat_etab', $etab);
}
} catch (\Doctrine\DBAL\DBALException $e) {
}
$tabInsert['dateUpdate'] = substr($tabInsert['dateInsert'], 0, 10);