X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FCoreBundle%2FRepository%2FTagRepository.php;h=5c45211f6beb1e2820e9ed5ddba79f95c10a04df;hb=2490f61dca635026a3eb9b5e9b6978b1981b1172;hp=81445989b71c97fc06a13e22f8aaada1b81d871d;hpb=eb2d613c3ed95d741e987917f976da349ea240eb;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/CoreBundle/Repository/TagRepository.php b/src/Wallabag/CoreBundle/Repository/TagRepository.php index 81445989..5c45211f 100644 --- a/src/Wallabag/CoreBundle/Repository/TagRepository.php +++ b/src/Wallabag/CoreBundle/Repository/TagRepository.php @@ -3,6 +3,7 @@ namespace Wallabag\CoreBundle\Repository; use Doctrine\ORM\EntityRepository; +use Wallabag\CoreBundle\Entity\Tag; class TagRepository extends EntityRepository { @@ -49,6 +50,7 @@ class TagRepository extends EntityRepository ->leftJoin('t.entries', 'e') ->where('e.user = :userId')->setParameter('userId', $userId) ->groupBy('t.id') + ->orderBy('t.slug') ->getQuery() ->getArrayResult(); @@ -60,6 +62,27 @@ class TagRepository extends EntityRepository return $tags; } + /** + * Find all tags (flat) per user with nb entries. + * + * @param int $userId + * + * @return array + */ + public function findAllFlatTagsWithNbEntries($userId) + { + return $this->createQueryBuilder('t') + ->select('t.id, t.label, t.slug, count(e.id) as nbEntries') + ->distinct(true) + ->leftJoin('t.entries', 'e') + ->where('e.user = :userId') + ->groupBy('t.id') + ->orderBy('t.slug') + ->setParameter('userId', $userId) + ->getQuery() + ->getArrayResult(); + } + /** * Used only in test case to get a tag for our entry. * @@ -75,4 +98,24 @@ class TagRepository extends EntityRepository ->getQuery() ->getSingleResult(); } + + public function findForArchivedArticlesByUser($userId) + { + $ids = $this->createQueryBuilder('t') + ->select('t.id') + ->leftJoin('t.entries', 'e') + ->where('e.user = :userId')->setParameter('userId', $userId) + ->andWhere('e.isArchived = true') + ->groupBy('t.id') + ->orderBy('t.slug') + ->getQuery() + ->getArrayResult(); + + $tags = []; + foreach ($ids as $id) { + $tags[] = $this->find($id); + } + + return $tags; + } }