Files
bio-concept-pharma/web/modules/nkmgls/classes/GlsController.php
2019-11-17 19:14:07 +01:00

192 lines
7.6 KiB
PHP

<?php
/**
* Module made by Nukium
*
* @author Nukium
* @copyright 2018 Nukium SAS
* @license All rights reserved
*
* ███ ██ ██ ██ ██ ██ ██ ██ ██ ███ ███
* ████ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████
* ██ ██ ██ ██ ██ █████ ██ ██ ██ ██ ████ ██
* ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
* ██ ████ ██████ ██ ██ ██ ██████ ██ ██
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
class GlsController
{
/**
* Soap Location du webservice
* @var string
*/
private $soap_location = 'http://www.gls-group.eu/276-I-PORTAL-WEBSERVICE/services/ParcelShopSearch/wsdl/2010_01_ParcelShopSearch.wsdl';
/**
* Login du webservice GLS
* @var string $ws_login
*/
private $ws_login = '';
/**
* Mot de passe du webservice GLS
* @var string $ws_pwd
*/
private $ws_pwd = '';
/**
* Client SOAP
* @var SoapClient
*/
private $soap_client = null;
public function __construct($_params = null)
{
if (!is_null($_params)) {
$this->ws_login = $_params['GLS_WSLOGIN'];
$this->ws_pwd = $_params['GLS_WSPWD'];
}
}
/**
* recherche d'un point relais
* @return object
*/
public function searchRelay($_cp, $_city = '', $_country = 'FR', $_street = '')
{
$soapclient = $this->getSoapClient();
if ($soapclient) {
//__ paramètre de la requête
$credentials = array('UserName' => $this->ws_login, 'Password' => $this->ws_pwd);
$address = array('ZipCode' => $_cp, 'Country' => $_country, 'City' => $_city, 'Name1' => '', 'Street1' => $_street);
$params = array('Credentials' => $credentials, 'Address' => $address);
try {
$response = $soapclient->GetParcelShops($params);
//__ Si aucun résultat on réduit le champs de recherche
if (!empty($response)
&& isset($response->exitCode->ErrorCode)
&& ((int)$response->exitCode->ErrorCode == 998 || (int)$response->exitCode->ErrorCode == 999)
) {
$address = array('ZipCode' => $_cp, 'Country' => $_country, 'City' => '', 'Name1' => '', 'Street1' => '');
$params = array('Credentials' => $credentials, 'Address' => $address);
$response = $soapclient->GetParcelShops($params);
}
} catch (SoapFault $e) {
return null;
}
if (!empty($response)) {
return $response;
} else {
return null;
}
}
return null;
}
/**
* Permet d'obtenir plus d'informations sur un point relais en particulier
* @param int $_id
*/
public function getRelayDetail($_id)
{
$soapclient = $this->getSoapClient();
if ($soapclient) {
//__ paramètre de la requête
$credentials = array('UserName' => $this->ws_login, 'Password' => $this->ws_pwd);
$params = array('ParcelShopId' => $_id, 'Credentials' => $credentials);
try {
$response = $soapclient->GetParcelShopById($params);
} catch (SoapFault $e) {
return false;
}
if (!empty($response)) {
if ($response->ExitCode->ErrorCode == 0) {
//__ Retour d'un tableau condensé des informations
return array(
'parcelShopById' => $_id,
'Name1' => $response->ParcelShop->Address->Name1,
'Street1' => $response->ParcelShop->Address->Street1,
'ZipCode' => $response->ParcelShop->Address->ZipCode,
'City' => $response->ParcelShop->Address->City,
'Country' => $response->ParcelShop->Address->Country,
'Phone' => $response->ParcelShop->Phone->Contact,
'Mobile' => $response->ParcelShop->Mobile->Contact,
'email' => $response->ParcelShop->Email,
'url' => $response->ParcelShop->URL,
'latitude' => $response->ParcelShop->GLSCoordinates->Latitude,
'longitude' => $response->ParcelShop->GLSCoordinates->Longitude,
'GLSWorkingDay' => $response->ParcelShop->GLSWorkingDay,
'Name2' => (!empty($response->ParcelShop->Address->Name2) ? $response->ParcelShop->Address->Name2 : ''),
'Name3' => (!empty($response->ParcelShop->Address->Name3) ? $response->ParcelShop->Address->Name3 : ''),
'ContactName' => (!empty($response->ParcelShop->Address->ContactName) ? $response->ParcelShop->Address->ContactName : ''),
'BlockNo1' => (!empty($response->ParcelShop->Address->BlockNo1) ? $response->ParcelShop->Address->BlockNo1 : ''),
'Street2' => (!empty($response->ParcelShop->Address->Street2) ? $response->ParcelShop->Address->Street2 : ''),
'BlockNo2' => (!empty($response->ParcelShop->Address->BlockNo2) ? $response->ParcelShop->Address->BlockNo2 : ''),
'Province' => (!empty($response->ParcelShop->Address->Province) ? $response->ParcelShop->Address->Province : ''),
);
} else {
//__ TODO: Gestion d'erreur à afficher ensuite dans les logs ?
}
} else {
//__ TODO: Gestion d'erreur à afficher ensuite dans les logs ?
}
}
return false;
}
/**
* Méthode créant le client SOAP de connexion au webservice GLS
*/
private function getSoapClient()
{
if (empty($this->soap_client)) {
try {
$this->soap_client = @new SoapClient(
$this->soap_location,
array(
'trace' => 1,
'cache_wsdl'=>WSDL_CACHE_NONE,
'exceptions'=>true,
'connection_timeout'=>15,)
);
//__ test de l'existe d'au moins une fonction
$soap_client_connected = false;
if (is_array($this->soap_client->__getFunctions())) {
foreach ($this->soap_client->__getFunctions() as $value) {
if (strpos($value, 'GetParcelShops') !== false) {
$soap_client_connected = true;
break;
}
}
}
if (!$soap_client_connected) {
return false;
}
} catch (SoapFault $e) {
return false;
} catch (Exception $e) {
return false;
}
}
return $this->soap_client;
}
}