/**
  * 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);
 }
Ejemplo n.º 2
0
 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();
 }