Created
February 12, 2013 23:31
-
-
Save umpirsky/4774504 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ThreadCountersListener implements EventSubscriberInterface | |
{ | |
protected $commentManager; | |
public function __construct(CommentManagerInterface $commentManager) | |
{ | |
$this->commentManager = $commentManager; | |
} | |
public function onCommentPersist(CommentEvent $event) | |
{ | |
$comment = $event->getComment(); | |
$thread = $comment->getThread(); | |
$count = 0; | |
foreach ($this->commentManager->findCommentsByThread($thread) as $comment) { | |
var_dump($comment->getState()); | |
if ($comment::STATE_VISIBLE == $comment->getState()) { | |
$count++; | |
} | |
} | |
$thread = $comment->getThread(); | |
$thread->setNumComments($count); | |
$thread->setLastCommentAt($comment->getCreatedAt()); | |
} | |
public static function getSubscribedEvents() | |
{ | |
return array(Events::COMMENT_POST_PERSIST => 'onCommentPersist'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You may try this