/** * @Security("has_role('ROLE_USER')") * @ParamConverter("emplacement", options={"mapping": {"emplacement_id" : "id"}}) */ public function updateAction(Emplacement $emplacement, Request $request) { if (!$this->getUser()->canDisplayExploitation($emplacement->getRucher()->getExploitation()) || !$emplacement->canBeUpdated()) { throw new NotFoundHttpException('Page inexistante.'); } $form = $this->createForm(new EmplacementType(), $emplacement); if ($form->handleRequest($request)->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($emplacement); $em->flush(); $flash = $this->get('braincrafted_bootstrap.flash'); $flash->success('Emplacement mis à jour avec succès'); return $this->redirect($this->generateUrl('kg_beekeeping_management_view_rucher', array('rucher_id' => $emplacement->getRucher()->getId()))); } return $this->render('KGBeekeepingManagementBundle:Emplacement:update.html.twig', array('form' => $form->createView(), 'emplacement' => $emplacement)); }
/** * @Security("has_role('ROLE_USER')") * @ParamConverter("emplacement", options={"mapping": {"emplacement_id" : "id"}}) */ public function addAction(Emplacement $emplacement, Request $request) { if (!$this->getUser()->canDisplayExploitation($emplacement->getRucher()->getExploitation()) || !$emplacement->isEmpty()) { throw new NotFoundHttpException('Page inexistante.'); } $ruche = new Ruche($emplacement); $form = $this->createForm(new RucheType(), $ruche); if ($form->handleRequest($request)->isValid()) { // La date du remérage est la même que celle de la création de la colonie $ruche->getColonie()->getRemerages()[0]->setDate($ruche->getColonie()->getDateColonie()); $em = $this->getDoctrine()->getManager(); $em->persist($ruche->getColonie()); $em->flush(); $flash = $this->get('braincrafted_bootstrap.flash'); $flash->success('Ruche créée avec succès'); return $this->redirect($this->generateUrl('kg_beekeeping_management_view_rucher', array('rucher_id' => $ruche->getRucher()->getId()))); } return $this->render('KGBeekeepingManagementBundle:Ruche:add.html.twig', array('form' => $form->createView(), 'emplacement' => $emplacement)); }
/** * @Assert\Callback */ public function isContentValid(ExecutionContextInterface $context) { foreach ($this->getColonie()->getTranshumances() as $lastTranshumance) { if ($this->date < $lastTranshumance->getDate() && $lastTranshumance->getId() != $this->getId()) { $context->buildViolation('La date ne peut pas être antérieur à celle d\'une ancienne transhumance')->atPath('date')->addViolation(); } } if ($this->date < $this->getColonie()->getDateColonie()) { $context->buildViolation('La date ne peut pas être antérieur à celle de la naissance de la colonie')->atPath('date')->addViolation(); } $today = new \DateTime(); if ($this->date > $today) { $context->buildViolation('La date ne peut pas être située dans le futur')->atPath('date')->addViolation(); } if ($this->emplacementfrom && $this->emplacementto) { if ($this->emplacementfrom->getRucher() == $this->emplacementto->getRucher()) { $context->buildViolation('La transhumance ne peut pas se faire dans le même rucher')->atPath('rucherto')->addViolation(); } } }
/** * Set emplacement * * @param \KG\BeekeepingManagementBundle\Entity\Emplacement $emplacement * @return Ruche */ public function setEmplacement(\KG\BeekeepingManagementBundle\Entity\Emplacement $emplacement = null) { $this->emplacement = $emplacement; if ($emplacement) { $emplacement->setRuche($this); $this->rucher = $emplacement->getRucher(); } return $this; }