bebeboutik-api/app/Models/Carrier.php
2017-11-17 18:33:56 +01:00

81 lines
2.3 KiB
PHP

<?php
namespace App\Models;
use Antadis\API\Front\Models\Carrier as BaseCarrier;
/**
* @rest\model Carrier
* @rest\property inetger is_relay
*/
class Carrier extends BaseCarrier
{
protected $_relayConfiguration = NULL;
const NORMAL = 0;
const MONDIALRELAY = 1;
const COLSSIMO_OFFICE = 2;
const COLSSIMO_PICKUP = 3;
/**
* 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;
}
public function isRelay() {
$relayConfiguration = $this->getRelayConfiguration();
return in_array($this->id, explode(',', $relayConfiguration));
}
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;
}
protected function getUrlToGetRelays() {
$url = null;
$type = $this->getType();
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;
}
/**
* {@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,
));
}
}