getMessage(),null,"pacsoft-tracking.log",true); return false; } if($data = json_decode($response,true)) { $response = $data; } if($response && is_array($response)) { return $this->_handleTrackingResponse($response); } return false; } protected function _handleTrackingResponse($data) { $response = array(); $response['data'] = $data; $response['status'] = array('header' => '', 'body' => ''); $response['history'] = array(); if(isset($data['TrackingInformationResponse']['shipments']) && is_array($data['TrackingInformationResponse']['shipments'])) { foreach($data['TrackingInformationResponse']['shipments'] as $shipment) { if(isset($shipment['statusText']) && is_array($shipment['statusText'])) { $response['status']['header'] = isset($shipment['statusText']['header']) ? $shipment['statusText']['header'] : ""; $response['status']['body'] = isset($shipment['statusText']['body']) ? $shipment['statusText']['body'] : ""; } $response['status']['code'] = isset($shipment['status']) ? str_replace('_', '', strtolower($shipment['status'])) : ""; foreach($shipment['items'] as $item) { if(isset($item['events']) && is_array($item['events'])) { foreach($item['events'] as $event) { $history = array(); $history['time'] = isset($event['eventTime']) ? date("d/m-Y H:i",strtotime($event['eventTime'])) : ""; $history['message'] = isset($event['eventDescription']) ? $event['eventDescription'] : ""; $history['message'] .= isset($event['location']['city']) ? " ".$event['location']['city'] : ""; if(isset($event['status']) && $event['status'] == "DELIVERED") { if(isset($item['acceptor']['name']) && $item['acceptor']['name']) { $history['message'] .= " til " . $item['acceptor']['name']; } } $response['history'][] = $history; } } } } } return $response; } }