code = $code; $this->carrier = $carrier; $this->to = $to; $this->from = $from; $this->current_status = $current_status; $this->history = $history; } public function setCode(string $code) { $this->code = $code; } public function getCode(): string { return $this->code; } public function setCarrier(string $carrierid) { $this->carrier = $carrierid; } public function getCarrier() { return $this->carrier; } public function setService(Service $service) { $this->service = $service; } public function getService() { return $this->service; } public function setTo(Location $to) { $this->to = $to; } public function getTo() { return $this->to; } public function setFrom(Location $from) { $this->from = $from; } public function getFrom() { return $this->from; } public function setCurrentStatus(TrackingEntry $status) { $this->current_status = $status; } public function getCurrentStatus() { return $this->current_status; } public function getHistory() { return $this->history; } public function appendHistoryEntry(TrackingEntry $history) { $this->history[] = $history; } public function toObject() { $output = [ "status" => "OK", "code" => $this->getCode(), "carrier" => [ "code" => Carriers::getCarrierCode($this->getCarrier()), "name" => Carriers::getCarrierName($this->getCarrier()) ], "service" => [ "id" => $this->service->id, "name" => $this->service->name ], "addresses" => [ "from" => [ "street" => "", "city" => "Unknown", "state" => "", "zip" => "", "country" => "" ], "to" => [ "street" => "", "city" => "Unknown", "state" => "", "zip" => "", "country" => "" ] ], "current" => [ "status" => "UNKNOWN", "details" => "No tracking information found.", "date" => time(), "location" => [ "street" => "", "city" => "", "state" => "", "zip" => "", "country" => "" ] ], "history" => [ ] ]; if (!is_null($this->getCurrentStatus())) { $output["current"] = [ "status" => TrackingStatus::statusToString($this->getCurrentStatus()->getStatus()), "details" => $this->getCurrentStatus()->toString(), "datetime" => $this->getCurrentStatus()->getDateTime(), "timestamp" => $this->getCurrentStatus()->getTimestamp(), "containerscan" => $this->getCurrentStatus()->isContainerScan(), "location" => [ "street" => "", "city" => "Unknown", "state" => "", "zip" => "", "country" => "" ] ]; if (!empty($this->getCurrentStatus()->getLocation())) { $output["current"]["location"] = [ "street" => $this->getCurrentStatus()->getLocation()->street, "city" => $this->getCurrentStatus()->getLocation()->city, "state" => $this->getCurrentStatus()->getLocation()->state, "zip" => $this->getCurrentStatus()->getLocation()->zip, "country" => $this->getCurrentStatus()->getLocation()->country ]; } } if (!is_null($this->getFrom())) { $output["addresses"]["from"] = [ "street" => $this->getFrom()->street, "city" => $this->getFrom()->city, "state" => $this->getFrom()->state, "zip" => $this->getFrom()->zip, "country" => $this->getFrom()->country ]; } if (!is_null($this->getTo())) { $output["addresses"]["to"] = [ "street" => $this->getTo()->street, "city" => $this->getTo()->city, "state" => $this->getTo()->state, "zip" => $this->getTo()->zip, "country" => $this->getTo()->country ]; } if (!is_null($this->getHistory())) { foreach ($this->getHistory() as $history) { $output["history"][] = [ "status" => TrackingStatus::statusToString($history->getStatus()), "details" => $history->toString(), "datetime" => $history->getDateTime(), "timestamp" => $history->getTimestamp(), "containerscan" => $history->isContainerScan(), "location" => [ "street" => $history->getLocation()->street, "city" => $history->getLocation()->city, "state" => $history->getLocation()->state, "zip" => $history->getLocation()->zip, "country" => $history->getLocation()->country ], ]; } } return $output; } }