1 <?php 
declare(strict_types
=1); 
   4  * This file is part of the Rapsys AirBundle package. 
   6  * (c) Raphaël Gertz <symfony@rapsys.eu> 
   8  * For the full copyright and license information, please view the LICENSE 
   9  * file that was distributed with this source code. 
  12 namespace Rapsys\AirBundle\Repository
; 
  14 use Doctrine\ORM\Query\ResultSetMapping
; 
  19 class DanceRepository 
extends EntityRepository 
{ 
  21          * Find dance names as array 
  23          * @return array The dance names 
  25         public function findNamesAsArray() { 
  30         GROUP_CONCAT(d.id ORDER BY d.id SEPARATOR "\\n") AS ids, 
  31         GROUP_CONCAT(d.type ORDER BY d.id SEPARATOR "\\n") AS types, 
  32         MAX(d.updated) AS modified 
  33 FROM RapsysAirBundle:Dance AS d 
  38                 //Replace bundle entity name by table name 
  39                 $req = str_replace($this->tableKeys
, $this->tableValues
, $req); 
  41                 //Get result set mapping instance 
  42                 //XXX: DEBUG: see ../blog.orig/src/Rapsys/BlogBundle/Repository/ArticleRepository.php 
  43                 $rsm = new ResultSetMapping(); 
  46                 //XXX: see vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/Types.php 
  47                 //addScalarResult($sqlColName, $resColName, $type = 'string'); 
  48                 $rsm->addScalarResult('name', 'name', 'string') 
  49                         ->addScalarResult('ids', 'ids', 'string') 
  50                         ->addScalarResult('types', 'types', 'string') 
  51                         ->addScalarResult('modified', 'modified', 'datetime') 
  52                         ->addIndexByScalar('name'); 
  56                         ->createNativeQuery($req, $rsm) 
  62                 //Iterate on each name 
  63                 foreach($result as $name) { 
  65                         $slug = $this->slugger
->slug($tname = $this->translator
->trans($name['name'])); 
  71                         $name['ids'] = explode("\n", $name['ids']); 
  74                         $name['types'] = explode("\n", $name['types']); 
  76                         //Iterate on each type 
  77                         foreach($name['ids'] as $k => $id) { 
  79                                 $types[$this->slugger
->short($name['types'][$k])] = [ 
  81                                         'type' => $type = $this->translator
->trans($name['types'][$k]), 
  82                                         'slug' => $stype = $this->slugger
->slug($type), 
  83                                         'link' => $this->router
->generate('rapsys_air_dance_view', ['id' => $id, 'name' => $slug, 'type' => $stype]) 
  88                         $return[$sname = $this->slugger
->short($name['name'])] = [ 
  91                                 'link' => $this->router
->generate('rapsys_air_dance_name', ['name' => $sname, 'dance' => $slug]), 
  93                                 'modified' => $name['modified'] 
 102          * Find dances by user id 
 104          * @param $id The user id 
 105          * @return array The user dances 
 107         public function findByUserId($userId) { 
 109                 $req = 'SELECT d.id, d.name, d.type 
 110 FROM RapsysAirBundle:UserDance AS ud 
 111 JOIN RapsysAirBundle:Dance AS d ON (d.id = ud.dance_id) 
 112 WHERE ud.user_id = :uid'; 
 114                 //Replace bundle entity name by table name 
 115                 $req = str_replace($this->tableKeys
, $this->tableValues
, $req); 
 117                 //Get result set mapping instance 
 118                 //XXX: DEBUG: see ../blog.orig/src/Rapsys/BlogBundle/Repository/ArticleRepository.php 
 119                 $rsm = new ResultSetMapping(); 
 121                 //Declare result set for our request 
 122                 $rsm->addEntityResult('RapsysAirBundle:Dance', 'd'); 
 123                 $rsm->addFieldResult('d', 'id', 'id'); 
 124                 $rsm->addFieldResult('d', 'name', 'name'); 
 125                 $rsm->addFieldResult('d', 'type', 'type'); 
 129                         ->createNativeQuery($req, $rsm) 
 130                         ->setParameter('uid', $userId)