public function getUser()
 {
     $this->__load();
     return parent::getUser();
 }
コード例 #2
0
 public function noticeCommentMentioned(BaseComment $comment, $recipients)
 {
     $group = null;
     if ($comment instanceof MicropetitionComment) {
         $micropetition = $comment->getPetition();
         $group = $micropetition->getGroup();
         $target = ['id' => $micropetition->getId(), 'preview' => $this->preparePreview($comment->getCommentBody()), 'type' => $micropetition->getType(), 'label' => $micropetition->getType() === $micropetition::TYPE_QUORUM ? 'post' : 'petition'];
     } else {
         if ($comment instanceof Comment) {
             $question = $comment->getQuestion();
             $target = ['id' => $question->getId(), 'type' => $question->getType()];
             $target['label'] = $this->getLabelByPoll($question);
             $group = $question->getUser();
         }
     }
     if ($comment->getParentComment()->getUser()) {
         $target['comment_id'] = $comment->getId();
     }
     $user = $comment->getUser();
     $target['user_id'] = $user->getId();
     $target['first_name'] = $user->getFirstName();
     $target['last_name'] = $user->getLastName();
     foreach ($recipients as $recipient) {
         if ($group instanceof Group && $this->em->getRepository(UserGroup::class)->isJoinedUser($group, $recipient)) {
             $socialActivity = (new SocialActivity(SocialActivity::TYPE_COMMENT_MENTIONED, null, $group))->setTarget($target)->setRecipient($recipient);
             $this->em->persist($socialActivity);
             $this->em->flush($socialActivity);
             $this->pt->addToQueue('sendSocialActivity', [$socialActivity->getId()]);
         } else {
             if ($this->em->getRepository(UserFollow::class)->findActiveFollower($user, $recipient)) {
                 $socialActivity = (new SocialActivity(SocialActivity::TYPE_COMMENT_MENTIONED, $user, null))->setTarget($target)->setRecipient($recipient);
                 $this->em->persist($socialActivity);
                 $this->em->flush($socialActivity);
                 $this->pt->addToQueue('sendSocialActivity', [$socialActivity->getId()]);
             }
         }
     }
 }
コード例 #3
0
 /**
  * Add rate to comment
  * @Route(
  *      "/comments/rate/{id}/{action}",
  *      requirements={"id"="\d+", "action"="up|down|delete"},
  *      name="api_question_rate_comment"
  * )
  * @ParamConverter("comment", class="CivixCoreBundle:BaseComment")
  * @Method("POST")
  * @ApiDoc(
  *     resource=true,
  *     description="Add rate to comment",
  *     statusCodes={
  *         200="Returns comment with new rate",
  *         401="Authorization required",
  *         405="Method Not Allowed"
  *     }
  * ) 
  */
 public function rateCommentAction(\Civix\CoreBundle\Entity\BaseComment $comment, $action)
 {
     $user = $this->getUser();
     $rateActionConstant = 'Civix\\CoreBundle\\Entity\\Poll\\CommentRate::RATE_' . strtoupper($action);
     if ($comment->getUser() == $user) {
         throw new BadRequestHttpException('You can\'t rate your comment');
     }
     $comment = $this->get('civix_core.poll.comment_manager')->updateRateToComment($comment, $user, constant($rateActionConstant));
     if ($comment instanceof \Civix\CoreBundle\Entity\Poll\Comment && !$comment->getParentComment() && $comment->getQuestion() instanceof \Civix\CoreBundle\Entity\Poll\Question\LeaderNews) {
         $this->get('civix_core.activity_update')->updateEntityRateCount($comment);
     }
     $response = new Response($this->jmsSerialization($comment, array('api-comments', 'api-comments-parent')));
     return $response;
 }