extranet/includes/graydon/functions2.php
Michael RICOIS bd30dd70de MAJ Graydon
2009-04-23 06:53:26 +00:00

334 lines
8.2 KiB
PHP

<?php
/**
* @file
* Fonctions utiles pour l'utilisation du webservice graydon
*
*/
function parseReport($type){}
/*
* Parcours le contenu du rapport en XML
*
* return array
*/
function parseReportXML($xml){
global $firephp;
$tabReport = array();
$doc = new DOMDocument;
$doc->preserveWhiteSpace = false;
$doc->loadxml($xml);
$xpath = new DOMXPath($doc);
$query = '/GraydonUKCompanySchema/CompanyReportPage/CompanyReport';
$report = $xpath->query($query);
//Liste des elements à parser
$elements = array( 'Company', 'Name', 'Address', 'Communication', 'Country', 'Credit_Rating',
'Date', 'DirectorsDetail', 'Employees', 'Financial_Summary', 'Legal_Form',
'Share_CapitalSummary', 'Taxonomy'
);
foreach($elements as $elementName){
//Pour chaque element, nouvelle requete xpath
$queryElement = $query.'/'.$elementName;
switch($elementName){
case "Company" :
$tabReport['Company'] = pxmlCompany($queryElement);
break;
case "Name";
$tabReport['Name'] = pxmlName($queryElement);
break;
case "Address";
$tabReport['Address'] = pxmlAddress($queryElement);
break;
case "Communication";
$tabReport['Communication'] = pxmlCommunication($queryElement);
break;
case "Country";
$country = pxmlCountry($queryElement);
if($country) $tabReport['Country'] = $country;
break;
case "Credit_Rating";
$creditRating = pxmlCreditRating($queryElement);
if($creditRating) $tabReport['CreditRating'] = $creditRating;
break;
case "Date";
$tabReport['Date'] = pxmlDate($queryElement);
break;
case "DirectorsDetail";
break;
case "Employees";
break;
case "Financial_Summary";
break;
case "Legal_Form";
break;
case "Share_CapitalSummary";
break;
case "Taxonomy";
break;
}
}
return $tabReport;
}
function pxmlCompany($query){
global $xpath;
global $firephp;
$firephp->log($query,'query');
$tabCompany = array();
$items = $xpath->query($query);
$countCompany = 0;
$oldType ='';
foreach ($items as $item){
$type = $item->getAttribute('Type');
if($type!=$oldType){$countCompany = 0;}
//Name
$name = $item->getElementsByTagName("Name")->item(0)->nodeValue;
$tabCompany[$type][$countCompany]['Name'] = $item->getElementsByTagName("Name")->item(0)->nodeValue;
//CompanyId
$tabCompanyId = pxmlCompanyId($query.'[@Type="'.$type.'"]/CompanyId');
if($tabCompanyId){ $tabCompany[$type][$countCompany]['CompanyId'] = $tabCompanyId;}
//Country
//@TODO
//Address
$tabAddress = pxmlAddress($query.'[@Type="'.$type.'"]['.$countCompany.']/Address');
if($tabAddress){ $tabCompany[$type][$countCompany]['Address'] = $tabAddress;}
//Amount
//@TODO
//FreeText
//@TODO
//Date
$tabDate = pxmlDate($query.'[@Type="'.$type.'"]/Date');
if($tabDate){ $tabCompany[$type][$countCompany]['Date'] = $tabDate;}
$oldType = $type;
$countCompany++;
}
return $tabCompany;
}
function pxmlCompanyId($query){
global $xpath;
global $firephp;
$tabCompanyId = array();
$items = $xpath->query($query);
if($items->length>0){
foreach ($items as $item){
$type = $item->getAttribute('Type');
$tabCompanyId[$type] = $item->nodeValue;
}
return $tabCompanyId;
}else{
return false;
}
}
function pxmlDate($query){
global $xpath;
global $firephp;
$tabDate = array();
$items = $xpath->query($query);
if($items->length>0){
foreach ($items as $item){
$type = $item->getAttribute('Type');
$format = $item->getAttribute('Format');
$value = $item->nodeValue;
//Formattage de la date
switch($format){
case "CCYY":
$date = $value;
break;
case "CCYYMMDD":
$date = substr($value,6,2).'/'.substr($value,4,2).'/'.substr($value,0,4);
break;
case "DD":
$date = $value;
break;
case "DDMM":
$date = $value;
break;
case "DDMMCCYY":
$date = $value;
break;
case "MM":
$timestamp = mktime(0, 0, 0, date("m")-$value, 1, date("Y"));
$date = date('m/Y',$timestamp);
break;
case "MMCCYY":
$date = $value;
break;
case "MMDDCCYY":
$date = substr($value,2,2).'/'.substr($value,0,2).'/'.substr($value,4,4);
break;
case "DD/MM/CCYY":
$date = $value;
break;
default:
$date = $value;
}
$tabDate[$type] = $date;
}
return $tabDate;
}else{
return false;
}
}
/*
* Lit le noeud xml Name
*
*/
function pxmlName($query){
global $xpath;
global $firephp;
$tabName = array();
$items = $xpath->query($query);
$countName = 0;
foreach ($items as $item){
$type = $item->getAttribute('Type');
if($type !='' ){ $index = $type; }else{$index = $countName;}
$tabName[$index] = $item->nodeValue;
$countName++;
}
return $tabName;
}
function pxmlAddress($query){
global $xpath;
global $firephp;
$tabAddress = array();
$firephp->log($query, 'query');
$items = $xpath->query($query);
$countAddress = 0;
if($items->length>0){
foreach ($items as $item){
$type = $item->getAttribute('Type');
if($type !='' ){ $index = $type; }else{$index = $countAddress;}
//Liste des elements à parser
$elements = array('EntireAddress', 'Building', 'Street', 'Town', 'City', 'County', 'PostCode', 'Country');
foreach($elements as $elementName){
if($emelmentName == 'Country'){
}else{
$value = $item->getElementsByTagName($elementName)->item(0)->nodeValue;
if ($value) { $tabAddress[$index][$elementName] = $value; }
}
}
$countAddress++;
}
return $tabAddress;
}else{
return false;
}
}
function pxmlCommunication($query){
global $xpath;
global $firephp;
$tabCommunication = array();
$items = $xpath->query($query);
if($items->length>0){
foreach ($items as $item){
$type = $item->getAttribute('Type');
if($type != '' ){
$tabCommunication[$type] = $item->nodeValue;
}
}
return $tabCommunication;
}else{
return false;
}
}
function pxmlCountry($query){
global $xpath;
global $firephp;
$tabCountry = array();
$items = $xpath->query($query);
$countCountry = 0;
if($items->length>0){
foreach ($items as $item){
$type = $item->getAttribute('Type');
if($type !='' ){ $tabName[$countCountry]['Type'] = $type; }
$dialcode = $item->getAttribute('DialCode');
if($dialcode !='' ){ $tabName[$countCountry]['DialCode'] = $dialcode; }
$isocode = $item->getAttribute('ISOCode');
if($isocode !='' ){ $tabName[$countCountry]['ISOCode'] = $isocode; }
$tabName[$countCountry]['Value'] = $item->nodeValue;
$countCountry++;
}
return $tabCountry;
}else{
return false;
}
}
function pxmlCreditRating($query){
global $xpath;
global $firephp;
$tab = array();
$items = $xpath->query($query);
$count = 0;
if($items->length>0){
foreach ($items as $item){
//Get type of Credit Rating
$type = $item->getAttribute('Type');
$units = $item->getAttribute('Units');
if($units !='' ){ $tab[$type]['Units'] = $units; }
switch($type){
case "Credit_Score" :
$tab[$type]['Value'] = $item->firstChild->nodeValue;
$freetextList = $item->getElementsByTagName('FreeText');
foreach ($freetextList as $freetext){
$tab[$type]['text'][$freetext->getAttribute('Type')] = $freetext->nodeValue;
}
break;
case "Previous_Credit_Score" :
$tab[$type]['Value'] = $item->firstChild->nodeValue;
$freetextList = $item->getElementsByTagName('FreeText');
foreach ($freetextList as $freetext){
$tab[$type]['text'][$freetext->getAttribute('Type')] = $freetext->nodeValue;
}
break;
case "Maximum_Credit_Guide" :
$amount = $item->getElementsByTagName('Amount')->item(0)->nodeValue;
$tab[$type]['Currency']= $item->getElementsByTagName('Currency')->item(0)->nodeValue;
$tab[$type]['Value'] = $amount;
$freetextList = $item->getElementsByTagName('FreeText');
foreach ($freetextList as $freetext){
$tab[$type]['text'][$freetext->getAttribute('Type')] = $freetext->nodeValue;
}
break;
}
$count++;
}
return $tab;
}else{
return false;
}
}
function pxmlDirectorsDetail($query){
}
function pxmlEmployees(){}
function pxmlFinancialSummary(){}
function pxmlLegalForm(){}
function pxmlShareCapitalSummary(){}
function pxmlTaxonomy(){}
function parseReportHTML(){}
function parseReportDOC(){}
?>