X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FRepository%2FEntryRepository.php;h=e9351d85ef439451584a7b2315c5a1fbc56854b9;hb=8cb869ea9556e84c07c9606c9c65432b70f522fd;hp=a16be9e01924d4cefb89b6a37db999fb341ef704;hpb=1930c19d8214c05ceefac5ac011a6b6e7e4a983d;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php index a16be9e0..e9351d85 100644 --- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php +++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php @@ -92,12 +92,15 @@ class EntryRepository extends EntityRepository * @param bool $isStarred * @param string $sort * @param string $order + * @param int $since + * @param string $tags * * @return array */ - public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC') + public function findEntries($userId, $isArchived = null, $isStarred = null, $sort = 'created', $order = 'ASC', $since = 0, $tags = '') { $qb = $this->createQueryBuilder('e') + ->leftJoin('e.tags', 't') ->where('e.user =:userId')->setParameter('userId', $userId); if (null !== $isArchived) { @@ -108,6 +111,16 @@ class EntryRepository extends EntityRepository $qb->andWhere('e.isStarred =:isStarred')->setParameter('isStarred', (bool) $isStarred); } + if ($since >= 0) { + $qb->andWhere('e.updatedAt > :since')->setParameter('since', new \DateTime(date('Y-m-d H:i:s', $since))); + } + + if ('' !== $tags) { + foreach (explode(',', $tags) as $tag) { + $qb->andWhere('t.label = :label')->setParameter('label', $tag); + } + } + if ('created' === $sort) { $qb->orderBy('e.id', $order); } elseif ('updated' === $sort) { @@ -157,7 +170,7 @@ class EntryRepository extends EntityRepository ->getQuery() ->getResult(); - $languages = array(); + $languages = []; foreach ($results as $result) { $languages[$result['language']] = $result['language']; } @@ -233,12 +246,11 @@ class EntryRepository extends EntityRepository * @param $url * @param $userId * - * @return array|bool + * @return Entry|bool */ - public function existByUrlAndUserId($url, $userId) + public function findByUrlAndUserId($url, $userId) { $res = $this->createQueryBuilder('e') - ->select('e.id, e.createdAt') ->where('e.url = :url')->setParameter('url', $url) ->andWhere('e.user = :user_id')->setParameter('user_id', $userId) ->getQuery() @@ -256,7 +268,7 @@ class EntryRepository extends EntityRepository * * @param int $userId * - * @return integer + * @return int */ public function countAllEntriesByUsername($userId) {