2012-10-30 09:46:59 +00:00
< ? php
2010-11-04 15:17:32 +00:00
require_once 'framework/common/curl.php' ;
2010-11-04 11:21:31 +00:00
2012-10-30 09:46:59 +00:00
class MBourse
{
2010-11-04 11:21:31 +00:00
var $siren = false ;
2011-08-29 14:32:39 +00:00
2010-11-04 11:21:31 +00:00
public function __construct ( $siren = 0 ) {
2012-10-30 09:46:59 +00:00
$this -> siren = $siren ;
2010-11-04 11:21:31 +00:00
}
2011-08-29 14:32:39 +00:00
2010-11-04 11:21:31 +00:00
public function getLibSource ( $source ) {
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 ;
}
}
2011-08-29 14:32:39 +00:00
2010-11-04 11:21:31 +00:00
/** Obtenir le code ISIN à partir d ' un siren
**
2012-10-30 09:46:59 +00:00
** @ param integer $siren
2010-11-04 11:21:31 +00:00
** @ return string
**/
function getCodeIsin ( $siren = false ) {
$iDb = new WDB ();
if ( ! $siren )
$siren = $this -> siren ;
2011-08-29 14:32:39 +00:00
2010-11-04 11:21:31 +00:00
$tabTmp = $iDb -> select ( 'infos_entrep' , 'isin' , " siren= $siren AND isin<>'' " , false , MYSQL_ASSOC );
return trim ( @ $tabTmp [ 0 ][ 'isin' ]);
}
/** Obtenir le SIREN à partir d ' un code ISIN
**
** @ param string $isin Code ISIN
** @ return integer
**/
function getCodeSiren ( $isin ) {
$iDb = new WDB ();
$tabTmp = $iDb -> select ( 'infos_entrep' , 'siren' , " isin=' $isin ' AND siren<>0 " , false , MYSQL_ASSOC );
return trim ( $tabTmp [ 0 ][ 'siren' ]);
}
2011-08-29 14:32:39 +00:00
2010-11-04 11:21:31 +00:00
/** 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 = false ) {
2011-08-29 14:32:39 +00:00
2010-11-04 11:21:31 +00:00
if ( ! $siren )
$siren = $this -> siren ;
$isin = $this -> getCodeIsin ( $siren );
unset ( $iDb );
$tabRet = array ();
if ( $isin <> '' ) {
$iDb = new WDB ( 'presse' );
if ( $id ) $sqlID = " AND id= $id " ;
else $sqlID = '' ;
2011-08-29 14:32:39 +00:00
2010-11-04 11:21:31 +00:00
$bodacc = $iDb -> select ( 'articles' ,
'id, companyName, companyIsin, companySiren, companyWebSite, pressReleaseDate, pressReleaseTitle, ' .
'pressReleaseText, pressReleaseHtml, pressReleaseAttachments, pressReleaseUrl, source, dateInsert' ,
" companyIsin=' $isin ' $sqlID ORDER BY pressReleaseDate DESC " , false , 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' ],
);
2012-10-30 09:46:59 +00:00
else
2010-11-04 11:21:31 +00:00
$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 ;
}
2011-08-29 14:32:39 +00:00
2010-11-04 11:21:31 +00:00
/** A partir d ' un siren , récupère les informations boursières
**
** @ param integer $siren
** @ return unknown
**/
function getInfosBourse ( $siren = false ) {
2010-11-29 16:12:32 +00:00
global $timer ;
2010-11-04 11:21:31 +00:00
$iDb = new WDB ( 'sdv1' );
if ( ! $siren )
$siren = $this -> siren ;
$isin = $this -> getCodeIsin ( $siren );
2010-11-29 16:12:32 +00:00
$timer [ 'infosBoursieres-getCodeIsin' ] = microtime ( true );
2010-11-04 11:21:31 +00:00
$tabRet = array ();
if ( $isin <> '' ) {
2010-11-29 16:12:32 +00:00
$datePre = date ( 'Y-m' ) . '-01' ;
2012-10-30 09:46:59 +00:00
if ( APPLICATION_ENV == 'development' ) {
$tabRes = $iDb -> select ( 'bourse_isin b, 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 b.dateUpdate DESC, c.dateInsert DESC LIMIT 0,1 " , false , MYSQL_ASSOC );
} else {
$tabRes = $iDb -> select ( 'bourse_isin b, 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') AND c.`date`>=' $datePre ' ORDER BY b.dateUpdate DESC, c.dateInsert DESC LIMIT 0,1 " , false , MYSQL_ASSOC );
}
2010-11-04 11:21:31 +00:00
$tabRet = $tabRes [ 0 ];
2010-11-29 16:12:32 +00:00
$timer [ 'infosBoursieres-infosIsin' ] = microtime ( true );
2011-08-29 14:32:39 +00:00
2010-11-04 11:21:31 +00:00
$tabRes = $iDb -> select ( 'bourse_cours' ,
'min(close) AS coursMin, avg(close) AS coursMoy, max(close) AS coursMax' ,
" isin=' $isin ' GROUP BY isin " , false , MYSQL_ASSOC );
$tabTmp = $tabRes [ 0 ];
$tabRet [ 'coursMin' ] = $tabTmp [ 'coursMin' ];
$tabRet [ 'coursMoy' ] = $tabTmp [ 'coursMoy' ];
$tabRet [ 'coursMax' ] = $tabTmp [ 'coursMax' ];
2010-11-29 16:12:32 +00:00
$timer [ 'infosBoursieres-derniersCours' ] = microtime ( true );
2012-10-30 09:46:59 +00:00
2010-11-04 11:21:31 +00:00
}
return $tabRet ;
}
2012-10-30 09:46:59 +00:00
}