extranet/includes/graydon/functions.php
2009-04-20 12:41:56 +00:00

265 lines
7.2 KiB
PHP

<?php
/**
* @file
* Fonctions utiles pour l'utilisation du webservice graydon
*
*/
function parseCompany($type){
global $xpath;
$query = '//GraydonUKCompanySchema/CompanyReportPage/CompanyReport/Company[@Type="'.$type.'"]';
$items = $xpath->query($query);
$attributs = array('Type');
$elements = array('Name', 'CompanyId', 'Address', 'FreeText', 'Date');
foreach ($items as $item) {
//Traitement des attributs
foreach($attributs as $attrName){
$tab[$attrName] = $item->getAttribute($attrName);
}
//Traitement des éléments
foreach($elements as $elementName){
$node = $item->getElementsByTagName($elementName);
if($elementName == 'Name'){ $tab[$elementName] = formatName($node); }
if($elementName == 'Address'){ $tab[$elementName] = parseAddress($node); }
if($elementName == 'CompanyId'){ $tab[$elementName] = parseCompanyId($node); }
if($elementName == 'FreeText'){ }
if($elementName == 'Date'){ $tab[$elementName] = parseDate($node); }
}
}
return $tab;
}
function parseCompanyAddress(){
global $xpath;
$query = '//GraydonUKCompanySchema/CompanyReportPage/CompanyReport/Address';
$items = $xpath->query($query);
$tab = parseAddress($items);
return $tab;
}
function parseLegal_Form(){
global $xpath;
$tab = array();
$query = '//GraydonUKCompanySchema/CompanyReportPage/CompanyReport/Legal_Form';
$items = $xpath->query($query);
foreach ($items as $item) {
$tab[$item->getAttribute('Type')] = $item->nodeValue;
}
return $tab;
}
function parseCompanyDateCreation(){
global $xpath;
$query = '//GraydonUKCompanySchema/CompanyReportPage/CompanyReport/Company[@Type="Subject"]/Date[@Type="Age_of_Company"]';
$items = $xpath->query($query);
if ($items->length>0){
$date = formatDate($items->item(0)->nodeValue,$items->item(0)->getAttribute('Format'));
}
return $date;
}
function parseCommunication(){
global $xpath;
$tab = array();
$query = '//GraydonUKCompanySchema/CompanyReportPage/CompanyReport/Communication';
$items = $xpath->query($query);
foreach ($items as $item) {
$type = $item->getAttribute('Type');
$tab[$type] = $item->nodeValue;
}
return $tab;
}
function parseDirectorDetails(){
global $xpath;
$tab = array();
$query = '//GraydonUKCompanySchema/CompanyReportPage/CompanyReport/DirectorsDetail';
$items = $xpath->query($query);
$attributs = array('Type','Nationality', 'Title');
$elements = array('Name','Address');
$countDirector = 0;
foreach ($items as $item) {
//Traitement des attributs
foreach($attributs as $attrName){
$tab[$countDirector][$attrName] = $item->getAttribute($attrName);
}
//Traitement des éléments
foreach($elements as $elementName){
$node = $item->getElementsByTagName($elementName);
if($elementName == 'Name' && $node->length<=1){
$tab[$countDirector][$elementName] = formatName($node);
}else{
$tab[$countDirector][$elementName] = parseName($node);
}
if($elementName == 'Address'){ $tab[$countDirector][$elementName] = parseAddress($node); }
}
$countDirector++;
}
return $tab;
}
function parseAddress($nodeList){
$tab = array();
$elements = array('EntireAddress','Building', 'Street', 'Town', 'City', 'PostCode', 'Country');
foreach ($nodeList as $domElement){
$type = $domElement->getAttribute('Type');
//Traitement des éléments
foreach($elements as $elementName){ $tab[$type][$elementName] = $domElement->getElementsByTagName($elementName)->item(0)->nodeValue; }
}
return $tab;
}
function parseDate($nodeList){
$tab = array();
foreach ($nodeList as $domElement){
$type = $domElement->getAttribute('Type');
$format = $domElement->getAttribute('Format');
$tab[$type] = formatDate($domElement->nodeValue, $format);
}
return $tab;
}
function parseCompanyId($nodeList){
$tab = array();
foreach ($nodeList as $domElement){
$type = $domElement->getAttribute('Type');
if ($type != 'Internal'){
$tab[$type] = $domElement->nodeValue;
}
}
return $tab;
}
function parseTaxonomy($type){
global $xpath;
$query = '//GraydonUKCompanySchema/CompanyReportPage/CompanyReport/Taxonomy[@Type="'.$type.'"]';
$items = $xpath->query($query);
foreach ($items as $item){
$type = $item->getAttribute('Type');
$tab[$type]['Code'] = $item->getAttribute('Code');
$tab[$type]['Value'] = $item->nodeValue;
}
return $tab;
}
function parseName($nodeList){
$tab = array();
foreach ($nodeList as $domElement){
$type = $domElement->getAttribute('Type');
$tab[$type] = $domElement->nodeValue;
}
$name = '';
if (isset($tab['Family'])){ $name = $tab['Family'];}
if (isset($tab['Family']) && isset($tab['Christian'])){ $name = $tab['Family'].', '.$tab['Christian'];}
return $name;
}
function parseEmployees($type){
global $xpath;
$query = '//GraydonUKCompanySchema/CompanyReportPage/CompanyReport/Employees[@Type="'.$type.'"]';
$items = $xpath->query($query);
foreach ($items as $item){
$number = $item->nodeValue;
}
return $number;
}
function parseShare_Capital(){
global $xpath;
$tab = array();
$query = '//GraydonUKCompanySchema/CompanyReportPage/CompanyReport/Share_CapitalSummary/Share_Capital';
$items = $xpath->query($query);
foreach ($items as $item){
$currency = $item->getElementsByTagName('Currency')->item(0)->nodeValue;
$amountList = $item->getElementsByTagName('Amount');
$tab = parseAmount($amountList, $currency);
}
return $tab;
}
function parseFinancial_Summary(){
global $xpath;
$tab = array();
$query = '//GraydonUKCompanySchema/CompanyReportPage/CompanyReport/Financial_Summary';
$items = $xpath->query($query);
foreach ($items as $item){
$amountList = $item->getElementsByTagName('Amount');
$tab = parseAmount($amountList);
}
return $tab;
}
function parseAmount($nodeList, $currency = ''){
$amount = array();
foreach ($nodeList as $domElement){
$format = $domElement->getAttribute('Format');
$type = $domElement->getAttribute('Type');
$unit = $domElement->getAttribute('Units');
$value = $domElement->nodeValue * $unit;
if($currency!=''){
$value = $value.' '.$currency;
}elseif($domElement->getAttribute('Currency')!= ''){
$value = $value.' '.$domElement->getAttribute('Currency');
}
if($format == 'Percentage'){ $value = $value.' %'; }
$amount[$type] = $value;
}
return $amount;
}
function parseFreeText($query){
global $xpath;
$tab = array();
$items = $xpath->query($query);
foreach ($items as $item){
$tab[] = $item->nodeValue;
}
return $tab;
}
function formatName($node){
/*
Court
Christian => Prénom
Family => Nom de famille (+ Prénom)
Trade
Trading_Division =>
Product
Full_Name
From
To
Subject
*/
return $node->item(0)->nodeValue;
}
function formatDate($value, $format){
if ($format=="CCYY"){
$date = $value;
}elseif($format=="CCYYMMDD"){
$date = substr($value,6,2).'/'.substr($value,4,2).'/'.substr($value,0,4);
}elseif($format=="DD"){
$date = $value;
}elseif($format=="DDMM"){
$date = $value;
}elseif($format=="DDMMCCYY"){
$date = $value;
}elseif($format=="MM"){
$timestamp = mktime(0, 0, 0, date("m")-$value, 1, date("Y"));
$date = date('m/Y',$timestamp);
}elseif($format=="MMCCYY"){
$date = $value;
}elseif($format=="MMDDCCYY"){
$date = substr($value,2,2).'/'.substr($value,0,2).'/'.substr($value,4,4);
}elseif($format=="DD/MM/CCYY"){
$date = $value;
}
return $date;
}
?>