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