示例#1
0
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $builder->add('differentielDelai', 'integer', array('label' => 'Modification du Délai (+/- x jours)', 'required' => true))->add('objet', 'textarea', array('label' => 'Exposer les causes de l’Avenant. Ne pas hésiter à détailler l\'historique des relations avec le client et du travail sur l\'étude qui ont conduit à l\'Avenant.', 'required' => true))->add('clauses', 'choice', array('label' => 'Type d\'avenant', 'multiple' => true, 'choices' => Av::getClausesChoices()))->add('phases', 'collection', array('type' => new PhaseType(), 'options' => array('isAvenant' => true), 'allow_add' => true, 'allow_delete' => true, 'prototype' => true, 'by_reference' => false));
     /*->add('avenantsMissions', 'collection', array(
           'type' => new AvMissionType,
           'allow_add' => true,
           'allow_delete' => true,
           'prototype' => true,
           'by_reference' => false,
       ))*/
     DocTypeType::buildForm($builder, $options);
 }
示例#2
0
 /**
  * @Security("has_role('ROLE_SUIVEUR')")
  */
 public function modifierAction($id, $idEtude = null)
 {
     $em = $this->getDoctrine()->getManager();
     if ($idEtude) {
         if (!($etude = $em->getRepository('Mgate\\SuiviBundle\\Entity\\Etude')->find($idEtude))) {
             throw $this->createNotFoundException('L\'étude n\'existe pas !');
         }
         $av = new Av();
         $av->setEtude($etude);
         $etude->addAv($av);
     } elseif (!($av = $em->getRepository('Mgate\\SuiviBundle\\Entity\\Av')->find($id))) {
         throw $this->createNotFoundException('L\'avenant n\'existe pas !');
     }
     $etude = $av->getEtude();
     if ($this->get('Mgate.etude_manager')->confidentielRefus($etude, $this->getUser(), $this->get('security.authorization_checker'))) {
         throw new AccessDeniedException('Cette étude est confidentielle');
     }
     $phasesAv = array();
     if ($av->getPhases()) {
         $phasesAv = $av->getPhases()->toArray();
         foreach ($av->getPhases() as $phase) {
             $av->removePhase($phase);
             $em->remove($phase);
         }
     }
     $phasesChanges = array();
     $phasesEtude = $av->getEtude()->getPhases()->toArray();
     foreach ($phasesEtude as $phase) {
         $changes = new PhaseChange();
         $phaseAV = new Phase();
         $this->copyPhase($phase, $phaseAV);
         if ($phaseOriginAV = $this->getPhaseByPosition($phaseAV->getPosition(), $phasesAv)) {
             $this->mergePhaseIfNotNull($phaseAV, $phaseOriginAV, $changes);
         }
         $phaseAV->setEtude()->setAvenant($av);
         $av->addPhase($phaseAV);
         $phasesChanges[] = $changes;
     }
     $form = $this->createForm(new AvType(), $av, array('prospect' => $av->getEtude()->getProspect()));
     if ($this->get('request')->getMethod() == 'POST') {
         $form->bind($this->get('request'));
         if ($form->isValid()) {
             $phasesEtude = $av->getEtude()->getPhases()->getValues();
             foreach ($av->getPhases() as $phase) {
                 $toKeep = false;
                 $av->removePhase($phase);
                 if (!($phaseEtude = $this->getPhaseByPosition($phase->getPosition(), $phasesEtude))) {
                     $toKeep = true;
                 }
                 if (isset($phaseEtude)) {
                     $toKeep = $this->nullFielIfEqual($phase, $phaseEtude);
                 }
                 if ($toKeep) {
                     $av->addPhase($phase);
                 }
                 unset($phaseEtude);
             }
             foreach ($av->getPhases() as $phase) {
                 $phase->setEtatSurAvenant(0);
                 if ($this->phaseChange($phase)) {
                     // S'il n'y a plus de modification sur la phase
                     $em->persist($phase);
                 } else {
                     $av->removePhase($phase);
                 }
             }
             if ($idEtude) {
                 // Si on ajoute un avenant
                 $em->persist($etude);
             } else {
                 // Si on modifie un avenant
                 $em->persist($av);
             }
             $em->flush();
             return $this->redirect($this->generateUrl('MgateSuivi_av_voir', array('id' => $av->getId())));
         }
     }
     return $this->render('MgateSuiviBundle:Av:modifier.html.twig', array('form' => $form->createView(), 'av' => $av, 'changes' => $phasesChanges));
 }