+
+ //Return return
+ return $return;
+ }
+
+ /**
+ * Find article by id as array
+ *
+ * @param integer $id The article id
+ * @return array The article array
+ */
+ public function findByIdAsArray(int $id): array {
+ //Set the request
+ $req = <<<SQL
+SELECT
+ b.id,
+ b.created,
+ b.updated,
+ b.modified,
+ b.body,
+ b.description,
+ b.slug,
+ b.title,
+ b.k_ids,
+ b.k_slugs,
+ b.k_titles,
+ GROUP_CONCAT(kat.locale ORDER BY kat.locale SEPARATOR "\\n") AS kat_locales,
+ GROUP_CONCAT(kat.slug ORDER BY kat.locale SEPARATOR "\\n") AS kat_slugs,
+ GROUP_CONCAT(kat.title ORDER BY kat.locale SEPARATOR "\\n") AS kat_titles
+FROM (
+ SELECT
+ a.id,
+ GREATEST(a.created, at.created, k.created, kt.created) AS created,
+ GREATEST(a.updated, at.updated, k.updated, kt.updated) AS updated,
+ GREATEST(a.created, at.created, k.created, kt.created, a.updated, at.updated, k.updated, kt.updated) AS modified,
+ at.body,
+ at.description,
+ at.slug,
+ at.title,
+ GROUP_CONCAT(k.id ORDER BY k.id SEPARATOR "\\n") AS k_ids,
+ GROUP_CONCAT(kt.slug ORDER BY k.id SEPARATOR "\\n") AS k_slugs,
+ GROUP_CONCAT(kt.title ORDER BY k.id SEPARATOR "\\n") AS k_titles
+ FROM RapsysBlogBundle:Article AS a
+ JOIN RapsysBlogBundle:ArticleTranslation AS at ON (at.article_id = a.id AND at.locale = :locale)
+ LEFT JOIN RapsysBlogBundle:ArticleKeyword AS ak ON (ak.article_id = a.id)
+ LEFT JOIN RapsysBlogBundle:Keyword AS k ON (k.id = ak.keyword_id)
+ LEFT JOIN RapsysBlogBundle:KeywordTranslation AS kt ON (kt.keyword_id = k.id AND kt.locale = :locale)
+ WHERE a.id = :id
+ GROUP BY a.id
+ ORDER BY NULL
+ LIMIT 0, :limit
+) AS b
+LEFT JOIN RapsysBlogBundle:ArticleTranslation AS kat ON (kat.article_id = b.id AND kat.locale <> :locale)
+GROUP BY b.id
+SQL;
+
+ //Replace bundle entity name by table name
+ $req = $this->replace($req);
+
+ //Get result set mapping instance
+ //XXX: DEBUG: see ../blog.orig/src/Rapsys/BlogBundle/Repository/ArticleRepository.php
+ $rsm = new ResultSetMapping();
+
+ //Declare all fields
+ //XXX: see vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/Types.php
+ //addScalarResult($sqlColName, $resColName, $type = 'string');
+ $rsm->addScalarResult('id', 'id', 'integer')
+ ->addScalarResult('body', 'body', 'string')
+ ->addScalarResult('description', 'description', 'string')
+ ->addScalarResult('slug', 'slug', 'string')
+ ->addScalarResult('title', 'title', 'string')
+ ->addScalarResult('k_ids', 'k_ids', 'string')
+ ->addScalarResult('k_slugs', 'k_slugs', 'string')
+ ->addScalarResult('k_titles', 'k_titles', 'string')
+ ->addScalarResult('kat_locales', 'kat_locales', 'string')
+ ->addScalarResult('kat_slugs', 'kat_slugs', 'string')
+ ->addScalarResult('kat_titles', 'kat_titles', 'string')
+ ->addScalarResult('created', 'created', 'datetime')
+ ->addScalarResult('updated', 'updated', 'datetime')
+ ->addScalarResult('modified', 'modified', 'datetime');
+
+ //Get data
+ $data = $this->_em
+ ->createNativeQuery($req, $rsm)
+ ->setParameter('id', $id)
+ ->getOneOrNullResult();
+
+ //Set return
+ $return = [
+ 'id' => $id = $data['id'],
+ 'body' => $data['body'],
+ 'description' => $data['description'],
+ 'slug' => $slug = $data['slug'],
+ 'title' => $data['title'],
+ 'created' => $data['created'],
+ 'updated' => $data['updated'],
+ 'modified' => $data['modified'],
+ 'link' => $this->router->generate('rapsys_blog_article_view', ['id' => $id, 'slug' => $slug]),
+ 'alternates' => [],
+ 'keywords' => []
+ ];
+
+ //Explode keyword ids
+ $data['k_ids'] = explode("\n", $data['k_ids']);
+
+ //Explode keyword slugs
+ $data['k_slugs'] = explode("\n", $data['k_slugs']);
+
+ //Explode keyword titles
+ $data['k_titles'] = explode("\n", $data['k_titles']);
+
+ foreach($data['k_ids'] as $k => $kid) {
+ $return['keywords'][$kid] = [
+ 'id' => $kid,
+ 'slug' => $slug = $data['k_slugs'][$k],
+ 'title' => $data['k_titles'][$k],
+ 'link' => $this->router->generate('rapsys_blog_keyword_view', ['id' => $kid, 'slug' => $slug]),
+ ];
+ }
+
+ //Explode alternate locales
+ $data['kat_locales'] = explode("\n", $data['kat_locales']);
+
+ //Explode alternate slugs
+ $data['kat_slugs'] = explode("\n", $data['kat_slugs']);
+
+ //Explode alternate titles
+ $data['kat_titles'] = explode("\n", $data['kat_titles']);
+
+ foreach($data['kat_locales'] as $k => $locale) {
+ $return['alternates'][$locale] = [
+ 'locale' => $locale,
+ 'slug' => $slug = $data['kat_slugs'][$k],
+ 'title' => $data['kat_titles'][$k],
+ 'link' => $this->router->generate('rapsys_blog_article_view', ['_locale' => $locale, 'id' => $id, 'slug' => $slug]),
+ ];
+ }
+
+ //Return return
+ return $return;