Exemplo n.º 1
0
 /**
  * @Security("has_role('ROLE_SUIVEUR')")
  */
 public function addAction()
 {
     $etude = new Etude();
     $etude->setMandat($this->get('Mgate.etude_manager')->getMaxMandat());
     $etude->setNum($this->get('Mgate.etude_manager')->getNouveauNumero());
     $user = $this->getUser();
     if (is_object($user) && $user instanceof User) {
         $etude->setSuiveur($user->getPersonne());
     }
     $form = $this->createForm(new EtudeType(), $etude);
     $em = $this->getDoctrine()->getManager();
     $error_messages = array();
     if ($this->get('request')->getMethod() == 'POST') {
         $form->handleRequest($this->get('request'));
         if ($form->isValid()) {
             if (!$etude->isKnownProspect()) {
                 $etude->setProspect($etude->getNewProspect());
             }
             $em->persist($etude);
             $em->flush();
             if ($this->get('request')->get('ap')) {
                 return $this->redirect($this->generateUrl('MgateSuivi_ap_rediger', array('id' => $etude->getId())));
             } else {
                 return $this->redirect($this->generateUrl('MgateSuivi_etude_voir', array('nom' => $etude->getNom())));
             }
         } else {
             //constitution du tableau d'erreurs
             $errors = $this->get('validator')->validate($etude);
             foreach ($errors as $error) {
                 array_push($error_messages, $error->getPropertyPath() . ' : ' . $error->getMessage());
             }
         }
     }
     return $this->render('MgateSuiviBundle:Etude:ajouter.html.twig', array('form' => $form->createView(), 'errors' => $error_messages));
 }