public function setPaymentAmount($payment_amount) { $this->__load(); return parent::setPaymentAmount($payment_amount); }
/** * Add new Answer * * @Route("/question/{question_id}/answer/add", requirements={"question_id"="\d+"}, name="api_answer_add") * @Method("POST") */ public function answerAddAction(Request $request) { $entityManager = $this->getDoctrine()->getManager(); $dispatcher = $this->get('event_dispatcher'); /** @var $user User */ $user = $this->getUser(); /** @var $question Question */ $question = $entityManager->getRepository('CivixCoreBundle:Poll\\Question')->find($request->get('question_id')); if (is_null($question)) { throw new BadRequestHttpException('Question not found'); } /** @var $option Option */ $option = $entityManager->getRepository('CivixCoreBundle:Poll\\Option')->find($request->get('option_id')); if (is_null($option) || $option->getQuestion()->getId() !== $question->getId()) { throw new BadRequestHttpException('Wrong option ID'); } $isCanAnswer = $this->get('civix_core.poll.answer_manager')->checkAccessAnswer($user, $question); if (!$isCanAnswer) { throw new AccessDeniedHttpException(); } /** @var $answer Answer */ $answer = $entityManager->getRepository('CivixCoreBundle:Poll\\Answer')->findOneBy(array('option' => $option, 'user' => $user)); if (!is_null($answer)) { throw new BadRequestHttpException('User is already answered this question'); } $answer = new Answer(); $answer->setQuestion($question); $answer->setOption($option); $answer->setUser($user); $answer->setComment($request->get('comment')); $answer->setPrivacy($request->get('privacy')); $answer->setPaymentAmount($request->get('payment_amount')); $errors = $this->getValidator()->validate($answer, array('api-poll')); $response = new Response(); $response->headers->set('Content-Type', 'application/json'); if (count($errors) > 0) { $response->setStatusCode(400)->setContent(json_encode(array('errors' => $this->transformErrors($errors)))); } else { if ($question instanceof PaymentRequest && !$question->getIsCrowdfunding() && $answer->getCurrentPaymentAmount()) { $this->get('civix_core.stripe')->chargeToPaymentRequest($question, $answer, $user); } $entityManager->persist($answer); $entityManager->flush(); if ($question instanceof PaymentRequest && $question->getIsCrowdfunding() && $answer->getCurrentPaymentAmount()) { $entityManager->getRepository(PaymentRequest::class)->updateCrowdfundingPledgedAmount($answer); } //update activity responses $this->get('civix_core.activity_update')->updateResponsesQuestion($question); $this->get('civix_core.poll.answer_manager')->setVisibleAnswersForRecipent($answer); $this->get('civix_core.poll.comment_manager')->addCommentByQuestionAnswer($answer); $this->get('civix_core.social_activity_manager')->noticeAnsweredToQuestion($answer); $response->setContent($this->jmsSerialization($answer, array('api-answers-list'))); } return $response; }