public function newAction(Request $request, $campaign)
 {
     $campaignService = $this->get('campaignchain.core.campaign');
     $campaign = $campaignService->getCampaign($campaign);
     $milestoneType = $this->get('campaignchain.core.form.type.milestone');
     $milestoneType->setBundleName(self::BUNDLE_NAME);
     $milestoneType->setModuleIdentifier(self::MODULE_IDENTIFIER);
     $milestoneType->setCampaign($campaign);
     $milestone = new Milestone();
     $milestone->setCampaign($campaign);
     $form = $this->createForm($milestoneType, $milestone);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         // Make sure that data stays intact by using transactions.
         try {
             $em->getConnection()->beginTransaction();
             $em->persist($milestone);
             // We need the milestone ID for storing the hooks. Hence we must flush here.
             $em->flush();
             $hookService = $this->get('campaignchain.core.hook');
             $milestone = $hookService->processHooks(self::BUNDLE_NAME, self::MODULE_IDENTIFIER, $milestone, $form, true);
             $em->flush();
             $em->getConnection()->commit();
         } catch (\Exception $e) {
             $em->getConnection()->rollback();
             throw $e;
         }
         $this->get('session')->getFlashBag()->add('success', 'Your new milestone <a href="' . $this->generateUrl('campaignchain_core_milestone_edit', array('id' => $milestone->getId())) . '">' . $milestone->getName() . '</a> was created successfully.');
         return $this->redirect($this->generateUrl('campaignchain_core_milestone'));
     }
     return $this->render('CampaignChainCoreBundle:Milestone:new.html.twig', array('page_title' => 'Create Scheduled Milestone', 'form' => $form->createView(), 'milestone' => $milestone));
     return $this->form($request, $milestone, 'Create New Milestone');
 }
コード例 #2
0
 public function moveMilestone(Milestone $milestone, $interval)
 {
     $hookService = $this->container->get($milestone->getTriggerHook()->getServices()['entity']);
     $hook = $hookService->getHook($milestone, Hook::MODE_MOVE);
     if ($hook->getStartDate() !== null) {
         $hook->setStartDate(new \DateTime($hook->getStartDate()->add($interval)->format(\DateTime::ISO8601)));
     }
     if ($hook->getEndDate() !== null) {
         $hook->setEndDate(new \DateTime($hook->getEndDate()->add($interval)->format(\DateTime::ISO8601)));
     }
     $milestone = $hookService->processHook($milestone, $hook);
     $this->em->persist($milestone);
     $this->em->flush();
     return $milestone;
 }