2017-07-21 16:40:11 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
use Antadis\API\Front\Models\Carrier as BaseCarrier;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @rest\model Carrier
|
|
|
|
* @rest\property inetger is_relay
|
|
|
|
*/
|
|
|
|
class Carrier extends BaseCarrier
|
|
|
|
{
|
2017-11-17 18:33:56 +01:00
|
|
|
protected $_relayConfiguration = NULL;
|
2017-07-21 16:40:11 +02:00
|
|
|
|
2017-11-17 18:33:56 +01:00
|
|
|
const NORMAL = 0;
|
|
|
|
const MONDIALRELAY = 1;
|
|
|
|
const COLSSIMO_OFFICE = 2;
|
|
|
|
const COLSSIMO_PICKUP = 3;
|
2017-10-12 12:31:06 +02:00
|
|
|
|
2017-11-17 18:33:56 +01:00
|
|
|
/**
|
|
|
|
* Returns carrier_ids which are relay
|
|
|
|
* @return type
|
|
|
|
*/
|
|
|
|
protected function getRelayConfiguration() {
|
|
|
|
if ($this->_relayConfiguration === NULL) {
|
|
|
|
$this->_relayConfiguration = \Configuration::get('ANT_CARRIERS_OOH');
|
|
|
|
}
|
|
|
|
return $this->_relayConfiguration;
|
|
|
|
}
|
2017-07-21 16:40:11 +02:00
|
|
|
|
2017-11-17 18:33:56 +01:00
|
|
|
public function isRelay() {
|
|
|
|
$relayConfiguration = $this->getRelayConfiguration();
|
|
|
|
return in_array($this->id, explode(',', $relayConfiguration));
|
|
|
|
}
|
2017-10-12 12:31:06 +02:00
|
|
|
|
2017-11-17 18:33:56 +01:00
|
|
|
public function getType() {
|
|
|
|
if ($this->isRelay() === false) {
|
|
|
|
return self::NORMAL;
|
|
|
|
} else {
|
|
|
|
if (strpos($this->name, 'Colissimo') !== false) {
|
|
|
|
if (strpos($this->name, 'PickUp') !== false) {
|
|
|
|
return self::COLSSIMO_PICKUP;
|
|
|
|
} else {
|
|
|
|
return self::COLSSIMO_OFFICE;
|
|
|
|
}
|
|
|
|
} elseif (strpos($this->name, 'Mondial Relay') !== false) {
|
|
|
|
return self::MONDIALRELAY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return self::NORMAL;
|
|
|
|
}
|
2017-10-12 12:31:06 +02:00
|
|
|
|
2017-11-17 18:33:56 +01:00
|
|
|
protected function getUrlToGetRelays() {
|
|
|
|
$url = null;
|
|
|
|
$type = $this->getType();
|
2017-10-12 12:31:06 +02:00
|
|
|
|
2017-11-17 18:33:56 +01:00
|
|
|
if ($type === self::MONDIALRELAY) {
|
|
|
|
$url = '/relays/mondialrelay';
|
|
|
|
} elseif ($type === self::COLSSIMO_OFFICE) {
|
|
|
|
$url = '/relays/socolissimo/office';
|
|
|
|
} elseif ($type === self::COLSSIMO_PICKUP) {
|
|
|
|
$url = '/relays/socolissimo/pickup';
|
|
|
|
}
|
|
|
|
return $url;
|
|
|
|
}
|
2017-10-12 12:31:06 +02:00
|
|
|
|
2017-11-17 18:33:56 +01:00
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function toArray() {
|
|
|
|
$relayConfiguration = $this->getRelayConfiguration();
|
|
|
|
$isRelay = in_array($this->id, explode(',', $relayConfiguration));
|
|
|
|
$urlToCall = $isRelay === false ? null : $this->getUrlToGetRelays($this->name);
|
|
|
|
return array_merge(parent::toArray(), array(
|
|
|
|
'is_relay' => $isRelay,
|
|
|
|
'url_to_call' => $urlToCall,
|
|
|
|
'external_module' => $this->external_module_name,
|
|
|
|
));
|
|
|
|
}
|
2017-07-21 16:40:11 +02:00
|
|
|
}
|