/** * @param Itinerary $anItinerary * @return RouteCandidateDto */ public function toDto(Itinerary $anItinerary) { $legs = array(); foreach ($anItinerary->legs() as $leg) { $legDto = new LegDto(); $legDto->setLoadLocation($leg->loadLocation()); $legDto->setUnloadLocation($leg->unloadLocation()); $legDto->setLoadTime($leg->loadTime()->format(\DateTime::ISO8601)); $legDto->setUnloadTime($leg->unloadTime()->format(\DateTime::ISO8601)); $legs[] = $legDto; } $routeCandidate = new RouteCandidateDto(); $routeCandidate->setLegs($legs); return $routeCandidate; }
/** * @param Cargo $aCargo * @return CargoRoutingDto */ public function toDto(Cargo $aCargo) { $cargoRoutingDto = new CargoRoutingDto(); $cargoRoutingDto->setTrackingId($aCargo->trackingId()->toString()); $cargoRoutingDto->setOrigin($aCargo->origin()); $cargoRoutingDto->setFinalDestination($aCargo->routeSpecification()->destination()); foreach ($aCargo->itinerary()->legs() as $leg) { $legDto = new LegDto(); $legDto->setLoadLocation($leg->loadLocation()); $legDto->setUnloadLocation($leg->unloadLocation()); $legDto->setLoadTime($leg->loadTime()->format(\DateTime::ISO8601)); $legDto->setUnloadTime($leg->unloadTime()->format(\DateTime::ISO8601)); $cargoRoutingDto->addLeg($legDto); } return $cargoRoutingDto; }
/** * @param array $legs * @return LegDto[] */ private function toLegDtosFromData(array $legs) { $legDtos = array(); foreach ($legs as $legData) { $legDto = new LegDto(); $legDto->setLoadLocation($legData['load_location']); $legDto->setUnloadLocation($legData['unload_location']); $legDto->setLoadTime($legData['load_time']); $legDto->setUnloadTime($legData['unload_time']); $legDtos[] = $legDto; } return $legDtos; }