3 namespace Rapsys\BlogBundle\Repository
;
8 * This class was generated by the Doctrine ORM. Add your own custom
9 * repository methods below.
11 class KeywordRepository
extends \Doctrine\ORM\EntityRepository
{
15 * @param string $_locale
16 * @param string $_keyword
18 public function findKeyword($_locale, $_keyword) {
20 $ret = $this->getEntityManager()
21 ->createQuery('SELECT k.id, k.created, k.updated, kt.slug, kt.title, kt.description, JSON(at.slug, at.title) AS articles, \'\' AS slugs FROM RapsysBlogBundle:Keyword k JOIN RapsysBlogBundle:KeywordTranslation kt WITH (kt.keyword_id = k.id AND kt.slug = :_keyword) JOIN RapsysBlogBundle:Language AS l WITH (l.id = kt.language_id AND l.iso6391 = :_locale) LEFT JOIN RapsysBlogBundle:ArticleKeyword ak WITH (ak.keyword_id = k.id) LEFT JOIN RapsysBlogBundle:ArticleTranslation at WITH (at.article_id = ak.article_id AND at.language_id = kt.language_id) GROUP BY k.id')
22 ->setParameter('_locale', $_locale)
23 ->setParameter('_keyword', $_keyword)
27 if (!empty($ret['articles'])) {
28 $ret['articles'] = json_decode($ret['articles'], true);
31 //Fetch keyword's slugs in other locale
32 $slugs = $this->getEntityManager()
33 ->createQuery('SELECT JSON(bl.iso6391, bkt.slug) AS slugs FROM RapsysBlogBundle:Language bl LEFT JOIN RapsysBlogBundle:KeywordTranslation bkt WITH (bkt.keyword_id = :_keyword AND bkt.language_id = bl.id) WHERE (bl.iso6391 <> :_locale) GROUP BY bkt.keyword_id')
34 ->setParameter('_locale', $_locale)
35 ->setParameter('_keyword', $ret['id'])
39 if (!empty($slugs['slugs'])) {
40 $ret['slugs'] = json_decode($slugs['slugs'], true);
50 * @param string $_locale
52 public function findKeywords($_locale) {
54 $ret = $this->getEntityManager()
55 #, JSON(kt.keyword_id, kt.title) AS keywords
56 ->createQuery('SELECT k.id, k.created, k.updated, kt.slug, kt.title, JSON(at.slug, at.title) AS articles FROM RapsysBlogBundle:Keyword k JOIN RapsysBlogBundle:KeywordTranslation kt WITH (kt.keyword_id = k.id) JOIN RapsysBlogBundle:Language AS l WITH (l.id = kt.language_id AND l.iso6391 = :_locale) LEFT JOIN RapsysBlogBundle:ArticleKeyword ak WITH (ak.keyword_id = k.id) LEFT JOIN RapsysBlogBundle:ArticleTranslation at WITH (at.article_id = ak.article_id AND at.language_id = kt.language_id) GROUP BY k.id')
57 ->setParameter('_locale', $_locale)
61 foreach ($ret as $id => $keyword) {
62 if (!empty($keyword['articles'])) {
63 $ret[$id]['articles'] = json_decode($keyword['articles'], true);