コード例 #1
0
 public function setVisibleAnswersForRecipent(Answer $answer)
 {
     /**
      * @var \Civix\CoreBundle\Entity\Poll\Question $question
      */
     $question = $answer->getQuestion();
     if ($question instanceof \Civix\CoreBundle\Entity\Poll\Question) {
         $specRepresentative = $question->getReportRecipient();
         $offTitleGroup = $question->getReportRecipientGroup();
         //Add specific representative to recipients of this question
         if (isset($specRepresentative)) {
             $question->addRecipient($specRepresentative);
         } elseif (isset($offTitleGroup)) {
             //check if user has representative with recient official title
             $districts = $answer->getUser()->getDistrictsIds();
             //check if user has districts (fill profile info)
             if (!empty($districts)) {
                 $representatives = $this->entityManager->getRepository('CivixCoreBundle:Representative')->getReprByDistrictsAndOffTitle($districts, $offTitleGroup);
                 //check if base has representatives with selected official title and districts
                 if ($representatives) {
                     foreach ($representatives as $recipient) {
                         if ($question->getUser() != $recipient) {
                             $question->addRecipient($recipient);
                         }
                     }
                 }
             }
         }
         $this->entityManager->persist($question);
         $this->entityManager->flush();
     }
 }
コード例 #2
0
 public function addCommentByQuestionAnswer(Answer $answer)
 {
     $parent = $this->em->getRepository('CivixCoreBundle:Poll\\Comment')->findOneBy(array('question' => $answer->getQuestion(), 'parentComment' => null));
     if ($answer->getComment()) {
         $comment = new Comment();
         $comment->setUser($answer->getUser())->setCommentBody($answer->getComment())->setQuestion($answer->getQuestion())->setPrivacy($answer->getPrivacy())->setParentComment($parent);
         return $this->saveNewComment($comment);
     }
 }
コード例 #3
0
 public function noticeAnsweredToQuestion(Answer $answer)
 {
     $question = $answer->getQuestion();
     if (!$question->getUser() instanceof Group) {
         return;
     }
     $target = ['id' => $question->getId(), 'type' => $question->getType()];
     $target['label'] = $this->getLabelByPoll($question);
     $target['preview'] = $this->getPreviewByPoll($question);
     $socialActivity = (new SocialActivity(SocialActivity::TYPE_ANSWERED, $answer->getUser(), $answer->getQuestion()->getUser()))->setTarget($target);
     $this->em->persist($socialActivity);
     $this->em->flush($socialActivity);
     return $socialActivity;
 }
 public function getUser()
 {
     $this->__load();
     return parent::getUser();
 }
コード例 #5
0
 /**
  * @Route("/answers/{id}/charges/")
  * @Method("GET")
  */
 public function charges(Answer $answer)
 {
     if ($answer->getUser() !== $this->getUser()) {
         throw $this->createNotFoundException();
     }
     $customer = $this->getDoctrine()->getRepository(Customer::getEntityClassByUser($this->getUser()))->findOneBy(['user' => $this->getUser()]);
     if (!$customer) {
         throw $this->createNotFoundException();
     }
     $charge = $this->getDoctrine()->getRepository(Charge::class)->findOneBy(['questionId' => $answer->getQuestion()->getId(), 'fromCustomer' => $customer]);
     return $this->createJSONResponse($this->jmsSerialization($charge->toArray(), ['api-answer-private']));
 }