/** * @Route("/petitions/buy-outsiders/{petition}") * @ParamConverter( * "petition", * class="CivixCoreBundle:Poll\Question\Petition" * ) * @Template("CivixFrontBundle:Payment:form.html.twig") */ public function buyPublicPetitionAction(Request $request, Petition $petition) { if ($petition->getUser() !== $this->getUser()) { throw new AccessDeniedHttpException(); } $card = new CardModel(); $form = $this->createForm(new CardFormType(), $card); //get marketplace $marketplaceToken = $this->get('civix_core.payments')->getMarketPlaceToken(); if ('POST' === $request->getMethod()) { if ($form->submit($request)->isValid()) { try { $customer = $this->get('civix_core.customer_manager')->getCustomerByUser($this->getUser()); $this->get('civix_core.payments')->buyPublishOutsiderPetition($card, $customer); $petition->setPublishedAt(new \DateTime()); $this->getDoctrine()->getManager()->flush($petition); $this->get('civix_core.activity_update')->publishPetitionToActivity($petition); $this->get('session')->getFlashBag()->add('notice', 'The petition has been successfully published'); return $this->redirect($this->generateUrl("civix_front_{$this->getUser()->getType()}_petition_index")); } catch (\Balanced\Errors\DuplicateAccountEmailAddress $ex) { $this->get('session')->getFlashBag()->add('error', 'User with this email exist in balanced system.'); } catch (\Balanced\Errors\Declined $ex) { $this->get('session')->getFlashBag()->add('error', 'The processor declined the debit. ' . $ex->description); } catch (\Balanced\Errors\NoFundingSource $ex) { $this->get('session')->getFlashBag()->add('error', 'The buyer has not active funding sources. ' . $ex->description); } catch (\Balanced\Errors\CannotDebit $ex) { $this->get('session')->getFlashBag()->add('error', 'The buyer has no debitable funding sources. ' . $ex->description); } catch (\Balanced\Errors\Error $ex) { $this->get('session')->getFlashBag()->add('error', $ex->description); } } } return array('formTitle' => '', 'marketplaceToken' => $marketplaceToken, 'petition' => $petition->getId(), 'form' => $form->createView()); }
/** * @Route("/invite/{id}", requirements={"id"="\d+"}) * @Template("CivixFrontBundle:Petition:invite.html.twig") * @ParamConverter( * "petition", * class="CivixCoreBundle:Poll\Question\Petition", * options={"repository_method" = "getPublishPetitonById"} * ) */ public function inviteAction(Request $request, Petition $petition) { $group = $this->getUser(); if ($petition->getUser() !== $group || $request->get('token') !== $this->getToken()) { throw new AccessDeniedHttpException(); } $answers = $this->getDoctrine()->getManager()->getRepository('CivixCoreBundle:Poll\\Question\\Petition')->getSignedUsersNotInGroup($petition, $group); if (!empty($answers)) { $package = $this->get('civix_core.subscription_manager')->getPackage($this->getUser()); $packageInviteAmount = $package->getSumForPetitionInvites(); if (0 < $packageInviteAmount) { /* @var Customer $customer */ $customer = $this->get('civix_core.customer_manager')->getCustomerByUser($this->getUser()); /* @var Card $card */ $card = $this->getDoctrine()->getRepository(Card::class)->findOneByCustomer($customer); if (!$card) { return $this->redirect($this->generateUrl('civix_front_' . $this->getUser()->getType() . '_paymentsettings_createcard', ['return_path' => $this->generateUrl('civix_front_' . $this->getUser()->getType() . '_invite', ['id' => $petition->getId()])])); } $form = $this->createForm('form'); if ('POST' === $request->getMethod() && $form->submit($request)->isValid()) { $paymentHistory = $this->get('civix_core.payments')->buyPetitionsInvites($card, $customer, $packageInviteAmount * 100); if (!$paymentHistory->isSucceeded()) { return $this->redirect($this->generateUrl("civix_front_{$this->getUser()->getType()}_invite", ['id' => $petition->getId()])); } } else { return ['card' => $card, 'price' => $packageInviteAmount, 'form' => $form->createView()]; } } $this->get('civix_core.invite_sender')->sendInviteForPetition($answers, $group); $this->getDoctrine()->getManager()->persist($group); $this->getDoctrine()->getManager()->flush(); $this->get('session')->getFlashBag()->add('notice', 'Invites have been sent'); } else { $this->get('session')->getFlashBag()->add('error', 'Signed users have not been found'); } return $this->redirect($this->generateUrl("civix_front_{$this->getUser()->getType()}_petition_index")); }
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")); }