forked from wallabag/wallabag
Set a starred_at field when an entry is starred.
This date is used to sort starred entries. Can not use Entry::timestamps method otherwise starred_at will be updated each time entry is updated. Add an updateStar method into Entry class A migration script has been added in order to set starred_at field.
This commit is contained in:
@ -65,7 +65,7 @@ class EntryRepository extends EntityRepository
|
||||
public function getBuilderForStarredByUser($userId)
|
||||
{
|
||||
return $this
|
||||
->getBuilderByUser($userId)
|
||||
->getBuilderByUser($userId, 'starredAt', 'desc')
|
||||
->andWhere('e.isStarred = true')
|
||||
;
|
||||
}
|
||||
@ -401,15 +401,16 @@ class EntryRepository extends EntityRepository
|
||||
/**
|
||||
* Return a query builder to used by other getBuilderFor* method.
|
||||
*
|
||||
* @param int $userId
|
||||
* @param int $userId
|
||||
* @param string $sortBy
|
||||
* @param string $direction
|
||||
*
|
||||
* @return QueryBuilder
|
||||
*/
|
||||
private function getBuilderByUser($userId)
|
||||
private function getBuilderByUser($userId, $sortBy = 'createdAt', $direction = 'desc')
|
||||
{
|
||||
return $this->createQueryBuilder('e')
|
||||
->andWhere('e.user = :userId')->setParameter('userId', $userId)
|
||||
->orderBy('e.createdAt', 'desc')
|
||||
;
|
||||
->orderBy(sprintf('e.%s', $sortBy), $direction);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user