Méthode getCompanyMatchIdentifier et getComapnyProducts

This commit is contained in:
Michael RICOIS 2009-06-08 12:33:29 +00:00
parent 51be02d1bd
commit 961f34c0cb
2 changed files with 141 additions and 2 deletions

View File

@ -108,6 +108,8 @@ define('GRAYDON_WSDL', realpath(dirname(__FILE__)).'/GraydonCompanyData.wsdl');
define('USER_PROFILE','SESS38R7'); define('USER_PROFILE','SESS38R7');
define('PASSWORD','E88MSU4'); define('PASSWORD','E88MSU4');
require_once realpath(dirname(__FILE__)).'/wsfunctions.php';
$options = array('trace' => 1); $options = array('trace' => 1);
//$options = array('trace' => 1, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS); //$options = array('trace' => 1, 'features' => SOAP_SINGLE_ELEMENT_ARRAYS);
// Create a soap client // Create a soap client

View File

@ -21,10 +21,147 @@ getCompanyReports
*/ */
function getCompanyMatchIdentifiers($pays){
global $firephp, $graydon, $authentication;
$firephp->info('Méthode getCompanyMatchIdentifiers');
setDbConn('graydon');
$q = Doctrine_Query::create()
->from('Matchidentifiers')
->where('country = ?', $pays);
$matchidentifiers = new Matchidentifiers();
$matchidentifiers = $q->fetchOne();
/** Recup des types d'identifiants pour le pays **/
if($matchidentifiers == FALSE){
//Récupération des intitulés identifiant
$request = new StdClass();
$request->Authentication_Parameters = $authentication;
$request->Country = $pays;
$firephp->log($request,'REQUETE CompanyMatchIdentifier');
try
{
$result = $graydon->getCompanyMatchIdentifiers($request);
//Enregistrement de l'action dans les logs
$transactionIdentifier = $result->Service_Log->TransactionIdentifier;
$sessionID = $result->Service_Log->SessionID;
graydonRequeteLog($_SESSION['tabInfo']['login'], $page, 'getCompanyMatchIdentifiers', $transactionIdentifier, $sessionID);
//Log de la requete dans la bdd
$log = new Requetelog();
$log->login = $_SESSION['tabInfo']['login'];
$log->action = 'getCompanyMatchIdentifiers';
$log->request = serialize($request);
$log->transactionIdentifier = $transactionIdentifier;
$log->sessionID = $sessionID;
$log->mode = $mode;
$log->save();
$count = count($result->CompanyMatchIdentifiers);
if ($count>1){
$tabIdentifiers = $result->CompanyMatchIdentifiers->CompanyMatchIdentifier->CompanyIdentifier;
}elseif($count==1){
$tabIdentifiers[] = $result->CompanyMatchIdentifiers->CompanyMatchIdentifier->CompanyIdentifier;
}
//Stockage du résultat de la méthode en cache
$matchidentifiers = new Matchidentifiers();
$matchidentifiers->country = $pays;
$matchidentifiers->identifiers = serialize($tabIdentifiers);
$matchidentifiers->replace();
}catch( SoapFault $fault ){
$code = $fault->detail->GraydonCompanyData_Fault->FaultReturnCode;
$text = $fault->detail->GraydonCompanyData_Fault->FaultMessage;
$firephp->log($text,'texterror');
require_once 'graydon/graydon_error.php';
if(graydon_error($code, $text)!=FALSE){
if($code=='CWS0112'){
//Stockage du résultat de la méthode en cache
$matchidentifiers = new Matchidentifiers();
$matchidentifiers->country = $pays;
$matchidentifiers->identifiers = serialize(false);
$matchidentifiers->replace();
}
}else{
graydon_processSoapFault($graydon,$fault,$tabInfo);
}
}
}else{
$firephp->info('tabIdentifiers pris dans la bdd');
$tabIdentifiers = unserialize($matchidentifiers->identifiers);
}
return $tabIdentifiers;
}
function getCompanyProducts($identifier){
global $firephp, $graydon, $authentification;
setDbConn('graydon');
$q = Doctrine_Query::create()
->from('Companyproducts')
->where('identifiers = ?', $identifier);
$companyproducts = new Companyproducts();
$companyproducts = $q->fetchOne();
$firephp->log($companyproducts->updated_at,'date');
$now = mktime(date('G'), date('i'), date('s'), date("m") , date("d"), date("Y"));
if($companyproducts == FALSE){
$request = new StdClass();
$request->Authentication_Parameters = $authentication;
$request->CompanyMatchIdentifier = $identifier;
try {
// Make a request on the web service
$result = $graydon->getCompanyProducts($request);
//Enregistrement de l'action dans les logs
$transactionIdentifier = $result->Service_Log->TransactionIdentifier;
$sessionID = $result->Service_Log->SessionID;
graydonRequeteLog($_SESSION['tabInfo']['login'], $page, 'getCompanyProducts', $transactionIdentifier, $sessionID);
//Log de la requete dans la bdd
$log = new Requetelog();
$log->login = $_SESSION['tabInfo']['login'];
$log->action = 'getCompanyProducts';
$log->request = serialize($request);
$log->transactionIdentifier = $transactionIdentifier;
$log->sessionID = $sessionID;
$log->mode = $mode;
$log->save();
$firephp->log($result,'result');
//Sauvegarde dans la bdd
$companyproducts = new Companyproducts();
$companyproducts->identifiers = $identifier;
$companyproducts->company = serialize($result->Company);
$companyproducts->products = serialize($result->Products);
$companyproducts->replace();
//Extraction
$company = $result->Company;
$products = $result->Products->Product;
}catch( SoapFault $fault ){
$code = $fault->detail->GraydonCompanyData_Fault->FaultReturnCode;
$text = $fault->detail->GraydonCompanyData_Fault->FaultMessage;
$firephp->log($text,'texterror');
require_once 'graydon/graydon_error.php';
if(graydon_error($code, $text)==FALSE){
graydon_processSoapFault($graydon,$fault,$tabInfo);
}
}
}else{
$company = unserialize($companyproducts->company);
$products = unserialize($companyproducts->products);
$products = $products->Product;
}
return array('Company' => $company, 'Products' => $products);
}
?> ?>