extranet/library/Scores/SessionEntreprise.php
Michael RICOIS b788db51ae Liens
2011-04-22 14:29:58 +00:00

115 lines
2.7 KiB
PHP

<?php
class SessionEntreprise
{
protected $index = 'entrep';
public function __construct($siret, $id = 0, $set = false)
{
if ( !$set && !$this->checkSession($siret, $id) ){
$this->getInfoEntrep($siret, $id);
}
}
public function getId()
{
$session = Zend_Registry::get($this->index);
return $session->id;
}
public function getSiren()
{
$session = Zend_Registry::get($this->index);
return $session->siren;
}
public function getSiret()
{
$session = Zend_Registry::get($this->index);
return $session->siret;
}
public function getRaisonSociale()
{
$session = Zend_Registry::get($this->index);
return $session->raisonSociale;
}
public function setInfoEntrep($identite)
{
$session = $this->setSession($identite);
Zend_Registry::set($this->index, $session);
}
public function getFormeJuridique()
{
$session = Zend_Registry::get($this->index);
return $session->fj;
}
protected function getInfoEntrep($siret, $id = 0)
{
require_once 'Scores/WsScores.php';
$ws = new WsScores();
$etab = $ws->getIdentite($siret, $id);
$session = $this->setSession($etab);
Zend_Registry::set($this->index, $session);
}
protected function setSession($etab)
{
$session = new stdClass();
$session->raisonSociale = $etab->Nom;
$session->id = $etab->id;
$session->siren = $etab->Siren;
$session->siret = $etab->Siret;
$session->siretSiege = $etab->SiretSiege;
$session->tva = $etab->TvaNumero;
$session->isin = $etab->Isin;
$session->AutreId = $etab->AutreId;
$session->active = $etab->Statut;
$session->Source = $etab->Source;
$session->SourceId = $etab->SourceId;
$session->codeCommune = $etab->Dept.$etab->codeCommune;
$session->nafEn = $etab->NafEnt;
$session->nafEnt = $etab->NafEtab;
$session->fj = $etab->FJ;
return $session;
}
protected function checkSession($siret, $id = 0)
{
$compare = false;
if (!Zend_Registry::isRegistered($this->index)) {
return false;
}
$session = Zend_Registry::get($this->index);
$compare = false;
// Comparaison Siren / Siret
if ( !empty($siret) && intval($siret) != 0) {
if (strlen($siret) == 9) {
// Comparaison entre siren
if ($siret == $session->siren) {
$compare = true;
}
} else if (strlen($siret) == 14) {
// Comparaison entre siret
if ($siret == $session->siret) {
$compare = true;
}
}
}
// Comparaison id
if ( empty($siret) && intval($siret) == 0) {
if ($id != 0 && $id == $session->id) {
$compare = true;
}
}
return $compare;
}
}