Пример #1
0
 /**
  * Perform database operations for voting
  *
  * @param Comment $comment
  * @param int $type Check out Tx_PwComments_Domain_Model_Vote constants
  * @return void
  */
 protected function performVoting(Comment $comment, $type)
 {
     $commentAnchor = '#' . $this->settings['commentAnchorPrefix'] . $comment->getUid();
     if (!$this->settings['enableVoting']) {
         $this->redirectToURI($this->buildUriToPage($this->pageUid, array('votingDisabled' => 1)) . $commentAnchor);
         return;
     }
     $this->createAuthorIdent();
     $vote = NULL;
     if ($this->currentAuthorIdent !== NULL) {
         if ($this->settings['ignoreVotingForOwnComments'] && $this->currentAuthorIdent == $comment->getAuthorIdent()) {
             $this->redirectToURI($this->buildUriToPage($this->pageUid, array('doNotVoteForYourself' => 1)) . $commentAnchor);
             return;
         }
         $vote = $this->voteRepository->findOneByCommentAndAuthorIdent($comment, $this->currentAuthorIdent);
     }
     if ($vote === NULL) {
         $comment->addVote($this->createNewVote($type, $comment));
         $this->commentRepository->update($comment);
     } else {
         $comment->removeVote($vote);
         $this->commentRepository->update($comment);
         $this->voteRepository->remove($vote);
         if ($type !== $vote->getType()) {
             $this->getPersistenceManager()->persistAll();
             $this->performVoting($comment, $type);
         }
     }
     $this->getPersistenceManager()->persistAll();
     $this->redirectToURI($this->buildUriToPage($this->pageUid) . $commentAnchor);
 }
Пример #2
0
 /**
  * Validator to check that message has been set
  *
  * @param Comment $comment Comment model to validate
  * @return bool
  */
 protected function messageIsSet(Comment $comment)
 {
     return trim($comment->getMessage());
 }
Пример #3
0
 /**
  * Find replies by given comment and attaches them to replies attribute.
  *
  * @param Comment $comment
  * @return void
  */
 protected function findAndAttachCommentReplies(Comment $comment)
 {
     $query = $this->createQuery();
     $query->matching($query->equals('parentComment', $comment->getUid()));
     $query->setOrderings(array('crdate' => $this->getReplySortingDirection()));
     $comment->setReplies($query->execute());
 }