Liens : Doctrine
This commit is contained in:
parent
8005a79209
commit
95ca467b50
@ -13,11 +13,6 @@ class Metier_Liens_Base
|
||||
*/
|
||||
protected $siren = null;
|
||||
|
||||
/**
|
||||
* @var Zend_Db_Adapter_Abstract
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* Array to list id find during list of childrens
|
||||
* @var array
|
||||
@ -43,38 +38,45 @@ class Metier_Liens_Base
|
||||
public $stopAtPP = true;
|
||||
|
||||
/**
|
||||
* Databas table name
|
||||
* @var string
|
||||
* PDO Connection with Doctrine
|
||||
* @var \Doctrine\DBAL\Connection
|
||||
*/
|
||||
protected $_schema = 'jo';
|
||||
protected $conn;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $id
|
||||
* @param string $type ref|siren
|
||||
* @param Zend_Db_Adapter $db
|
||||
* @throws SoapFault
|
||||
* Gestion des liens inter entreprises
|
||||
* @param \Doctrine\DBAL\Connection $conn
|
||||
*/
|
||||
public function __construct($id, $type = 'ref', $db = null)
|
||||
{
|
||||
//Get defaut database adapter
|
||||
if( $db === null ) {
|
||||
$this->db = Zend_Db_Table_Abstract::getDefaultAdapter();
|
||||
} else {
|
||||
$this->db = $db;
|
||||
Zend_Db_Table_Abstract::setDefaultAdapter($db);
|
||||
}
|
||||
public function __construct($conn = null)
|
||||
{
|
||||
if ($conn === null) {
|
||||
$this->conn = Zend_Registry::get('doctrine');
|
||||
}
|
||||
else {
|
||||
$this->conn = $conn;
|
||||
}
|
||||
}
|
||||
|
||||
//Get Id
|
||||
/**
|
||||
* Identifiant
|
||||
* @param string $id
|
||||
* @param string $type ref|siren
|
||||
*/
|
||||
public function setId($id, $type = 'ref')
|
||||
{
|
||||
// Get Id
|
||||
if ( $type == 'siren' ) {
|
||||
$this->siren = $id;
|
||||
$refM = new Application_Model_JoLiensRef();
|
||||
$sql = $refM->select()->where('siren=?', $id)->where('dateSuppr=0');
|
||||
$result = $refM->fetchRow($sql);
|
||||
if ( $result !== null ) {
|
||||
$this->idRef = $result->id;
|
||||
}
|
||||
} else {
|
||||
$sql = "SELECT * FROM jo.liensRef WHERE siren = :id AND dateSuppr = 0";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('siren', $id);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||
$this->idRef = $result->id;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$this->idRef = $id;
|
||||
}
|
||||
}
|
||||
@ -98,34 +100,36 @@ class Metier_Liens_Base
|
||||
}
|
||||
|
||||
try {
|
||||
$sql = $this->db->select()
|
||||
->from(array('l'=>$this->_schema.'.liens2'),
|
||||
array('id', 'idAct', 'PDetention', 'Pvote', 'MajMin', 'idPar',
|
||||
'dateEffetLien', 'dateInsert', 'dateUpdate'))
|
||||
->where('idPar=?', $id)
|
||||
->join(array('r'=>$this->_schema.'.liensRef'), 'l.idAct=r.id',
|
||||
array('LPAD(siren, 9, 000000000) AS siren','PpPm', 'RS', 'sigle', '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',
|
||||
'idLoc1Type', 'idLoc1Num', 'idLoc2Type', 'idLoc2Num', 'idLoc3Type', 'idLoc3Num',
|
||||
))
|
||||
->order('PDetention DESC');
|
||||
$qb = $this->conn->createQueryBuilder();
|
||||
$qb->select(array(
|
||||
'l.id', 'l.idAct', 'l.PDetention', 'l.Pvote', 'l.MajMin', 'l.idPar',
|
||||
'l.dateEffetLien', 'l.dateInsert', 'l.dateUpdate',
|
||||
'r.LPAD(siren, 9, 0) AS siren', 'r.PpPm', 'r.RS', 'r.sigle', 'r.civilite', 'r.nom',
|
||||
'r.prenom', 'r.nom_usage', 'r.naissance_date', 'r.naissance_dept_pays',
|
||||
'r.naissance_lieu', 'r.nat', 'r.adresse_num', 'r.adresse_btq', 'r.adresse_codvoie',
|
||||
'r.adresse_libvoie', 'r.adresse_comp', 'r.adresse_cp', 'r.adresse_ville',
|
||||
'r.adresse_pays', 'r.idLoc1Type', 'r.idLoc1Num', 'r.idLoc2Type', 'r.idLoc2Num',
|
||||
'r.idLoc3Type', 'r.idLoc3Num'
|
||||
)
|
||||
)->from('jo.liens2', 'l')->join('l', 'jo.liensRef', 'r', 'l.idAct=r.id')
|
||||
->where('l.idPar = :id')->setParameter('id', $id)
|
||||
->orderBy('PDetention', 'DESC');
|
||||
|
||||
//Actif / Inactif
|
||||
if ( null !== $actif ) {
|
||||
if ( false === $actif ) {
|
||||
$sql->where('l.actif=?',0);
|
||||
} else {
|
||||
$sql->where('l.actif=?',1);
|
||||
// Actif / Inactif
|
||||
if ( null !== $actif ) {
|
||||
if ( false === $actif ) {
|
||||
$qb->andWhere('l.actif = 0');
|
||||
} else {
|
||||
$qb->andWhere('l.actif = 1');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Don't display deleted - anomaly
|
||||
$sql->where('l.dateSuppr=?', '0000-00-00 00:00:00');
|
||||
|
||||
$liens = $this->db->fetchAll($sql, null, Zend_Db::FETCH_OBJ);
|
||||
} catch (Zend_Db_Exception $e) {
|
||||
//Don't display deleted - anomaly
|
||||
$qb->andWhere("l.dateSuppr = '0000-00-00 00:00:00'");
|
||||
$stmt = $qb->execute();
|
||||
$liens = $stmt->fetchAll(\PDO::FETCH_OBJ);
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
throw new Exception(__METHOD__ . ': ' . $e->getMessage());
|
||||
}
|
||||
|
||||
@ -157,34 +161,36 @@ class Metier_Liens_Base
|
||||
}
|
||||
|
||||
try {
|
||||
$sql = $this->db->select()
|
||||
->from(array('l'=>$this->_schema.'.liens2'),
|
||||
array('id', 'idAct', 'PDetention', 'Pvote', 'MajMin', 'idPar',
|
||||
'dateEffetLien', 'dateInsert', 'dateUpdate'))
|
||||
->where('idAct=?', $id)
|
||||
->join(array('r'=>$this->_schema.'.liensRef'), 'l.idPar=r.id',
|
||||
array('LPAD(siren, 9, 000000000) AS siren','PpPm', 'RS', 'sigle', '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',
|
||||
'idLoc1Type', 'idLoc1Num', 'idLoc2Type', 'idLoc2Num', 'idLoc3Type', 'idLoc3Num',
|
||||
))
|
||||
->order('PDetention DESC');
|
||||
$qb = $this->conn->createQueryBuilder();
|
||||
$qb->select(array(
|
||||
'l.id', 'l.idAct', 'l.PDetention', 'l.Pvote', 'l.MajMin', 'l.idPar',
|
||||
'l.dateEffetLien', 'l.dateInsert', 'l.dateUpdate',
|
||||
'r.LPAD(siren, 9, 0) AS siren', 'r.PpPm', 'r.RS', 'r.sigle', 'r.civilite', 'r.nom',
|
||||
'r.prenom', 'r.nom_usage', 'r.naissance_date', 'r.naissance_dept_pays',
|
||||
'r.naissance_lieu', 'r.nat', 'r.adresse_num', 'r.adresse_btq', 'r.adresse_codvoie',
|
||||
'r.adresse_libvoie', 'r.adresse_comp', 'r.adresse_cp', 'r.adresse_ville',
|
||||
'r.adresse_pays', 'r.idLoc1Type', 'r.idLoc1Num', 'r.idLoc2Type', 'r.idLoc2Num',
|
||||
'r.idLoc3Type', 'r.idLoc3Num'
|
||||
)
|
||||
)->from('jo.liens2', 'l')->join('l', 'jo.liensRef', 'r', 'l.idPar=r.id')
|
||||
->where('l.idAct = :id')->setParameter('id', $id)
|
||||
->orderBy('PDetention', 'DESC');
|
||||
|
||||
//Actif / Inactif
|
||||
// Actif / Inactif
|
||||
if ( null !== $actif ) {
|
||||
if ( false === $actif ) {
|
||||
$sql->where('l.actif=?',0);
|
||||
$qb->andWhere('l.actif = 0');
|
||||
} else {
|
||||
$sql->where('l.actif=?',1);
|
||||
$qb->andWhere('l.actif = 1');
|
||||
}
|
||||
}
|
||||
|
||||
//Don't display deleted - anomaly
|
||||
$sql->where('l.dateSuppr=?', '0000-00-00 00:00:00');
|
||||
|
||||
$liens = $this->db->fetchAll($sql, null, Zend_Db::FETCH_OBJ);
|
||||
} catch (Zend_Db_Exception $e) {
|
||||
$qb->andWhere("l.dateSuppr = '0000-00-00 00:00:00'");
|
||||
$stmt = $qb->execute();
|
||||
$liens = $stmt->fetchAll(\PDO::FETCH_OBJ);
|
||||
}
|
||||
catch (\Doctrine\DBAL\DBALException $e) {
|
||||
throw new Exception(__METHOD__ . ': ' . $e->getMessage());
|
||||
}
|
||||
|
||||
@ -198,38 +204,41 @@ class Metier_Liens_Base
|
||||
*/
|
||||
public function getDirections($actif = null)
|
||||
{
|
||||
if ( null === $this->siren ) {
|
||||
$refM = new Application_Model_JoLiensRef();
|
||||
$rows = $refM->find($this->idRef);
|
||||
$siren = str_pad($rows->current()->siren, 9, '0', STR_PAD_LEFT);
|
||||
} else {
|
||||
if (null === $this->siren) {
|
||||
$sql = "SELECT LPAD(siren, 9, 0) AS siren FROM jo.liensRef WHERE id = :id";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('id', $this->idRef);
|
||||
$result = $stmt->fetch(\PDO::FETCH_OBJ);
|
||||
$siren = $result->siren;
|
||||
}
|
||||
else {
|
||||
$siren = $this->siren;
|
||||
}
|
||||
|
||||
$result = array();
|
||||
|
||||
if ( null !== $siren && intval($siren) != 0 )
|
||||
{
|
||||
if (null !== $siren && intval($siren) != 0) {
|
||||
try {
|
||||
$directionsM = new Application_Model_JoRncsDirigeants();
|
||||
$sql = $directionsM->select()->from($directionsM, array(
|
||||
'LPAD(siren, 9, 000000000) AS 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 ) {
|
||||
$qb = $this->conn->createQueryBuilder();
|
||||
$qb->select(array('LPAD(siren, 9, 0) AS siren', 'raisonSociale',
|
||||
'dirSiren', 'dirRS', 'civilite', 'nom', 'prenom', 'naissance_date',
|
||||
'naissance_lieu', 'fonction_code', 'fonction_lib')
|
||||
)->from('jo.rncs_dirigeants')->where("typeDir IN ('PM', 'PP')")
|
||||
->andWhere('dirSiren = :siren')->setParameter('siren', $siren);
|
||||
// Actif / Inactif
|
||||
if (null !== $actif) {
|
||||
if ( false === $actif ) {
|
||||
$sql->where('actif=?',0);
|
||||
} else {
|
||||
$sql->where('actif=?',1);
|
||||
$qb->andWhere('actif = 0');
|
||||
}
|
||||
else {
|
||||
$qb->andWhere('actif = 1');
|
||||
}
|
||||
}
|
||||
$sql->order('fonction_code DESC');
|
||||
$sql->order('raisonSociale ASC');
|
||||
|
||||
$result = $directionsM->fetchAll($sql);
|
||||
} catch (Zend_Db_Exception $e) {
|
||||
$qb->orderBy('fonction_code', 'DESC');
|
||||
$qb->orderBy('raisonSociale', 'ASC');
|
||||
$stmt = $qb->execute();
|
||||
$stmt->fetchAll(\PDO::FETCH_OBJ);
|
||||
} catch (\Doctrine\DBAL\DBALException $e) {
|
||||
throw new Exception(__METHOD__ . ': ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
@ -237,7 +246,6 @@ class Metier_Liens_Base
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retourne la maison mère
|
||||
* @param int $id
|
||||
@ -304,10 +312,12 @@ class Metier_Liens_Base
|
||||
$id = $this->idRef;
|
||||
}
|
||||
|
||||
$refM = new Application_Model_JoLiensRef();
|
||||
$row = $refM->find($id);
|
||||
if (null !== $row) {
|
||||
return $row->current();
|
||||
$sql = "SELECT * FROM jo.liensRef WHERE id = :id";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->bindValue('id', $id);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() > 0) {
|
||||
return $stmt->fetch(\PDO::FETCH_OBJ);
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -319,7 +329,7 @@ class Metier_Liens_Base
|
||||
* @param int $nbNiveaux
|
||||
* @return array
|
||||
*/
|
||||
public function getTree( $pctMin=33, $nbNiveaux=10 )
|
||||
public function getTree($pctMin = 33, $nbNiveaux = 10)
|
||||
{
|
||||
//Get identity to stop at isin
|
||||
$itemWithIsin = null;
|
||||
@ -423,14 +433,19 @@ class Metier_Liens_Base
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return multitype:NULL
|
||||
* Liste des entités du CAC40
|
||||
* @return array
|
||||
*/
|
||||
public function getCAC40()
|
||||
{
|
||||
$sql = "SELECT isin, nom, MAX(`date`) AS dateMAJ FROM sdv1.bourse_listes WHERE lstCode='xcac40p' GROUP BY lstCode, isin HAVING MAX(`date`) ORDER BY dateMAJ DESC;";
|
||||
$sql = "SELECT isin, nom, MAX(date) AS dateMAJ FROM sdv1.bourse_listes
|
||||
WHERE lstCode='xcac40p' GROUP BY lstCode, isin HAVING MAX(date) ORDER BY dateMAJ DESC;";
|
||||
$result = $this->db->query($sql);
|
||||
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
$result = $stmt->fetchAll(\PDO::FETCH_OBJ);
|
||||
|
||||
$output = array();
|
||||
foreach ( $result as $item ) {
|
||||
$output[] = $item->isin;
|
||||
@ -444,23 +459,23 @@ class Metier_Liens_Base
|
||||
* @param number $pctMin
|
||||
* @return array
|
||||
*/
|
||||
public function getGroupeCAC40( $pctMin=50 )
|
||||
public function getGroupeCAC40($pctMin = 50)
|
||||
{
|
||||
$listeIsin = $this->getCAC40();
|
||||
$isin = implode(",",$listeIsin);
|
||||
|
||||
$refM = new Application_Model_JoLiensRef();
|
||||
$sql = $refM->select()
|
||||
->where("idLoc1Type=63")->where("idLoc1Num IN (?)", $isin)
|
||||
->orWhere("idLoc2Type=63")->where("idLoc2Num IN (?)", $isin)
|
||||
->orWhere("idLoc3Type=63")->where("idLoc3Num IN (?)", $isin);
|
||||
|
||||
$result = $refM->fetchAll($sql);
|
||||
|
||||
$this->findId = array();
|
||||
|
||||
$qb = $this->conn->createQueryBuilder();
|
||||
$qb->select('*')->where('idLoc1Type=63')->andWhere('idLoc1Num IN (:isin)')
|
||||
->orWhere("idLoc2Type=63")->andwhere("idLoc2Num IN (:isin)")
|
||||
->orWhere("idLoc3Type=63")->andwhere("idLoc3Num IN (:isin)")
|
||||
->setParameter('isin', $isin);
|
||||
$stmt = $qb->execute();
|
||||
|
||||
$output = array();
|
||||
if ( $result->count()>0 ) {
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$result = $stmt->fetchAll(\PDO::FETCH_OBJ);
|
||||
foreach ( $result as $item ) {
|
||||
$output = $output + $this->getListeGroupeCAC40($item->id, $pctMin);
|
||||
}
|
||||
@ -504,7 +519,7 @@ class Metier_Liens_Base
|
||||
* @param number $pctMin
|
||||
* @return boolean
|
||||
*/
|
||||
public function isInGroupeCAC40( $pctMin=50 )
|
||||
public function isInGroupeCAC40($pctMin = 50)
|
||||
{
|
||||
//Si pas d'actionnaires => false
|
||||
if ( count($this->getActionnaires()) == 0 ) {
|
||||
@ -524,18 +539,16 @@ class Metier_Liens_Base
|
||||
*/
|
||||
protected function getCountry()
|
||||
{
|
||||
$countryM = new Application_Model_JoTabPays();
|
||||
$sql = $countryM->select()
|
||||
->from($countryM, array('codPays3', 'libPays'))
|
||||
->where('codPays3 IS NOT NULL');
|
||||
$rows = $countryM->fetchAll($sql);
|
||||
if ( $rows !== null ) {
|
||||
$data = array();
|
||||
foreach($rows as $item) {
|
||||
$data[$item->codPays3] = $item->libPays;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
$sql = "SELECT codPays3, libPays FROM jo.tabPays WHERE codPays3 IS NOT NULL";
|
||||
$stmt = $this->conn->prepare($sql);
|
||||
$stmt->execute();
|
||||
if ($stmt->rowCount() > 0) {
|
||||
$data = array();
|
||||
foreach($rows as $item) {
|
||||
$data[$item->codPays3] = $item->libPays;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user