extranet/library/Scores/Session/Entreprise.php
2015-07-01 09:52:03 +00:00

186 lines
4.1 KiB
PHP

<?php
class Scores_Session_Entreprise
{
protected $index = 'entrep';
/**
* @param string $siret
* @param int $id
* @param boolean $set
*/
public function __construct($siret, $id = 0, $set = false)
{
if ( !empty($siret) && !$set ) {
if (!$this->checkSession($siret, $id) ){
$this->getInfoEntrep($siret, $id);
}
}
}
public function getId()
{
return $this->get('id');
}
public function getSiren()
{
return $this->get('siren');
}
public function getSiret()
{
return $this->get('siret');
}
public function getAutreId()
{
return $this->get('AutreId');
}
public function getSiretSiege()
{
return $this->get('siretSiege');
}
public function getRaisonSociale()
{
return $this->get('raisonSociale');
}
public function setInfoEntrep($identite)
{
$this->setSession($identite);
}
public function getFormeJuridique()
{
return $this->get('fj');
}
public function getNaf()
{
return $this->get('nafEn');
}
public function getCodeCommune()
{
return $this->get('codeCommune');
}
public function getTva()
{
return $this->get('tva');
}
public function getIsin()
{
return $this->get('isin');
}
public function getSource()
{
return $this->get('Source');
}
public function getSourceId()
{
return $this->get('SourceId');
}
public function getAdresse()
{
$adresse = $this->get('Adresse');
if ( $this->get('Adresse2') != '' ) {
$adresse.= ' '.$this->get('Adresse2');
}
if ( $this->get('CP') != '' ) {
$adresse.= ' '.$this->get('CP');
}
$adresse.= ' '.$this->get('Ville');
if ( $this->get('Pays') != '' && strtoupper(substr($this->get('Pays'),0,3)) != 'FRA') {
$adresse.= ', '.$this->get('Pays');
}
return $adresse;
}
protected function get($key)
{
$session = new Zend_Session_Namespace($this->index);
return $session->$key;
}
protected function getInfoEntrep($siret, $id = 0)
{
Zend_Registry::get('firebug')->info('getInfoEntrep');
require_once 'Scores/WsScores.php';
$ws = new WsScores();
$etab = $ws->getIdentiteLight($siret, $id);
$this->setSession($etab);
}
protected function setSession($etab)
{
$session = new Zend_Session_Namespace($this->index);
$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->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;
$session->Adresse = $etab->Adresse;
$session->Adresse2 = $etab->Adresse2;
$session->AdresseNum = $etab->AdresseNum;
$session->AdresseBtq = $etab->AdresseBtq;
$session->AdresseVoie = $etab->AdresseVoie;
$session->AdresseRue = $etab->AdresseRue;
$session->CP = $etab->CP;
$session->Ville = $etab->Ville;
}
protected function checkSession($siret, $id = 0)
{
$compare = false;
if (!Zend_Session::namespaceIsset($this->index)) {
return false;
}
$session = new Zend_Session_Namespace($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;
}
}