362 lines
9.8 KiB
PHP
362 lines
9.8 KiB
PHP
<?php
|
|
class MLiens2
|
|
{
|
|
/**
|
|
* Company Reference id
|
|
* @var int
|
|
*/
|
|
protected $idRef = null;
|
|
|
|
/**
|
|
* Company SIREN
|
|
* @var string
|
|
*/
|
|
protected $siren = null;
|
|
|
|
/**
|
|
* @var Zend_Db
|
|
*/
|
|
protected $db;
|
|
|
|
/**
|
|
* Array to list id find during list of childrens
|
|
* @var array
|
|
*/
|
|
protected $findId = array();
|
|
|
|
/**
|
|
*
|
|
* @param string $id
|
|
* @param string $type ref|siren
|
|
* @throws SoapFault
|
|
*/
|
|
public function __construct($id, $type = 'ref')
|
|
{
|
|
//Load configuration
|
|
if (Zend_Registry::isRegistered('config')) {
|
|
$c = Zend_Registry::get('config');
|
|
} else {
|
|
$c = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini');
|
|
}
|
|
|
|
//Connect to the database
|
|
try {
|
|
$this->db = Zend_Db::factory($c->profil->db->jo);
|
|
$this->db->getConnection();
|
|
} catch (Zend_Db_Adapter_Exception $e) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
} catch (Zend_Exception $e) {
|
|
throw new SoapFault('ERR', "Application error");
|
|
}
|
|
|
|
if ( $type == 'siren' ) {
|
|
$this->siren = $id;
|
|
$refM = new Application_Model_JoLiensRef($this->db);
|
|
$sql = $refM->select()->where('siren=?', $id);
|
|
$result = $refM->fetchRow($sql);
|
|
if ( $result !== null ) {
|
|
$this->idRef = $result->id;
|
|
}
|
|
} else {
|
|
$this->idRef = $id;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Retourne les actionnaires
|
|
* @param int $id
|
|
* @param boolean $actif
|
|
* @return array Tableau d'actionnaires
|
|
*/
|
|
public function getActionnaires($id = null, $actif = null)
|
|
{
|
|
|
|
if ( null === $id ) {
|
|
$id = $this->idRef;
|
|
}
|
|
|
|
$liens = array();
|
|
|
|
if ( null === $id ) {
|
|
return $liens;
|
|
}
|
|
|
|
try {
|
|
$sql = $this->db->select()
|
|
->from(array('l'=>'liens2'),
|
|
array('id', 'idAct', 'PDetention', 'Pvote', 'MajMin', 'idPar',
|
|
'dateEffetLien', 'dateInsert'))
|
|
->where('idPar=?', $id)
|
|
->join(array('r'=>'liensRef'), 'l.idAct=r.id',
|
|
array('LPAD(siren, 9, 000000000) AS siren','PpPm', 'RS', 'civilite', 'nom', 'prenom', 'nom_usage',
|
|
'naissance_date', 'naissance_dept_pays', 'naissance_lieu', 'nat',
|
|
'adresse_num', 'adresse_btq', 'adresse_codvoie', 'adresse_libvoie',
|
|
'adresse_comp', 'adresse_cp', 'adresse_ville', 'adresse_pays'
|
|
))
|
|
->order('PDetention DESC');
|
|
|
|
//Actif / Inactif
|
|
if ( null !== $actif ) {
|
|
if ( false === $actif ) {
|
|
$sql->where('l.actif=?',0);
|
|
} else {
|
|
$sql->where('l.actif=?',1);
|
|
}
|
|
}
|
|
|
|
$liens = $this->db->fetchAll($sql, null, Zend_Db::FETCH_OBJ);
|
|
} catch (Zend_Exception $e) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
|
|
return $liens;
|
|
}
|
|
|
|
/**
|
|
* Retourne les participations
|
|
* @param int $id
|
|
* @param boolean $actif
|
|
* @return array Tableau des participations
|
|
*/
|
|
public function getParticipations($id = null, $actif = null)
|
|
{
|
|
if ( null === $id ) {
|
|
$id = $this->idRef;
|
|
}
|
|
|
|
if ( false === $actif ) {
|
|
$actif = 0;
|
|
} else {
|
|
$actif = 1;
|
|
}
|
|
|
|
$liens = array();
|
|
|
|
if ( null === $id ) {
|
|
return $liens;
|
|
}
|
|
|
|
try {
|
|
$sql = $this->db->select()
|
|
->from(array('l'=>'liens2'),
|
|
array('id', 'idAct', 'PDetention', 'Pvote', 'MajMin', 'idPar',
|
|
'dateEffetLien', 'dateInsert'))
|
|
->where('idAct=?', $id)
|
|
->join(array('r'=>'liensRef'), 'l.idPar=r.id',
|
|
array('LPAD(siren, 9, 000000000) AS siren','PpPm', 'RS', 'civilite', 'nom', 'prenom', 'nom_usage',
|
|
'naissance_date', 'naissance_dept_pays', 'naissance_lieu', 'nat',
|
|
'adresse_num', 'adresse_btq', 'adresse_codvoie', 'adresse_libvoie',
|
|
'adresse_comp', 'adresse_cp', 'adresse_ville', 'adresse_pays'
|
|
))
|
|
->order('PDetention DESC');
|
|
|
|
//Actif / Inactif
|
|
if ( null !== $actif ) {
|
|
if ( false === $actif ) {
|
|
$sql->where('l.actif=?',0);
|
|
} else {
|
|
$sql->where('l.actif=?',1);
|
|
}
|
|
}
|
|
|
|
$liens = $this->db->fetchAll($sql, null, Zend_Db::FETCH_OBJ);
|
|
} catch (Zend_Exception $e) {
|
|
throw new SoapFault('ERR', $e->getMessage());
|
|
}
|
|
|
|
return $liens;
|
|
}
|
|
|
|
/**
|
|
* Fonctions de direction
|
|
* @param boolean $actif
|
|
* @return Zend_Db_Table_Rowset_Abstract
|
|
*/
|
|
public function getDirections($actif = null)
|
|
{
|
|
if ( null === $this->siren ) {
|
|
$refM = new Application_Model_JoLiensRef($this->db);
|
|
$rows = $refM->find($this->idRef);
|
|
$siren = str_pad($rows->current()->siren, 9, '0', STR_PAD_LEFT);
|
|
} else {
|
|
$siren = $this->siren;
|
|
}
|
|
|
|
$result = array();
|
|
|
|
if ( null !== $siren && intval($siren) != 0 )
|
|
{
|
|
$directionsM = new Application_Model_JoRncsDirigeants($this->db);
|
|
$sql = $directionsM->select()->from($directionsM, array(
|
|
'siren','raisonSociale', 'dirSiren', 'dirRS', 'civilite', 'nom',
|
|
'prenom', 'naissance_date', 'naissance_lieu', 'fonction_code', 'fonction_lib'
|
|
))->where("typeDir IN ('PM', 'PP')")->where('dirSiren=?', $siren);
|
|
|
|
//Actif / Inactif
|
|
if ( null !== $actif ) {
|
|
if ( false === $actif ) {
|
|
$sql->where('actif=?',0);
|
|
} else {
|
|
$sql->where('actif=?',1);
|
|
}
|
|
}
|
|
$sql->order('fonction_code DESC');
|
|
$sql->order('raisonSociale ASC');
|
|
|
|
$result = $directionsM->fetchAll($sql);
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
|
|
/**
|
|
* Retourne la maison mère
|
|
* @param int $id
|
|
* @return int
|
|
*/
|
|
public function getHead($id = null)
|
|
{
|
|
if ( null === $id ) {
|
|
$id = $this->idRef;
|
|
}
|
|
|
|
//Add ID to the list of known
|
|
$this->findId[] = $id;
|
|
|
|
//Through the list
|
|
$liens = $this->getActionnaires($id, true);
|
|
|
|
//Find the following up entity
|
|
if ( count($liens)>0 ) {
|
|
foreach ( $liens as $item ) {
|
|
//Don't through again and again
|
|
if ( in_array($item->idAct, $this->findId) ) {
|
|
continue;
|
|
}
|
|
|
|
// Remove Special
|
|
if ( $item->idAct <= 1000 ) {
|
|
return $id;
|
|
}
|
|
//Same id
|
|
elseif ( $item->idAct == $id ) {
|
|
return $id;
|
|
}
|
|
//PDetention>50
|
|
elseif ( $item->PDetention > 50 ) {
|
|
return $this->getHead($item->idAct);
|
|
}
|
|
//MajMin=+
|
|
elseif ( $item->MajMin == '+' ) {
|
|
return $this->getHead($item->idAct);
|
|
}
|
|
//--
|
|
elseif ( $item->idAct > 1000 ) {
|
|
return $item->idAct;
|
|
}
|
|
}
|
|
}
|
|
|
|
return $id;
|
|
}
|
|
|
|
/**
|
|
* Retourne les éléments identitaire présent dans lienRef
|
|
* @param string $id
|
|
* @return Zend_Db_Table_Rowset_Abstract
|
|
*/
|
|
public function getIdentity($id = null)
|
|
{
|
|
if ( null === $id ) {
|
|
$id = $this->idRef;
|
|
}
|
|
|
|
$refM = new Application_Model_JoLiensRef($this->db);
|
|
$row = $refM->find($id);
|
|
if (null !== row) {
|
|
return $row->current();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Retourne l'arborescence pour les groupes
|
|
* @param int $pctMin
|
|
* @param int $nbNiveaux
|
|
* @return array
|
|
*/
|
|
public function getTree( $pctMin=33, $nbNiveaux=10 )
|
|
{
|
|
//Récupération de la maison mère
|
|
$id = $this->getHead();
|
|
|
|
//Informations de la maison mère
|
|
$identity = $this->getIdentity($id);
|
|
|
|
$this->findId = array();
|
|
$this->findId[] = $identity->id;
|
|
|
|
$nom = $identity->RS;
|
|
if ( $identity->nom != '') {
|
|
$nom = $identity->civilite.' '.$identity->nom.' '.$identity->prenom;
|
|
}
|
|
|
|
//Retour
|
|
$tabRet = array (
|
|
'id' => $identity->id,
|
|
'name' => $nom,
|
|
'siren' => str_pad($identity->siren, 9, '0', STR_PAD_LEFT),
|
|
'pmin' => $item->PDetention,
|
|
'pays' => $identity->adresse_pays,
|
|
'children' => $this->getTreeRecursive($identity->id, $pctMin, 1, $nbNiveaux),
|
|
);
|
|
|
|
return $tabRet;
|
|
}
|
|
|
|
/**
|
|
* Retourne un sous élement de l'arborescence pour les groupes
|
|
* @param int $id
|
|
* @param int $pctMin
|
|
* @param int $niveau
|
|
* @param int $nbNiveaux
|
|
* @return array
|
|
*/
|
|
public function getTreeRecursive( $id, $pctMin=33, $niveau=0, $nbNiveaux=10 )
|
|
{
|
|
if ( $niveau > $nbNiveaux ) return array();
|
|
$niveau++;
|
|
|
|
$tabRet = array();
|
|
$participations = $this->getParticipations($id, true);
|
|
if ( count($participations)>0 ) {
|
|
foreach ( $participations as $item ) {
|
|
if ( $item->PDetention > $pctMin ) {
|
|
$identity = $this->getIdentity($item->idPar);
|
|
|
|
$nom = $identity->RS;
|
|
if ( $identity->nom != '') {
|
|
$nom = $identity->civilite.' '.$identity->nom.' '.$identity->prenom;
|
|
}
|
|
|
|
$data = array (
|
|
'id' => $identity->id,
|
|
'name' => $nom,
|
|
'siren' => str_pad($identity->siren, 9, '0', STR_PAD_LEFT),
|
|
'pmin' => $item->PDetention,
|
|
'pays' => $identity->adresse_pays,
|
|
'children' => array(),
|
|
);
|
|
//Pour éviter d'avoir des boucles infinis
|
|
if ( !in_array($identity->id, $this->findId) ){
|
|
$this->findId[] = $identity->id;
|
|
$data['children'] = $this->getTreeRecursive($identity->id, $pctMin, $niveau, $nbNiveaux);
|
|
}
|
|
$tabRet[] = $data;
|
|
}
|
|
}
|
|
}
|
|
return $tabRet;
|
|
}
|
|
|
|
} |