示例#1
0
 /**
  * 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.');
     }
 }
示例#2
0
 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);
     }
 }
示例#3
0
 /**
  * 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)));
 }