namespace Wallabag\CoreBundle\Repository;
use Doctrine\ORM\EntityRepository;
+use Doctrine\ORM\QueryBuilder;
use Wallabag\CoreBundle\Entity\Tag;
class TagRepository extends EntityRepository
*/
public function findAllTags($userId)
{
- $ids = $this->createQueryBuilder('t')
+ $ids = $this->getQueryBuilderByUser($userId)
->select('t.id')
- ->leftJoin('t.entries', 'e')
- ->where('e.user = :userId')->setParameter('userId', $userId)
- ->groupBy('t.id')
- ->orderBy('t.slug')
->getQuery()
->getArrayResult();
*/
public function findAllFlatTagsWithNbEntries($userId)
{
- return $this->createQueryBuilder('t')
+ return $this->getQueryBuilderByUser($userId)
->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();
}
public function findForArchivedArticlesByUser($userId)
{
- $ids = $this->createQueryBuilder('t')
+ $ids = $this->getQueryBuilderByUser($userId)
->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();
return $tags;
}
+
+ /**
+ * Retrieve a sorted list of tags used by a user.
+ *
+ * @param int $userId
+ *
+ * @return QueryBuilder
+ */
+ private function getQueryBuilderByUser($userId)
+ {
+ return $this->createQueryBuilder('t')
+ ->leftJoin('t.entries', 'e')
+ ->where('e.user = :userId')->setParameter('userId', $userId)
+ ->groupBy('t.id')
+ ->orderBy('t.slug');
+ }
}