|
@@ -51,4 +51,24 @@ class ArticleRepository extends ServiceEntityRepository
|
|
|
->getOneOrNullResult()['publicationDate'] ?? null
|
|
|
;
|
|
|
}
|
|
|
+
|
|
|
+ public function findByTag(string $tag, bool $onlyPublished = true): array
|
|
|
+ {
|
|
|
+ $qb = $this->createQueryBuilder('a');
|
|
|
+
|
|
|
+ if ($onlyPublished) {
|
|
|
+ $qb->andWhere('a.state = :published')
|
|
|
+ ->setParameter('published', 'published')
|
|
|
+ ;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $qb
|
|
|
+ ->innerJoin('a.tags', 't')
|
|
|
+ ->andWhere($qb->expr()->like('t.name', ':tag'))
|
|
|
+ ->setParameter('tag', '%'.$tag.'%')
|
|
|
+ ->orderBy('a.publicationDate', 'DESC')
|
|
|
+ ->getQuery()
|
|
|
+ ->getResult()
|
|
|
+ ;
|
|
|
+ }
|
|
|
}
|