/** * @param array $legs * @return LegDto[] */ private function toLegDtosFromData(array $legs) : array { $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; }
/** * @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::ATOM)); $legDto->setUnloadTime($leg->unloadTime()->format(\DateTime::ATOM)); $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::ATOM)); $legDto->setUnloadTime($leg->unloadTime()->format(\DateTime::ATOM)); $cargoRoutingDto->addLeg($legDto); } return $cargoRoutingDto; }