class TagRepository extends EntityRepository
{
- public function findByEntries($entryId)
+ /**
+ * Find Tags.
+ *
+ * @param int $userId
+ *
+ * @return array
+ */
+ public function findAllTags($userId)
{
- $qb = $this->createQueryBuilder('t')
- ->select('t')
- ->leftJoin('t.id', 'u')
- ->where('e.isStarred = true')
- ->andWhere('u.id =:userId')->setParameter('userId', $userId)
- ->orderBy('e.createdAt', 'desc')
- ->getQuery();
-
- $paginator = new Paginator($qb);
+ return $this->createQueryBuilder('t')
+ ->leftJoin('t.entries', 'e')
+ ->where('e.user = :userId')->setParameter('userId', $userId);
+ }
- return $paginator;
+ /**
+ * Used only in test case to get a tag for our entry.
+ *
+ * @return Tag
+ */
+ public function findOneByEntryAndTagLabel($entry, $label)
+ {
+ return $this->createQueryBuilder('t')
+ ->leftJoin('t.entries', 'e')
+ ->where('e.id = :entryId')->setParameter('entryId', $entry->getId())
+ ->andWhere('t.label = :label')->setParameter('label', $label)
+ ->setMaxResults(1)
+ ->getQuery()
+ ->getSingleResult();
}
}