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(); } }
public function testRenderShow() { $trip = new Trip('Praha (test)', 'Brno (test)'); $service = new TripService($this->entityManager); $service->save($trip); $presenter = new TripPresenter(); $request = new PresenterRequest('Trip', 'GET', array('action' => 'show', 'id' => $trip->id)); $response = $presenter->run($request); $this->assertType('Nette\\Application\\RenderResponse', $response); }
/** * locationsForm submit handler (trip saving). * @param Nette\Application\AppForm */ public function submitLocationsForm(AppForm $form) { $values = $form->values; $service = new TripService($this->entityManager); try { $trip = $service->buildTrip($values['from'], $values['to'], new TripCurlMapper()); $service->save($trip); $this->flashMessage('Trip successfully saved.'); $this->redirect('Trip:show', array('id' => $trip->id)); } catch (InvalidStateException $e) { $form->addError('Error occurred while getting directions. Please try again later.'); } }
public function testBuildTrips() { $service = new TripService($this->entityManager); $trip = $service->buildTrip('Praha', 'Brno', new MockTripMapper()); $this->assertType('Trip', $trip); // data from MockTripMapper $this->assertEquals(3, $trip->distance); $this->assertEquals(6, $trip->duration); $this->assertEquals(3, count($trip->steps)); // 3 cycles (3 steps) foreach ($trip->steps as $step) { $this->assertType('Step', $step); $this->assertEquals('text', $step->instructions); $this->assertEquals(1, $step->distance); $this->assertEquals(2, $step->duration); } }
/** * AJAX signal handler for getting navigation directions info. */ public function handleDirections() { $from = $this->request->post['from']; $to = $this->request->post['to']; $service = new TripService($this->entityManager); try { $trip = $service->buildTrip($from, $to, new TripCurlMapper()); } catch (InvalidStateException $e) { $this->terminate(new JsonResponse(array('status' => 'FAIL'))); } $steps = array(); foreach ($trip->steps as $step) { $arr = array(); $arr['distance'] = $step->distance; $arr['instructions'] = $step->instructions; $steps[] = $arr; } $this->terminate(new JsonResponse(array('status' => 'OK', 'duration' => $trip->duration, 'distance' => $trip->distance, 'steps' => $steps))); }