/** * Displays a form to create a new Document entity. * * @Route("/new", name="document_new") * @Method("GET") */ public function newAction($ajax = false, $params = null) { $entity = new Document(); $options = array(); if ($params && is_array($params)) { $em = $this->getDoctrine()->getManager(); if (array_key_exists('candidature_id', $params)) { $candidature = $em->getRepository('CandidaturesBundle:Candidature')->find($params['candidature_id']); $entity->setCandidature($candidature); $options = array('candidature' => 'hide', 'evenement' => 'hide'); } if (array_key_exists('evenement_id', $params)) { $evenement = $em->getRepository('CandidaturesBundle:Evenement')->find($params['evenement_id']); $entity->setCandidature($evenement); $options = array('candidature' => 'hide', 'evenement' => 'hide'); } } $form = $this->createCreateForm($entity, $options); if ($ajax) { return $this->render('CandidaturesBundle:Document:form.html.twig', array('form' => $form->createView())); } return $this->render('CandidaturesBundle:Document:new.html.twig', array('entity' => $entity, 'form' => $form->createView())); }
/** * Add documents * * @param \NomayaCandidaturesBundle\Entity\Document $documents * @return Candidature */ public function addDocument(\NomayaCandidaturesBundle\Entity\Document $document) { // Assure l'enregistrement de la clé étrangère $document->setCandidature($this); $this->documents[] = $document; return $this; }