Ejemplo n.º 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();
     }
 }
Ejemplo n.º 2
0
 /**
  * @author Petr Vales
  * @version 4.11.2010
  */
 public function handlePois()
 {
     $location = $this->request->post['location'];
     $service = new LocationService();
     $coords = $service->getCoordinates($location);
     $service = new PoiService($this->entityManager);
     try {
         $key = Environment::getConfig('api')->gowallaKey;
         $pois = $service->getPois($coords['latitude'], $coords['longitude'], new PoiGowallaMapper($key));
     } catch (InvalidStateException $e) {
         $this->terminate(new JsonResponse(array('status' => 'FAIL')));
     }
     $jsonResponse = array();
     foreach ($pois as $poi) {
         $jsonResponse['pois'][] = array('name' => $poi->name, 'types' => $poi->types, 'address' => $poi->address, 'latitude' => $poi->latitude, 'longitude' => $poi->longitude, 'url' => $poi->url, 'icon' => $poi->imageUrl);
     }
     $jsonResponse['status'] = 'OK';
     $jsonResponse['latitude'] = $coords['latitude'];
     $jsonResponse['longitude'] = $coords['longitude'];
     $this->terminate(new JsonResponse($jsonResponse));
 }