Example #1
0
 /**
  * Persists a vote.
  *
  * @param VoteInterface $vote
  * @param VotableCommentInterface $comment
  * @return void
  */
 public function addVote(VoteInterface $vote, VotableCommentInterface $comment)
 {
     $vote->setComment($comment);
     $comment->setScore($comment->getScore() + $vote->getValue());
     $this->dm->persist($comment);
     $this->dm->persist($vote);
     $this->dm->flush();
 }
 public function saveVote(VoteInterface $vote)
 {
     if (null === $vote->getComment()) {
         throw new \InvalidArgumentException('Vote passed into saveVote must have a comment');
     }
     $event = new VoteEvent($vote);
     $this->dispatcher->dispatch(Events::VOTE_PRE_PERSIST, $event);
     $this->doSaveVote($vote);
     $event = new VoteEvent($vote);
     $this->dispatcher->dispatch(Events::VOTE_POST_PERSIST, $event);
 }
 /**
  * Assigns the Security token's user to the vote.
  *
  * @throws InvalidArgumentException when the vote does not implement SignedVoteInterface
  * @throws RuntimeException When the firewall is not properly configured
  * @param VoteInterface $vote
  * @return void
  */
 public function blame(VoteInterface $vote)
 {
     if (!$vote instanceof SignedVoteInterface) {
         throw new InvalidArgumentException('The vote must implement SignedVoteInterface');
     }
     if (null === $this->securityContext->getToken()) {
         throw new RuntimeException('You must configure a firewall for this route');
     }
     if ($this->securityContext->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
         $vote->setVoter($this->securityContext->getToken()->getUser());
     }
 }
 /**
  * Persists a vote.
  *
  * @param \FOS\CommentBundle\Model\VoteInterface $vote
  */
 protected function doSaveVote(VoteInterface $vote)
 {
     $this->em->persist($vote->getComment());
     $this->em->persist($vote);
     $this->em->flush();
 }
 /**
  * {@inheritDoc}
  */
 public function saveVote(VoteInterface $vote)
 {
     if (!$this->voteAcl->canCreate()) {
         throw new AccessDeniedException();
     }
     if (!$this->commentAcl->canView($vote->getComment())) {
         throw new AccessDeniedException();
     }
     $this->realManager->saveVote($vote);
     $this->voteAcl->setDefaultAcl($vote);
 }