* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Rapsys\BlogBundle\Repository; use Doctrine\ORM\Query\ResultSetMapping; /** * KeywordRepository * * This class was generated by the Doctrine ORM. Add your own custom * repository methods below. */ class KeywordRepository extends EntityRepository { /** * Find keyword count as int * * @return integer The keywords count */ public function findCountAsInt(): int { //Set the request $req = <<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('count', 'count', 'integer'); //Get result return $this->_em ->createNativeQuery($req, $rsm) ->getSingleScalarResult(); } /** * Find keywords as array * * @param integer $page The page * @param integer $count The count * @return array The keywords array */ public function findAllAsArray(int $page, int $count): array { //Set the request $req = <<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('description', 'description', 'string') ->addScalarResult('slug', 'slug', 'string') ->addScalarResult('title', 'title', 'string') ->addScalarResult('created', 'created', 'datetime') ->addScalarResult('updated', 'updated', 'datetime') ->addScalarResult('modified', 'modified', 'datetime') ->addIndexByScalar('id'); //Get result $result = $this->_em ->createNativeQuery($req, $rsm) ->setParameter('offset', $page * $count) ->setParameter('count', $count) ->getArrayResult(); //Set return $return = []; //Iterate on each city foreach($result as $data) { //Add to return $return[$data['id']] = [ 'id' => $id = $data['id'], '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_keyword_view', ['id' => $id, 'slug' => $slug]) ]; } //Return return return $return; } /** * Find keyword by id as array * * @param integer $id The keyword id * @return array The keyword array */ public function findByIdAsArray(int $id): array { //Set the request $req = << :locale) GROUP BY c.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('a_ids', 'a_ids', 'string') ->addScalarResult('a_descriptions', 'a_descriptions', 'string') ->addScalarResult('a_slugs', 'a_slugs', 'string') ->addScalarResult('a_titles', 'a_titles', 'string') ->addScalarResult('ak_aids', 'ak_aids', 'string') ->addScalarResult('ak_kids', 'ak_kids', 'string') ->addScalarResult('ak_slugs', 'ak_slugs', 'string') ->addScalarResult('ak_titles', 'ak_titles', 'string') ->addScalarResult('ckt_locales', 'ckt_locales', 'string') ->addScalarResult('ckt_slugs', 'ckt_slugs', 'string') ->addScalarResult('ckt_titles', 'ckt_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'], '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_keyword_view', ['id' => $id, 'slug' => $slug]), 'alternates' => [], 'articles' => [] ]; //Explode article ids $data['a_ids'] = explode("\n", $data['a_ids']); //Explode article descriptions $data['a_descriptions'] = explode("\n", $data['a_descriptions']); //Explode article slugs $data['a_slugs'] = explode("\n", $data['a_slugs']); //Explode article titles $data['a_titles'] = explode("\n", $data['a_titles']); //Iterate on articles foreach($data['a_ids'] as $k => $aid) { $return['articles'][$aid] = [ 'id' => $aid, 'description' => $data['a_descriptions'][$k], 'slug' => $slug = $data['a_slugs'][$k], 'title' => $data['a_titles'][$k], 'link' => $this->router->generate('rapsys_blog_article_view', ['id' => $aid, 'slug' => $slug]), 'keywords' => [] ]; } //Explode article ids $data['ak_aids'] = explode("\n", $data['ak_aids']); //Explode article keyword ids $data['ak_kids'] = explode("\n", $data['ak_kids']); //Explode article keyword slugs $data['ak_slugs'] = explode("\n", $data['ak_slugs']); //Explode article keyword titles $data['ak_titles'] = explode("\n", $data['ak_titles']); //Iterate on articles foreach($data['ak_aids'] as $k => $aid) { $return['articles'][$aid]['keywords'][$data['ak_kids'][$k]] = [ 'id' => $data['ak_kids'][$k], 'slug' => $slug = $data['ak_slugs'][$k], 'title' => $data['ak_titles'][$k], 'link' => $this->router->generate('rapsys_blog_keyword_view', ['id' => $data['ak_kids'][$k], 'slug' => $slug]), ]; } //Explode alternate locales $data['ckt_locales'] = explode("\n", $data['ckt_locales']); //Explode alternate slugs $data['ckt_slugs'] = explode("\n", $data['ckt_slugs']); //Explode alternate titles $data['ckt_titles'] = explode("\n", $data['ckt_titles']); foreach($data['ckt_locales'] as $k => $locale) { $return['alternates'][$locale] = [ 'locale' => $locale, 'slug' => $slug = $data['ckt_slugs'][$k], 'title' => $data['ckt_titles'][$k], 'link' => $this->router->generate('rapsys_blog_keyword_view', ['_locale' => $locale, 'id' => $id, 'slug' => $slug]), ]; } //Return return return $return; } }