Skip to content

Commit

Permalink
Add MessageRepositoryInterface::findRecentSentByUser with mongodb odm…
Browse files Browse the repository at this point in the history
… implementation
  • Loading branch information
ornicar committed Dec 26, 2010
1 parent 49702d0 commit 9c59f7c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Document/MessageRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,20 @@ public function findRecentByUser(User $user, $asPaginator = false)
return array_values($query->getQuery()->execute()->toArray());
}

/**
* @see MessageRepositoryInterface::findRecentSentByUser
*/
public function findRecentSentByUser(User $user, $asPaginator = false)
{
$query = $this->createSentByUserQuery($user)->sort('createdAt', 'DESC');

if ($asPaginator) {
return new Paginator(new DoctrineMongoDBAdapter($query));
}

return array_values($query->getQuery()->execute()->toArray());
}

/**
* @see MessageRepositoryInterface::countUnreadByUser
*/
Expand All @@ -45,6 +59,11 @@ protected function createByUserQuery(User $user)
return $this->createQueryBuilder()->field('to.$id')->equals(new MongoId($user->getId()));
}

protected function createSentByUserQuery(User $user)
{
return $this->createQueryBuilder()->field('from.$id')->equals(new MongoId($user->getId()));
}

protected function createByUserUnreadQuery(User $user)
{
return $this->createByUserQuery($user)->field('isRead')->equals(false);
Expand Down
2 changes: 2 additions & 0 deletions Model/MessageRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ interface MessageRepositoryInterface
{
function findRecentByUser(User $user, $asPaginator = false);

function findRecentSentByUser(User $user, $asPaginator = false);

function countUnreadByUser(User $user);

function createNewMessage();
Expand Down

0 comments on commit 9c59f7c

Please sign in to comment.