/**
  * Ajoute un technicien sur une intervention
  * @Secure(roles="ROLE_USER")
  * @Template()
  */
 public function newAction(Shifting $shifting)
 {
     $entity = new ShiftTechnician();
     $entity->setBegin(new \DateTime());
     $form = $this->get('form.factory')->createNamed('shiftTechNew' . $shifting->getId(), new AddTechnicianType(), $entity);
     return array('shifting' => $shifting, 'entity' => $entity, 'form' => $form->createView(), 'id' => $shifting->getId());
 }
 /**
  * Displays a form to create a new InterventionPlanned entity.
  *
  * @Template()
  * @Secure(roles="ROLE_USER")
  */
 public function newAction()
 {
     $entity = new ShiftTechnician();
     $entity->setBegin(new \DateTime());
     $shifting = new Equipment();
     $shifting->setPlace('Saint-Soupplets (Bureau)');
     $shifting->setReason('Récupération matériel');
     $entity->setShifting($shifting);
     $form = $this->createForm(new RecuperationEquipmentType(), $entity);
     return array('entity' => $entity, 'form' => $form->createView());
 }
 /**
  * Cherche les entretiens les plus proche d'une adresse
  *
  * @Template()
  */
 public function neighborAction(Door $door)
 {
     $em = $this->getDoctrine()->getManager();
     // Choper les entretiens à faire
     $repo = $em->getRepository('JLMDailyBundle:Maintenance');
     $maints = $repo->getOpened();
     $repo = $em->getRepository('JLMDailyBundle:Ride');
     $baseUrl = 'http://maps.googleapis.com/maps/api/distancematrix/json?sensor=false&language=fr-FR&origins=' . $door->getCoordinates() . '&destinations=';
     foreach ($maints as $maint) {
         $dest = $maint->getDoor();
         if (!$repo->hasRide($door, $dest)) {
             $url = $baseUrl . $dest->getCoordinates();
             $string = file_get_contents($url);
             $json = json_decode($string);
             if ($json->status == 'OK' && isset($json->rows[0]->elements[0]->duration->value) && isset($json->rows[0]->elements[0]->duration->value)) {
                 $ride = new Ride();
                 $ride->setDeparture($door);
                 $ride->setDestination($dest);
                 $ride->setDuration($json->rows[0]->elements[0]->duration->value);
                 $ride->setDistance($json->rows[0]->elements[0]->distance->value);
                 $em->persist($ride);
             }
         }
     }
     $em->flush();
     $entities = $repo->getMaintenanceNeighbor($door, 30);
     $forms = array();
     foreach ($entities as $entity) {
         $shift = new ShiftTechnician();
         $shift->setBegin(new \DateTime());
         $forms[] = $this->get('form.factory')->createNamed('shiftTechNew' . $entity->getDestination()->getNextMaintenance()->getId(), new AddTechnicianType(), $shift)->createView();
     }
     return array('door' => $door, 'entities' => $entities, 'forms_addTech' => $forms);
 }