public function newAction(Request $request)
 {
     // create a campaign and give it some dummy data for this example
     $campaign = new Campaign();
     $campaign->setTimezone($this->get('session')->get('campaignchain.timezone'));
     $campaign->setStatus(Action::STATUS_PAUSED);
     // A campaign template does not have absolute dates.
     $campaign->setHasRelativeDates(true);
     // All campaign templates start Jan 1st, 2012 midnight.
     $campaign->setStartDate(new \DateTime(Campaign::RELATIVE_START_DATE));
     $campaignType = $this->getCampaignType();
     $form = $this->createForm($campaignType, $campaign);
     $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($campaign);
             // We need the campaign ID for storing the hooks. Hence we must flush here.
             $em->flush();
             $hookService = $this->get('campaignchain.core.hook');
             $campaign = $hookService->processHooks(static::BUNDLE_NAME, static::MODULE_IDENTIFIER, $campaign, $form, true);
             $hookService = $this->get('campaignchain.core.hook');
             $campaign->setTriggerHook($hookService->getHook(static::TRIGGER_HOOK));
             $em->flush();
             $em->getConnection()->commit();
         } catch (\Exception $e) {
             $em->getConnection()->rollback();
             throw $e;
         }
         $this->addFlash('success', 'Your new campaign template <a href="' . $this->generateUrl('campaignchain_campaign_template_edit', array('id' => $campaign->getId())) . '">' . $campaign->getName() . '</a> was created successfully.');
         if ($this->getRequest()->isXmlHttpRequest()) {
             return new JsonResponse(array('step' => 2));
         } else {
             return $this->redirectToRoute('campaignchain_core_plan_campaigns');
         }
     }
     return $this->render($this->getRequest()->isXmlHttpRequest() ? 'CampaignChainCoreBundle:Base:new_modal.html.twig' : 'CampaignChainCoreBundle:Base:new.html.twig', array('page_title' => 'New ' . static::CAMPAIGN_DISPLAY_NAME, 'form' => $form->createView(), 'form_submit_label' => 'Save'));
 }
 public function newAction(Request $request)
 {
     // create a campaign and give it some dummy data for this example
     $campaign = new Campaign();
     $campaign->setTimezone($this->get('session')->get('campaignchain.timezone'));
     $dateTimeZone = new \DateTimeZone($this->get('session')->get('campaignchain.timezone'));
     $now = new \DateTime('now', $dateTimeZone);
     $campaign->setStartDate($now);
     $campaign->setEndDate($now->modify('+1 day'));
     $campaignType = $this->getCampaignType();
     $form = $this->createForm($campaignType, $campaign);
     $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($campaign);
             // We need the campaign ID for storing the hooks. Hence we must flush here.
             $em->flush();
             $hookService = $this->get('campaignchain.core.hook');
             $campaign = $hookService->processHooks(self::BUNDLE_NAME, self::MODULE_IDENTIFIER, $campaign, $form, true);
             $em->flush();
             $em->getConnection()->commit();
         } catch (\Exception $e) {
             $em->getConnection()->rollback();
             throw $e;
         }
         $this->addFlash('success', 'Your new campaign <a href="' . $this->generateUrl('campaignchain_core_campaign_edit', array('id' => $campaign->getId())) . '">' . $campaign->getName() . '</a> was created successfully.');
         if ($this->getRequest()->isXmlHttpRequest()) {
             return new JsonResponse(array('step' => 2));
         } else {
             return $this->redirectToRoute('campaignchain_core_plan_campaigns');
         }
     }
     return $this->render($this->getRequest()->isXmlHttpRequest() ? 'CampaignChainCoreBundle:Base:new_modal.html.twig' : 'CampaignChainCoreBundle:Base:new.html.twig', array('page_title' => 'Create New Scheduled Campaign', 'form' => $form->createView()));
 }