/**
  * @param Activity $activity
  *
  * @return LinkedInClientService
  */
 public function getConnectionByActivity(Activity $activity)
 {
     $application = $this->oauthApp->getApplication(self::RESOURCE_OWNER);
     $token = $this->oauthToken->getToken($activity->getLocation());
     $connection = $this->connect($application->getKey(), $application->getSecret(), $token->getAccessToken(), $token->getTokenSecret());
     return new LinkedInClientService($connection);
 }
 public function getClosestScheduledActivity(Activity $activity, $interval)
 {
     $startInterval = clone $activity->getStartDate();
     $startInterval->modify($interval);
     $qb = $this->createQueryBuilder('a');
     $qb->select('a');
     if (substr($interval, 0, 1) == "-") {
         $qb->where('a.startDate < :startDate')->andWhere('a.startDate > :startInterval');
     } else {
         $qb->where('a.startDate > :startDate')->andWhere('a.startDate < :startInterval');
     }
     $qb->setParameter('startInterval', $startInterval)->andWhere('a.location = :location')->andWhere('a.campaign = :campaign')->andWhere('a.status != :closed')->setParameter('startDate', $activity->getStartDate())->setParameter('location', $activity->getLocation())->setParameter('campaign', $activity->getCampaign())->setParameter('closed', Action::STATUS_CLOSED)->orderBy('a.startDate', 'DESC')->setMaxResults(1);
     $query = $qb->getQuery();
     return $query->getOneOrNullResult();
 }
 /**
  * Symfony controller action that takes the data posted by the editModalAction
  * and persists it.
  *
  * @param Request $request
  * @param $id
  * @return Response
  * @throws \Exception
  */
 public function editApiAction(Request $request, $id)
 {
     $responseData = array();
     $data = $request->get('campaignchain_core_activity');
     $activityService = $this->get('campaignchain.core.activity');
     $this->activity = $activityService->getActivity($id);
     $this->activity->setName($data['name']);
     if ($this->parameters['equals_operation']) {
         /** @var Operation $operation */
         $operation = $activityService->getOperation($id);
         // The activity equals the operation. Thus, we update the operation
         // with the same data.
         $operation->setName($data['name']);
         $this->operations[0] = $operation;
         if ($this->handler->hasContent('editModal')) {
             $content = $this->handler->processContent($this->operations[0], $data[$this->contentModuleFormName]);
         }
     } else {
         throw new \Exception('Multiple Operations for one Activity not implemented yet.');
     }
     $em = $this->getDoctrine()->getManager();
     $em->persist($this->activity);
     $em->persist($this->operations[0]);
     if ($this->handler->hasContent('editModal')) {
         $em->persist($content);
     }
     $hookService = $this->get('campaignchain.core.hook');
     $this->activity = $hookService->processHooks($this->parameters['bundle_name'], $this->parameters['module_identifier'], $this->activity, $data);
     $em->flush();
     $responseData['start_date'] = $responseData['end_date'] = $this->activity->getStartDate()->format(\DateTime::ISO8601);
     $serializer = $this->get('campaignchain.core.serializer.default');
     return new Response($serializer->serialize($responseData, 'json'));
 }
 public function processActivity(Activity $activity, $data)
 {
     $sid = $data['slideshow'];
     $title = $this->availableSlideshows[$sid]['title'];
     $activity->setName($title);
     return $activity;
 }
 public function processActivity(Activity $activity, $data)
 {
     $remoteNewsletter = $this->getRemoteNewsletter($data);
     $activity->setName($remoteNewsletter['title']);
     return $activity;
 }
 public function processActivity(Activity $activity, $data)
 {
     $activity->setName($this->remoteWebinar['subject']);
     $webinarStartDate = new \DateTime($this->remoteWebinar['times'][0]['startTime']);
     $activity->setStartDate($webinarStartDate);
     $webinarEndDate = new \DateTime($this->remoteWebinar['times'][0]['endTime']);
     $activity->setEndDate($webinarEndDate);
     $triggerHook = $this->hookService->getHook(self::TRIGGER_HOOK_IDENTIFIER);
     $activity->setTriggerHook($triggerHook);
     return $activity;
 }
 public function connectByActivity(Activity $activity)
 {
     // Get Access Token and Token Secret
     $this->token = $this->tokenService->getToken($activity->getLocation());
     return $this->connect();
 }
 public function newOperationByActivity(Activity $activity, $bundleName, $moduleIdentifier)
 {
     $operationModule = $this->getOperationModule($bundleName, $moduleIdentifier);
     $operation = new Operation();
     $operation->setName($activity->getName());
     $operation->setStartDate($activity->getStartDate());
     $operation->setEndDate($activity->getEndDate());
     $operation->setTriggerHook($activity->getTriggerHook());
     $operation->setActivity($activity);
     $activity->addOperation($operation);
     $operationModule->addOperation($operation);
     $operation->setOperationModule($operationModule);
     return $operation;
 }
 /**
  * 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;
 }
 public function connectByActivity(Activity $activity)
 {
     return $this->connectByLocation($activity->getLocation());
 }
Beispiel #11
0
 public function cloneActivity(Campaign $campaign, Activity $activity, $status = null)
 {
     /** @var Activity $clonedActivity */
     $clonedActivity = clone $activity;
     $clonedActivity->setCampaign($campaign);
     $campaign->addActivity($clonedActivity);
     if ($status != null) {
         $clonedActivity->setStatus($status);
     }
     $this->em->persist($clonedActivity);
     // Clone all related Operations.
     $operations = $activity->getOperations();
     if ($operations->count()) {
         $operationService = $this->container->get('campaignchain.core.operation');
         foreach ($operations as $operation) {
             $operationService->cloneOperation($activity, $operation);
         }
     }
     $this->em->flush();
     return $clonedActivity;
 }
 /**
  * Get a company update statistics
  *
  * @param Activity $activity
  * @param NewsItem $newsItem
  * @return array
  */
 public function getCompanyUpdate(Activity $activity, NewsItem $newsItem)
 {
     $id = $activity->getLocation()->getIdentifier();
     $request = $this->connect->get('companies/' . $id . '/updates/key=' . $newsItem->getUpdateKey(), [], ['query' => ['format' => 'json']]);
     try {
         return $request->send()->json();
     } catch (\Exception $e) {
         throw new ExternalApiException($e->getMessage(), $e->getCode(), $e);
     }
 }
 /**
  * Compares the status message of an already scheduled Activity with the
  * content of a new/edited Activity.
  *
  * @param Activity $existingActivity
  * @param StatusBase $content
  * @return array
  */
 protected function isUniqueContent(Activity $existingActivity, StatusBase $content)
 {
     /** @var StatusBase $existingStatus */
     $existingStatus = $this->em->getRepository('CampaignChainOperationFacebookBundle:StatusBase')->findOneByOperation($existingActivity->getOperations()[0]);
     if ($existingStatus->getMessage() == $content->getMessage()) {
         return array('status' => false, 'message' => 'Same status message has already been scheduled: ' . '<a href="' . $this->router->generate('campaignchain_activity_facebook_publish_status_edit', array('id' => $existingActivity->getId())) . '">' . $existingActivity->getName() . '</a>. ' . 'Either change the message or leave at least ' . $this->maxDuplicateInterval . ' between yours and the other post.');
     } else {
         return array('status' => true);
     }
 }
Beispiel #14
0
 public function getNewActivity()
 {
     // Reset memory of pre-selected campaign.
     $this->container->get('session')->set('campaignchain.campaign', null);
     // Merge context with persistence manager.
     $repository = $this->container->get('doctrine')->getManager();
     $this->session->resume();
     $campaign = $this->session->get('campaignchain_campaign');
     $campaign = $repository->merge($campaign);
     $activityModule = $this->session->get('campaignchain_activityModule');
     $activityModule = $repository->merge($activityModule);
     // Create new Activity.
     $activity = new Activity();
     $activity->setActivityModule($activityModule);
     $activity->setCampaign($campaign);
     if ($this->session->has('campaignchain_location')) {
         $location = $this->session->get('campaignchain_location');
         $location = $repository->getRepository('CampaignChainCoreBundle:Location')->find($location);
         //$location = $repository->merge($location);
         $activity->setLocation($location);
         $activity->setChannel($location->getChannel());
     }
     return $activity;
 }