X-Git-Url: https://git.rapsys.eu/airbundle/blobdiff_plain/f0a1de5ce9ec93c81eaf4f2593fefda43a1dfef8..9b5aab485913580c7cdf414f4d8157ae6aa4c4b4:/Repository/SlotRepository.php diff --git a/Repository/SlotRepository.php b/Repository/SlotRepository.php new file mode 100644 index 0000000..b54fd5a --- /dev/null +++ b/Repository/SlotRepository.php @@ -0,0 +1,60 @@ +getEntityManager(); + + //Get quote strategy + $qs = $em->getConfiguration()->getQuoteStrategy(); + $dp = $em->getConnection()->getDatabasePlatform(); + + //Set the request from quoted table name + //XXX: this allow to make this code table name independent + $req = 'SELECT s.id, s.title FROM '.$qs->getTableName($em->getClassMetadata('RapsysAirBundle:Slot'), $dp).' AS s'; + + //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('title', 'title', 'string') + ->addIndexByScalar('id'); + + //Fetch result + $res = $em + ->createNativeQuery($req, $rsm) + ->getResult(); + + //Init return + $ret = []; + + //Process result + foreach($res as $data) { + //Get translated slot + $slot = $translator->trans($data['title']); + //Set data + //XXX: ChoiceType use display string as key + $ret[$slot] = $data['id']; + } + + //Send result + return $ret; + } +}