Created
October 13, 2010 19:43
-
-
Save bshaffer/624754 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 ForumTopic extends PluginForumTopic | |
{ | |
public function getNewPostCount(sfUser $user) | |
{ | |
if (!$user->isAuthenticated()) | |
{ | |
throw new InvalidArgumentException('This method can only be used with authenticated sfUser instances'); | |
} | |
$userId = $user->getGuardUser()->getId(); | |
$lastLogin = $user->getPreviousLogin(); | |
$lastLogin = $lastLogin ? $lastLogin : date('Y-m-d H:i:s'); | |
// All New Posts for old forum threads | |
$numNewPosts = Doctrine::getTable('ForumThreadComment') | |
->createQuery('c') | |
->leftJoin('c.Thread t') | |
->leftJoin('t.Views v WITH v.user_id = ? AND v.created_at >= c.created_at', $userId) | |
->andWhere('v.id IS NULL') | |
->andWhere('c.created_at > ?', $lastLogin) | |
->andWhere('t.topic_id = ?', $this->getId()) | |
->count(); | |
// All new posts for new forum threads | |
$numNewThreads = Doctrine::getTable('ForumThread') | |
->createQuery('t') | |
->leftJoin('t.Views v WITH v.user_id = ? AND v.created_at >= t.last_activity_date', $userId) | |
->leftJoin('t.Comments c WITH c.created_at >= t.last_activity_date') | |
->andWhere('v.id IS NULL') | |
->andWhere('t.created_at > ?', $lastLogin) | |
->andWhere('t.topic_id = ?', $this->getId()) | |
->andWhere('c.id IS NULL') | |
->count(); | |
return $numNewPosts + $numNewThreads; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment