Beispiel #1
0
 public function renderShow($id)
 {
     $service = new TripService($this->entityManager);
     $trip = $service->find($id);
     $this->template->trip = $trip;
     try {
         $eventService = new EventService();
         $config = Environment::getConfig('api');
         $events = $eventService->getEvents($trip->arrival, new DateTime(), new EventfulMapper($config->eventfulUser, $config->eventfulPassword, $config->eventfulKey));
         $this->template->events = $events;
     } catch (InvalidStateException $e) {
         $this->template->events = array();
     }
     $articleService = new ArticleService($this->entityManager);
     $this->template->article = $articleService->buildArticle($trip->arrival, new ArticleWikipediaMapper());
     try {
         $airportMapper = new AirportTravelMathMapper();
         $airportService = new AirportService();
         $locationService = new LocationService();
         $coordinates = $locationService->getCoordinates($trip->getDeparture());
         $from = $airportService->searchNearestAirport($airportMapper, $coordinates['latitude'], $coordinates['longitude']);
         $coordinates = $locationService->getCoordinates($trip->getArrival());
         $to = $airportService->searchNearestAirport($airportMapper, $coordinates['latitude'], $coordinates['longitude']);
         $flightMapper = new FlightKayakMapper();
         $flightService = new FlightService($this->entityManager);
         $depart_date = new DateTime('now');
         $return_date = new DateTime('+1 week');
         $this->template->flights = $flightService->buildFlights($flightMapper, $from, $to, $depart_date, $return_date, '1', 'e', 'n');
     } catch (FlightException $e) {
         $this->template->flightsError = "Connection with search system <a href='http://kayak.com'>Kayak</a> failed.";
     } catch (AirportException $e) {
         $this->template->flightsError = $e->getMessage();
     }
 }