extranet/library/Scores/SessionEntreprise.php

152 lines
3.1 KiB
PHP
Raw Normal View History

<?php
class SessionEntreprise
{
protected $index = 'entrep';
2012-04-13 15:43:42 +00:00
/**
* @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');
}
2011-08-29 14:22:39 +00:00
public function getSiretSiege()
{
return $this->get('siretSiege');
}
public function getRaisonSociale()
{
return $this->get('raisonSociale');
}
public function setInfoEntrep($identite)
{
$this->setSession($identite);
}
2011-04-22 14:29:58 +00:00
public function getFormeJuridique()
{
return $this->get('fj');
2011-04-22 14:29:58 +00:00
}
public function getNaf()
{
return $this->get('nafEn');
}
2011-05-02 06:52:12 +00:00
public function getCodeCommune()
{
return $this->get('codeCommune');
}
2011-06-03 08:53:22 +00:00
public function getTva()
{
2011-06-15 13:26:11 +00:00
return $this->get('tva');
}
public function getSource()
{
return $this->get('Source');
}
public function getSourceId()
{
return $this->get('SourceId');
2011-06-03 08:53:22 +00:00
}
protected function get($key)
{
$session = new Zend_Session_Namespace($this->index);
return $session->$key;
2011-05-02 06:52:12 +00:00
}
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->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;
}
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;
}
}