/**
  * @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);
 }
 /**
  * Symfony controller action for editing a CampaignChain Activity in a
  * pop-up window.
  *
  * @param Request $request
  * @param $id
  * @return Response
  * @throws \Exception
  */
 public function editModalAction(Request $request, $id)
 {
     $activityService = $this->get('campaignchain.core.activity');
     $this->activity = $activityService->getActivity($id);
     $this->location = $this->activity->getLocation();
     $this->campaign = $this->activity->getCampaign();
     if ($this->parameters['equals_operation']) {
         // Get the one operation.
         $this->operations[0] = $activityService->getOperation($id);
     } else {
         throw new \Exception('Multiple Operations for one Activity not implemented yet.');
     }
     $activityFormType = $this->getActivityFormType('editModal');
     $activityFormType->setView('default');
     $this->handler->preFormSubmitEditModalEvent($this->operations[0]);
     $form = $this->createForm($activityFormType, $this->activity);
     $form->handleRequest($request);
     /*
      * Define default rendering options and then apply those defined by the
      * module's handler if applicable.
      */
     $defaultRenderOptions = array('template' => 'CampaignChainCoreBundle:Base:new_modal.html.twig', 'vars' => array('page_title' => 'Edit Activity', 'form' => $form->createView()));
     $handlerRenderOptions = $this->handler->getEditModalRenderOptions($this->operations[0]);
     return $this->renderWithHandlerOptions($defaultRenderOptions, $handlerRenderOptions);
 }
 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();
 }
 public function connectByActivity(Activity $activity)
 {
     // Get Access Token and Token Secret
     $this->token = $this->tokenService->getToken($activity->getLocation());
     return $this->connect();
 }
 public function connectByActivity(Activity $activity)
 {
     return $this->connectByLocation($activity->getLocation());
 }
 /**
  * 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);
     }
 }