/**
  * @Route("/propose", name="covoiturage_my_propose")
  * @Template()
  */
 public function proposeAction(Request $request)
 {
     if (!$this->getUserLayer()->isUser()) {
         return $this->createAccessDeniedResponse();
     }
     /** @var EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     $proposal = new Covoit();
     $proposal->setAuthor($this->getUser());
     $proposal->setStartCity($em->getRepository('EtuCoreBundle:City')->find(749));
     // Troyes
     $proposal->setEndCity($em->getRepository('EtuCoreBundle:City')->find(826));
     // Paris
     if ($this->getUser()->getPhoneNumber()) {
         $proposal->setPhoneNumber($this->getUser()->getPhoneNumber());
     }
     $form = $this->createForm($this->get('etu.covoit.form.proposal'), $proposal);
     if ($request->getMethod() == 'POST' && $form->submit($request)->isValid()) {
         $proposal->setStartHour($proposal->getStartHour()->format('H:i'));
         $proposal->setEndHour($proposal->getEndHour()->format('H:i'));
         $em->persist($proposal);
         $em->flush();
         // Add current user as subscriber
         $this->getSubscriptionsManager()->subscribe($this->getUser(), 'covoit', $proposal->getId());
         // Dispatch the covoit for alerts
         $this->get('etu.covoit.notifs_dispatcher')->dispatch($proposal);
         $this->get('session')->getFlashBag()->set('message', array('type' => 'success', 'message' => 'covoit.messages.created'));
         return $this->redirect($this->generateUrl('covoiturage_view', ['id' => $proposal->getId(), 'slug' => $proposal->getStartCity()->getSlug() . '-' . $proposal->getEndCity()->getSlug()]));
     }
     return ['form' => $form->createView()];
 }
 /**
  * Does the given alert match the given covoit.
  *
  * @param CovoitAlert $alert
  * @param Covoit $covoit
  * @return bool
  */
 private function match(CovoitAlert $alert, Covoit $covoit)
 {
     if ($alert->getStartCity() && $alert->getStartCity()->getId() != $covoit->getStartCity()->getId()) {
         return false;
     }
     if ($alert->getEndCity() && $alert->getEndCity()->getId() != $covoit->getEndCity()->getId()) {
         return false;
     }
     if ($alert->getPriceMax() && $alert->getPriceMax() < $covoit->getPrice()) {
         return false;
     }
     if ($alert->getStartDate() && $alert->getEndDate()) {
         if ($alert->getStartDate() > $covoit->getDate() || $alert->getEndDate() < $covoit->getDate()) {
             return false;
         }
     } elseif ($alert->getStartDate() && !$alert->getEndDate()) {
         if ($alert->getStartDate() != $covoit->getDate()) {
             return false;
         }
     } elseif (!$alert->getStartDate() && $alert->getEndDate()) {
         if ($alert->getEndDate() < $covoit->getDate()) {
             return false;
         }
     }
     return true;
 }
Example #3
0
 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     $faker = Factory::create('fr_FR');
     $covoit = new Covoit();
     $covoit->setAuthor($this->getReference('user_user'));
     $covoit->setStartCity($this->getReference('city_troyes'));
     $covoit->setEndCity($this->getReference('city_paris'));
     $covoit->setStartAdress($faker->text(150));
     $covoit->setEndAdress($faker->text(150));
     $covoit->setStartHour('16:00');
     $covoit->setEndHour('19:00');
     $covoit->setCapacity(rand(2, 5));
     $covoit->setDate($faker->dateTimeThisYear);
     $covoit->setPhoneNumber($faker->phoneNumber);
     $covoit->setPrice(rand(15, 35));
     $covoit->setNotes($faker->text(250));
     $manager->persist($covoit);
     $manager->flush();
 }