/**
  * Symfony controller action for creating a new CampaignChain Activity.
  *
  * @param Request $request
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
  * @throws \Exception
  */
 public function newAction(Request $request)
 {
     $operation = null;
     /*
      * Set Activity's context from user's choice.
      */
     $wizard = $this->get('campaignchain.core.activity.wizard');
     if (!$wizard->getCampaign()) {
         return $this->redirectToRoute('campaignchain_core_activities_new');
     }
     $campaignService = $this->get('campaignchain.core.campaign');
     $campaign = $campaignService->getCampaign($wizard->getCampaign());
     $locationService = $this->get('campaignchain.core.location');
     if ($wizard->getLocation()) {
         $location = $locationService->getLocation($wizard->getLocation());
     } else {
         $location = null;
     }
     $this->setActivityContext($campaign, $location);
     /** @var Activity $activity */
     $activity = $wizard->getActivity();
     $activity->setActivityModule($wizard->getActivityModule());
     $activity->setEqualsOperation($this->parameters['equals_operation']);
     $form = $this->createForm($this->getActivityFormType('new'), $activity);
     $form->handleRequest($request);
     if ($form->isValid()) {
         $activity = $wizard->end();
         try {
             $activity = $this->createActivity($activity, $form);
             $this->addFlash('success', 'Your new activity <a href="' . $this->generateUrl('campaignchain_core_activity_edit', array('id' => $activity->getId())) . '">' . $activity->getName() . '</a> was created successfully.');
             return $this->redirect($this->generateUrl('campaignchain_core_activities'));
         } catch (\Exception $e) {
             $this->addFlash('warning', $e->getMessage());
             $this->getLogger()->error($e->getMessage(), array('file' => $e->getFile(), 'line' => $e->getLine(), 'trace' => $e->getTrace()));
         }
     }
     if ($location) {
         $channelModule = $wizard->getChannelModule();
         $channelModuleBundle = $wizard->getChannelModuleBundle();
     } else {
         $channelModule = null;
         $channelModuleBundle = null;
     }
     /*
      * Define default rendering options and then apply those defined by the
      * module's handler if applicable.
      */
     $defaultRenderOptions = array('template' => 'CampaignChainCoreBundle:Operation:new.html.twig', 'vars' => array('page_title' => 'New Activity', 'activity' => $activity, 'campaign' => $this->campaign, 'campaign_module' => $this->campaign->getCampaignModule(), 'channel_module' => $channelModule, 'channel_module_bundle' => $channelModuleBundle, 'location' => $this->location, 'form' => $form->createView(), 'form_submit_label' => 'Save', 'form_cancel_route' => 'campaignchain_core_activities_new'));
     $handlerRenderOptions = $this->handler->getNewRenderOptions();
     return $this->renderWithHandlerOptions($defaultRenderOptions, $handlerRenderOptions);
 }
 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()));
 }
 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'));
 }
