3 namespace Rapsys\BlogBundle\Repository
;
8 * This class was generated by the Doctrine ORM. Add your own custom
9 * repository methods below.
11 class ArticleRepository
extends \Doctrine\ORM\EntityRepository
{
15 * @param string $_locale
16 * @param string $_article
18 public function findArticle($_locale, $_article) {
19 # //TODO: voir comment faire ça sans gros hack sql ?
21 # $rsm = new \Doctrine\ORM\Query\ResultSetMapping();
22 # $rsm->addScalarResult('id', 'id');
23 # $rsm->addScalarResult('created', 'created');
24 # $rsm->addScalarResult('updated', 'updated');
25 # $rsm->addScalarResult('slug', 'slug');
26 # $rsm->addScalarResult('title', 'title');
27 # $rsm->addScalarResult('description', 'description');
28 # $rsm->addScalarResult('body', 'body');
29 # $rsm->addScalarResult('keywords', 'keywords');
30 # $rsm->addScalarResult('slugs', 'slugs');
33 # $ret = $this->getEntityManager()
34 # #->createQuery('SELECT b.*, JSON(bl.iso6391, bat.slug) AS slugs FROM (SELECT a.id, a.created, a.updated, at.slug, at.title, at.description, at.body, JSON(kt.slug, kt.title) AS keywords FROM RapsysBlogBundle:Article a JOIN RapsysBlogBundle:ArticleTranslation at WITH (at.article_id = a.id AND at.slug = :_article) JOIN RapsysBlogBundle:Language AS l WITH (l.id = at.language_id AND l.iso6391 = :_locale) LEFT JOIN RapsysBlogBundle:ArticleKeyword ak WITH (ak.article_id = a.id) LEFT JOIN RapsysBlogBundle:KeywordTranslation kt WITH (kt.keyword_id = ak.keyword_id AND kt.language_id = at.language_id) GROUP BY a.id) b LEFT JOIN RapsysBlogBundle:Language AS bl WITH (bl.iso6391 <> :_locale) LEFT JOIN RapsysBlogBundle:ArticleTranslation bat WITH (bat.language_id = bl.id AND bat.article_id = b.id) GROUP BY b.id')
35 # ->createNativeQuery('SELECT b.*, CONCAT(\'{\', GROUP_CONCAT(CONCAT(\'"\', REPLACE(bl.iso6391, \'"\', \'\\\\"\'), \'": "\', REPLACE(bat.slug, \'"\', \'\\\\"\'), \'"\')), \'}\') AS slugs FROM (SELECT a.id, a.created, a.updated, at.slug, at.title, at.description, at.body, CONCAT(\'{\', GROUP_CONCAT(CONCAT(\'"\', REPLACE(kt.slug, \'"\', \'\\\\"\'), \'": "\', REPLACE(kt.title, \'"\', \'\\\\"\'), \'"\')), \'}\') AS keywords FROM articles a JOIN articles_translations at ON (at.article_id = a.id AND at.slug = ?) JOIN languages AS l ON (l.id = at.language_id AND l.iso6391 = ?) LEFT JOIN articles_keywords ak ON (ak.article_id = a.id) LEFT JOIN keywords_translations kt ON (kt.keyword_id = ak.keyword_id AND kt.language_id = at.language_id) GROUP BY a.id) b LEFT JOIN languages AS bl ON (bl.iso6391 <> ?) LEFT JOIN articles_translations bat ON (bat.language_id = bl.id AND bat.article_id = b.id) GROUP BY b.id', $rsm)
36 # ->setParameter(0, $_article)
37 # ->setParameter(1, $_locale)
38 # ->setParameter(2, $_locale)
39 # ->getSingleResult();
41 # if (!empty($ret['keywords'])) {
42 # $ret['keywords'] = json_decode($ret['keywords'], true);
44 # if (!empty($ret['slugs'])) {
45 # $ret['slugs'] = json_decode($ret['slugs'], true);
51 $ret = $this->getEntityManager()
52 #->createQuery('SELECT b.*, JSON(bl.iso6391, bat.slug) AS slugs FROM (SELECT a.id, a.created, a.updated, at.slug, at.title, at.description, at.body, JSON(kt.slug, kt.title) AS keywords FROM RapsysBlogBundle:Article a JOIN RapsysBlogBundle:ArticleTranslation at WITH (at.article_id = a.id AND at.slug = :_article) JOIN RapsysBlogBundle:Language AS l WITH (l.id = at.language_id AND l.iso6391 = :_locale) LEFT JOIN RapsysBlogBundle:ArticleKeyword ak WITH (ak.article_id = a.id) LEFT JOIN RapsysBlogBundle:KeywordTranslation kt WITH (kt.keyword_id = ak.keyword_id AND kt.language_id = at.language_id) GROUP BY a.id) b LEFT JOIN RapsysBlogBundle:Language AS bl WITH (bl.iso6391 <> :_locale) LEFT JOIN RapsysBlogBundle:ArticleTranslation bat WITH (bat.language_id = bl.id AND bat.article_id = b.id) GROUP BY b.id')
53 ->createQuery('SELECT a.id, a.created, a.updated, at.slug, at.title, at.description, at.body, JSON(kt.slug, kt.title) AS keywords FROM RapsysBlogBundle:Article a JOIN RapsysBlogBundle:ArticleTranslation at WITH (at.article_id = a.id AND at.slug = :_article) JOIN RapsysBlogBundle:Language AS l WITH (l.id = at.language_id AND l.iso6391 = :_locale) LEFT JOIN RapsysBlogBundle:ArticleKeyword ak WITH (ak.article_id = a.id) LEFT JOIN RapsysBlogBundle:KeywordTranslation kt WITH (kt.keyword_id = ak.keyword_id AND kt.language_id = at.language_id) GROUP BY a.id')
54 ->setParameter('_locale', $_locale)
55 ->setParameter('_article', $_article)
59 if (!empty($ret['keywords'])) {
60 $ret['keywords'] = json_decode($ret['keywords'], true);
63 //Fetch article's slugs in other locale
64 $slugs = $this->getEntityManager()
65 ->createQuery('SELECT JSON(bl.iso6391, bat.slug) AS slugs FROM RapsysBlogBundle:Language bl LEFT JOIN RapsysBlogBundle:ArticleTranslation bat WITH (bat.article_id = :_article AND bat.language_id = bl.id) WHERE (bl.iso6391 <> :_locale) GROUP BY bat.article_id')
66 ->setParameter('_locale', $_locale)
67 ->setParameter('_article', $ret['id'])
71 if (!empty($slugs['slugs'])) {
72 $ret['slugs'] = json_decode($slugs['slugs'], true);
82 * @param string $_locale
84 public function findArticles($_locale) {
86 $ret = $this->getEntityManager()
87 ->createQuery('SELECT a.id, a.created, a.updated, at.slug, at.title, at.description, JSON(kt.slug, kt.title) AS keywords FROM RapsysBlogBundle:Article a JOIN RapsysBlogBundle:ArticleTranslation at WITH (at.article_id = a.id) JOIN RapsysBlogBundle:Language AS l WITH (l.id = at.language_id AND l.iso6391 = :_locale) LEFT JOIN RapsysBlogBundle:ArticleKeyword ak WITH (ak.article_id = a.id) LEFT JOIN RapsysBlogBundle:KeywordTranslation kt WITH (kt.keyword_id = ak.keyword_id AND kt.language_id = at.language_id) GROUP BY a.id')
88 ->setParameter('_locale', $_locale)
92 foreach ($ret as $id => $article) {
93 if (!empty($article['keywords'])) {
94 $ret[$id]['keywords'] = json_decode($article['keywords'], true);