2013-11-05 11:18:30 +00:00
< ? php
2016-01-27 21:10:45 +00:00
class Metier_Partenaires_MBourse
2013-11-05 11:18:30 +00:00
{
2015-01-20 16:32:59 +00:00
protected $siren = false ;
protected $iDb ;
2015-06-05 15:29:18 +00:00
2015-01-20 16:32:59 +00:00
public function __construct ( $siren = 0 , $db = null )
{
$this -> siren = $siren ;
2015-06-05 15:29:18 +00:00
2015-01-20 16:32:59 +00:00
if ( $db === null ) {
2016-07-18 15:21:48 +02:00
$this -> iDb = new Metier_Util_Db ();
2015-01-20 16:32:59 +00:00
} else {
$this -> iDb = $db ;
}
2013-11-05 11:18:30 +00:00
}
2015-01-20 16:32:59 +00:00
public function getLibSource ( $source )
{
2013-11-05 11:18:30 +00:00
switch ( $source ) {
case 'B' : return 'Business Wire' ; break ;
case 'H' : return 'Hugin' ; break ;
case 'A' : return 'ActusNews' ; break ;
case 'D' : return 'DiRelease' ; break ;
case 'E' : return 'Les Echos' ; break ;
default : return 'N/C' ; break ;
}
}
/** Vérifie la validité de la structure d ' un code ISIN
**
** @ param string $isin
** @ return bool
**/
2015-01-20 16:32:59 +00:00
function isIsin ( $isin )
{
2013-11-05 11:18:30 +00:00
if ( strlen ( trim ( $isin ))) {
$cle = substr ( $isin , - 1 );
$isinLeft = substr ( $isin , 0 , strlen ( $isin ) - 1 );
$letter2number = array ( 'A' => 10 , 'B' => 11 , 'C' => 12 , 'D' => 13 , 'E' => 14 , 'F' => 15 , 'G' => 16 , 'H' => 17 , 'I' => 18 , 'J' => 19 , 'K' => 20 , 'L' => 21 , 'M' => 22 , 'N' => 23 , 'O' => 24 , 'P' => 25 , 'Q' => 26 , 'R' => 27 , 'S' => 28 , 'T' => 29 , 'U' => 30 , 'V' => 31 , 'W' => 32 , 'X' => 33 , 'Y' => 34 , 'Z' => 35 );
$isinConvertion = strtr ( $isinLeft , $letter2number );
$sum = '' ;
$sumFinal = 0 ;
for ( $i = 0 ; $i < strlen ( $isinConvertion ); ++ $i ) $sum .= (( $i % 2 ) ? 1 : 2 ) * $isinConvertion [ $i ];
for ( $i = 0 ; $i < strlen ( $sum ); ++ $i ) $sumFinal += $sum [ $i ];
if ( $sumFinal % 10 ){
$cleVerif = (( int )( $sumFinal / 10 ) + 1 ) * 10 - $sumFinal ;
} else {
$cleVerif = 0 ;
}
if ( $cle == $cleVerif ) {
return true ;
} else
return false ;
} else return false ;
}
/** Obtenir le code ISIN à partir d ' un siren
**
** @ param integer $siren
** @ return string
**/
2015-01-20 16:32:59 +00:00
function getCodeIsin ( $siren = false )
{
2013-11-05 11:18:30 +00:00
if ( ! $siren )
$siren = $this -> siren ;
2015-01-20 16:32:59 +00:00
$tabTmp = $this -> iDb -> select ( 'jo.infos_entrep' , 'isin' , " siren= $siren AND isin<>'' " , false , MYSQL_ASSOC );
2013-11-05 11:18:30 +00:00
return trim ( @ $tabTmp [ 0 ][ 'isin' ]);
}
/** Obtenir le SIREN à partir d ' un code ISIN
**
** @ param string $isin Code ISIN
** @ return integer
**/
2015-01-20 16:32:59 +00:00
function getCodeSiren ( $isin )
{
$tabTmp = $this -> iDb -> select ( 'jo.infos_entrep' , 'siren' , " isin=' $isin ' AND siren<>0 " , false , MYSQL_ASSOC );
2013-11-05 11:18:30 +00:00
return trim ( $tabTmp [ 0 ][ 'siren' ]);
}
/** A partir d ' un siren , récupère les informations règlementés
**
** @ param integer $siren
** @ param integer $id
** @ return unknown
**/
function getInfosReg ( $siren = false , $id = null )
{
if ( ! $siren ) $siren = $this -> siren ;
$isin = $this -> getCodeIsin ( $siren );
$tabRet = array ();
if ( $isin != '' ) {
$sqlID = '' ;
if ( null !== $id ) {
$sqlID = " AND id= $id " ;
}
2015-01-20 16:32:59 +00:00
$bodacc = $this -> iDb -> select (
'presse.articles' ,
2013-11-05 11:18:30 +00:00
'id, companyName, companyIsin, companySiren, companyWebSite, pressReleaseDate, pressReleaseTitle, ' .
'pressReleaseText, pressReleaseHtml, pressReleaseAttachments, pressReleaseUrl, source, dateInsert' ,
" companyIsin=' $isin ' $sqlID ORDER BY pressReleaseDate DESC " , true , MYSQL_ASSOC );
if ( count ( $bodacc ) > 0 ) {
foreach ( $bodacc as $k => $ann ) {
if ( $id )
$tabRet [ $k ] = array (
'id' => $ann [ 'id' ],
'source' => $this -> getLibSource ( $ann [ 'source' ]),
'DateParution' => $ann [ 'pressReleaseDate' ],
'raisonSociale' => $ann [ 'companyName' ],
'titre' => $ann [ 'pressReleaseTitle' ],
'communique' => $ann [ 'pressReleaseText' ],
'communiqueHtml' => $ann [ 'pressReleaseHtml' ],
'pj' => $ann [ 'pressReleaseAttachments' ],
'url' => $ann [ 'pressReleaseUrl' ],
'dateInsertionSD' => $ann [ 'dateInsert' ],
);
else
$tabRet [ $k ] = array (
'id' => $ann [ 'id' ],
'source' => $this -> getLibSource ( $ann [ 'source' ]),
'DateParution' => $ann [ 'pressReleaseDate' ],
'raisonSociale' => $ann [ 'companyName' ],
'titre' => $ann [ 'pressReleaseTitle' ],
'pj' => $ann [ 'pressReleaseAttachments' ],
'url' => $ann [ 'pressReleaseUrl' ],
'dateInsertionSD' => $ann [ 'dateInsert' ],
);
}
}
}
return $tabRet ;
}
/** A partir d ' un siren , récupère les informations boursières
**
** @ param integer $siren
** @ return unknown
**/
2015-01-20 16:32:59 +00:00
function getInfosBourse ( $siren = false )
{
2013-11-05 11:18:30 +00:00
global $timer ;
if ( ! $siren )
$siren = $this -> siren ;
$isin = $this -> getCodeIsin ( $siren );
$timer [ 'infosBoursieres-getCodeIsin' ] = microtime ( true );
$tabRet = array ();
if ( $isin <> '' ) {
2015-01-20 16:32:59 +00:00
$tabRes = $this -> iDb -> select (
'sdv1.bourse_isin b, sdv1.bourse_cours c' ,
'siren, raisonSociale, adresse, effectif, code_sicovam, code_mnemo, code_bloomberg, code_datastream, code_isin, logo, code_ric, ' .
'dateIntroduction, dateDerAG, dateRadiation, autre_isin, eligibleSRD, eligiblePEA, nombreTitres, tel1, tel2, fax1, fax2, web, mail, ' .
'marche, placeCotation, description, secteur, activite, activiteDet, dirigeants, actionnaires, chiffresTrim, ' .
'c.autre, c.`date`, c.`heure`, c.`open` , c.`high` , c.`low` , c.`close` , c.`volume`' ,
" code_isin=' $isin ' /*OR siren= $siren )*/ AND b.code_isin=c.isin AND c.autre IN('','e','f','g','m','s','u') ORDER BY c.`date` DESC, c.`heure` DESC LIMIT 0,1 " , false , MYSQL_ASSOC );
2013-11-05 11:18:30 +00:00
$tabRet = $tabRes [ 0 ];
$timer [ 'infosBoursieres-infosIsin' ] = microtime ( true );
2015-01-20 16:32:59 +00:00
$tabRes = $this -> iDb -> select ( 'sdv1.bourse_cours' ,
'min(close) AS coursMin, avg(close) AS coursMoy, max(close) AS coursMax' ,
" isin=' $isin ' GROUP BY isin " , false , MYSQL_ASSOC );
2013-11-05 11:18:30 +00:00
$tabTmp = $tabRes [ 0 ];
$tabRet [ 'coursMin' ] = $tabTmp [ 'coursMin' ];
$tabRet [ 'coursMoy' ] = $tabTmp [ 'coursMoy' ];
$tabRet [ 'coursMax' ] = $tabTmp [ 'coursMax' ];
$timer [ 'infosBoursieres-derniersCours' ] = microtime ( true );
}
2015-06-05 15:29:18 +00:00
2013-11-05 11:18:30 +00:00
return $tabRet ;
}
}