From a991c46eedec0efb24d0a9974b1c7fcabf8cfa66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20D?= Date: Wed, 23 Aug 2017 23:06:40 +0200 Subject: 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. --- src/Wallabag/CoreBundle/Repository/EntryRepository.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/Wallabag/CoreBundle/Repository/EntryRepository.php') diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index eb5e3205..ecc159fc 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -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); } } -- cgit v1.2.3