3 namespace Rapsys\AirBundle\Repository
;
5 use Symfony\Component\Translation\TranslatorInterface
;
6 use Doctrine\ORM\Query\ResultSetMapping
;
11 class DanceRepository
extends \Doctrine\ORM\EntityRepository
{
13 * Find dances by user id
15 * @param $id The user id
16 * @return array The user dances
18 public function findByUserId($userId) {
20 $em = $this->getEntityManager();
23 $qs = $em->getConfiguration()->getQuoteStrategy();
24 $dp = $em->getConnection()->getDatabasePlatform();
26 //Get quoted table names
27 //XXX: this allow to make this code table name independent
29 'RapsysAirBundle:UserDance' => $qs->getJoinTableName($em->getClassMetadata('RapsysAirBundle:User')->getAssociationMapping('dances'), $em->getClassMetadata('RapsysAirBundle:User'), $dp),
30 'RapsysAirBundle:Dance' => $qs->getTableName($em->getClassMetadata('RapsysAirBundle:Dance'), $dp)
34 $req = 'SELECT d.id, d.title
35 FROM RapsysAirBundle:UserDance AS ud
36 JOIN RapsysAirBundle:Dance AS d ON (d.id = ud.dance_id)
37 WHERE ud.user_id = :uid';
39 //Replace bundle entity name by table name
40 $req = str_replace(array_keys($tables), array_values($tables), $req);
42 //Get result set mapping instance
43 //XXX: DEBUG: see ../blog.orig/src/Rapsys/BlogBundle/Repository/ArticleRepository.php
44 $rsm = new ResultSetMapping();
46 //Declare result set for our request
47 $rsm->addEntityResult('RapsysAirBundle:Dance', 'd');
48 $rsm->addFieldResult('d', 'id', 'id');
49 $rsm->addFieldResult('d', 'title', 'title');
53 ->createNativeQuery($req, $rsm)
54 ->setParameter('uid', $userId)