first commit
This commit is contained in:
105
class/class.AutomaticImportAspireConnect.php
Normal file
105
class/class.AutomaticImportAspireConnect.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
class AutomaticImportAspireConnect
|
||||
{
|
||||
private $loginid;
|
||||
private $Password;
|
||||
private $BaseUrl;
|
||||
private $xml;
|
||||
|
||||
public function __construct($loginid = null, $Password = null)
|
||||
{
|
||||
$this->loginid = $loginid;
|
||||
$this->Password = $Password;
|
||||
}
|
||||
|
||||
public function Run()
|
||||
{
|
||||
self::getItemsDetails();
|
||||
|
||||
return $this->xml;
|
||||
}
|
||||
|
||||
public function __set($name, $value)
|
||||
{
|
||||
switch ($name) {
|
||||
case 'loginid':
|
||||
$this->loginid = $value;
|
||||
break;
|
||||
case 'Password':
|
||||
$this->Password = $value;
|
||||
break;
|
||||
case 'BaseUrl':
|
||||
$this->BaseUrl = $value;
|
||||
break;
|
||||
case 'url':
|
||||
$this->url = $value;
|
||||
break;
|
||||
case 'xml':
|
||||
$this->xml = $value;
|
||||
break;
|
||||
default:
|
||||
throw new Exception('Variable '.$name.' not found.');
|
||||
}
|
||||
}
|
||||
|
||||
public function __get($name)
|
||||
{
|
||||
switch ($name) {
|
||||
case 'loginid':
|
||||
return $this->loginid;
|
||||
break;
|
||||
case 'Password':
|
||||
return $this->Password;
|
||||
break;
|
||||
default:
|
||||
throw new Exception('Variable '.$name.' not found.');
|
||||
}
|
||||
}
|
||||
|
||||
private function downloadXmlFile()
|
||||
{
|
||||
$aspireConnect = new SoapClient($this->url, ['trace' => true]);
|
||||
|
||||
$data = $aspireConnect->KompletniKatalog(['login' => $this->loginid, 'password' => $this->Password]);
|
||||
// $header = $aspireConnect->__getLastRequestHeaders();
|
||||
// $dt = $aspireConnect->__getLastRequest();
|
||||
|
||||
if (is_soap_fault($data)) {
|
||||
throw new Exception("SOAP Fault: (faultcode: {$data->faultcode}, faultstring: {$data->faultstring}), ".E_USER_ERROR);
|
||||
}
|
||||
|
||||
if ($data->KompletniKatalogResult != 0) {
|
||||
throw new Exception("Chyba importu Aspire, odpoved {$data->KompletniKatalogResult}");
|
||||
}
|
||||
|
||||
return $data->Katalogy;
|
||||
}
|
||||
|
||||
private function getItemsDetails()
|
||||
{
|
||||
$url_xml = self::downloadXmlFile();
|
||||
$root = 'xml';
|
||||
|
||||
$xml = new SimpleXMLElement("<{$root}></{$root}>");
|
||||
$f = function ($f, $c, $a) {
|
||||
foreach ((array) $a as $k => $v) {
|
||||
if (is_array($v) || is_object($v)) {
|
||||
if (is_numeric($k)) {
|
||||
$ch = $c->addChild('item');
|
||||
} else {
|
||||
$ch = $c->addChild($k);
|
||||
}
|
||||
$f($f, $ch, $v);
|
||||
} else {
|
||||
$c->addChild($k, htmlspecialchars($v));
|
||||
}
|
||||
}
|
||||
};
|
||||
foreach ($url_xml->Katalog as $Katalog) {
|
||||
$f($f, $xml, isset($Katalog->KatalogPolozky) ? $Katalog->KatalogPolozky : (isset($Katalog->KatalogPolozka) ? $Katalog->KatalogPolozka : []));
|
||||
}
|
||||
|
||||
$this->xml = $xml;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user