Beispiel #4
0
 public function getCampaignWithChildren(Campaign $campaign)
 {
     $data['type'] = 'campaign';
     $data['campaignchain_id'] = (string) $campaign->getId();
     $data['text'] = $campaign->getName();
     $data['route_edit_api'] = $campaign->getCampaignModule()->getRoutes()['edit_api'];
     $data['route_plan_detail'] = $campaign->getCampaignModule()->getRoutes()['plan_detail'];
     $campaignService = $this->container->get('campaignchain.core.campaign');
     $data['tpl_teaser'] = $campaignService->tplTeaser($campaign->getCampaignModule(), array('only_icon' => true, 'size' => 24));
     // Define the trigger hook's identifier.
     if (!$campaign->getInterval() && $campaign->getTriggerHook()) {
         $data['id'] = (string) $campaign->getId() . '_campaign';
         $hookService = $this->container->get($campaign->getTriggerHook()->getServices()['entity']);
         $hook = $hookService->getHook($campaign);
         $data['start_date'] = $hook->getStartDate()->format(self::FORMAT_TIMELINE_DATE);
         if ($hook->getEndDate()) {
             $data['end_date'] = $hook->getEndDate()->format(self::FORMAT_TIMELINE_DATE);
         } else {
             $data['end_date'] = $data['start_date'];
         }
         $ganttCampaignData[] = $data;
     } elseif ($campaign->getInterval()) {
         // Handle repeating campaigns.
         if (!$campaign->getIntervalEndOccurrence()) {
             $occurrences = 1;
         } else {
             $occurrences = $campaign->getIntervalEndOccurrence();
         }
         /** @var \DateTime $startDate */
         $startDate = $campaign->getIntervalStartDate();
         /** @var \DateInterval $duration */
         $duration = $campaign->getStartDate()->diff($campaign->getEndDate());
         $now = new \DateTime('now');
         $maxTimelineDate = clone $now;
         $maxTimelineDate->modify($this->container->getParameter('campaignchain.max_date_interval'));
         $firstInstanceId = null;
         $repeatingCount = 0;
         // If an actual instance exists as a child campaign, then add it.
         /** @var Campaign $childCampaign */
         $childCampaign = $this->em->getRepository('CampaignChain\\CoreBundle\\Entity\\Campaign')->findOneByParent($campaign);
         if ($childCampaign) {
             $firstInstanceId = $data['id'] = (string) $campaign->getId() . '_campaign';
             $data['start_date'] = $childCampaign->getStartDate()->format(self::FORMAT_TIMELINE_DATE);
             $data['end_date'] = $childCampaign->getEndDate()->format(self::FORMAT_TIMELINE_DATE);
             $ganttCampaignData[] = $data;
         }
         /*
          * Let's iterate through all the future instances of a repeating
          * campaign.
          */
         for ($i = 0; $i < $occurrences; $i++) {
             /*
              * Take the interval's start/end date for the first instance,
              * otherwise calculate the start/end date by adding the
              * campaign's interval to the start/end date of the
              * previous instance.
              */
             $startDate->modify($campaign->getInterval());
             $endDate = clone $startDate;
             $endDate->add($duration);
             $hasEnded = $campaign->getIntervalEndDate() != NULL && $endDate > $campaign->getIntervalEndDate();
             /*
              * If the instance is in the past, skip it,
              * because we only want ongoing or upcoming ones.
              */
             if (!$hasEnded && $startDate >= $campaign->getIntervalNextRun() && ($startDate > $now || $endDate > $now)) {
                 /*
                  * Is this the first repeating campaign instance?
                  */
                 if (!$firstInstanceId) {
                     /*
                      * This is the first instance, so we define it as
                      * the parent of the other repeating campaign
                      * instances.
                      */
                     $firstInstanceId = $data['id'] = (string) $campaign->getId() . '_campaign';
                 } else {
                     /*
                      * This is not the first instance of a repeating
                      * campaign in the timeline, so let's add the first instance
                      * as the parent campaign.
                      */
                     $data['id'] = (string) $campaign->getId() . '_' . $repeatingCount . '_campaign';
                     $data['parent'] = $firstInstanceId;
                     $repeatingCount++;
                 }
                 $data['start_date'] = $startDate->format(self::FORMAT_TIMELINE_DATE);
                 $data['interval'] = $campaign->getIntervalHumanReadable();
                 $data['end_date'] = $endDate->format(self::FORMAT_TIMELINE_DATE);
                 $ganttCampaignData[] = $data;
             }
             if ($campaign->getIntervalEndOccurrence() == NULL && (!$hasEnded && $startDate < $maxTimelineDate)) {
                 $occurrences++;
             }
         }
     } else {
         throw new \Exception('Unknown campaign type.');
     }
     return $ganttCampaignData;
 }
Beispiel #5
0
 public function getCampaignURI(Campaign $campaign)
 {
     $bundleName = $campaign->getCampaignModule()->getBundle()->getName();
     $moduleIdentifier = $campaign->getCampaignModule()->getIdentifier();
     return $bundleName . '/' . $moduleIdentifier;
 }
 /**
  * Get facts data per dimension.
  *
  * @param Campaign $campaign
  * @param Activity $activity
  * @param boolean  $percent
  *
  * @return array
  */
 public function getFacts(Campaign $campaign, Activity $activity, $percent = false)
 {
     $qb = $this->em->createQueryBuilder();
     $qb->select('r.time, r.value, IDENTITY(r.metric) as metric')->from('CampaignChain\\CoreBundle\\Entity\\ReportAnalyticsActivityFact', 'r')->where('r.activity = :activityId')->andWhere('r.campaign = :campaignId')->orderBy('r.time', 'ASC')->setParameter('activityId', $activity->getId())->setParameter('campaignId', $campaign->getId());
     $query = $qb->getQuery();
     $facts = $query->getArrayResult();
     $factsData = [];
     $tmp = [];
     foreach ($facts as $fact) {
         $tmp[$fact['metric']][] = [$fact['time']->getTimestamp() * 1000, $fact['value']];
     }
     foreach (array_keys($tmp) as $k) {
         $factsData[$k]['data'] = $this->serializer->serialize($tmp[$k], 'json');
         $factsData[$k]['id'] = $k;
         if ($percent) {
             $factsData[$k]['percent'] = $this->getDimensionPercent($campaign, $activity, $k);
         }
     }
     return $factsData;
 }
 private function setModuleAndHook(Campaign $repeatingCampaign)
 {
     $moduleService = $this->container->get('campaignchain.core.module');
     $module = $moduleService->getModule(static::BUNDLE_NAME, static::MODULE_IDENTIFIER);
     $repeatingCampaign->setCampaignModule($module);
     $hookService = $this->container->get('campaignchain.core.hook');
     $repeatingCampaign->setTriggerHook($hookService->getHook('campaignchain-date-repeat'));
     return $repeatingCampaign;
 }