public function publishPetitionToActivity(Petition $petition) { $expireDate = new \DateTime('now'); $expireDate->add(new \DateInterval('P' . $this->settings->get(Settings::DEFAULT_EXPIRE_INTERVAL)->getValue() . 'D')); $activity = new ActivityPetition(); $activity->setQuestionId($petition->getId())->setTitle($petition->getPetitionTitle())->setDescription($petition->getPetitionBody())->setExpireAt($expireDate)->setSentAt($petition->getPublishedAt()); $userMethod = 'set' . ucfirst($petition->getUser()->getType()); $activity->{$userMethod}($petition->getUser()); $this->setImage($activity, $petition); $this->cm->addPollRootComment($petition, $petition->getPetitionBody()); //send push notifications $this->pushSender->addToQueue('sendPushPublishQuestion', array($petition->getId(), "Sign: {$petition->getPetitionTitle()}")); $this->entityManager->persist($activity); $this->entityManager->flush(); $this->createActivityConditionsForQuestion($activity, $petition); }
/** * @Route("/delete/{id}", requirements={"id"="\d+"}) * @ParamConverter("petition", class="CivixCoreBundle:Poll\Question") */ public function deleteAction(Request $request, Petition $petition) { if ($petition->getUser() !== $this->getUser() || $petition->getPublishedAt() || $request->get('token') !== $this->getToken()) { throw new AccessDeniedHttpException(); } $manager = $this->getDoctrine()->getManager(); $manager->remove($petition); $manager->flush(); $this->get('session')->getFlashBag()->add('notice', 'The petition has been successfully removed'); return $this->redirect($this->generateUrl("civix_front_{$this->getUser()->getType()}_petition_index")); }