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
;
16 use Rapsys\AirBundle\Repository
;
21 class SlotRepository
extends Repository
{
23 * Find slots with translated title
25 * @return array The slots id keyed by translated title
27 public function findAllWithTranslatedTitle(): array {
28 //Set the request from quoted table name
29 //XXX: this allow to make this code table name independent
30 $req = 'SELECT s.id, s.title FROM RapsysAirBundle:Slot AS s';
32 //Replace bundle entity name by table name
33 $req = str_replace($this->tableKeys
, $this->tableValues
, $req);
35 //Get result set mapping instance
36 //XXX: DEBUG: see ../blog.orig/src/Rapsys/BlogBundle/Repository/ArticleRepository.php
37 $rsm = new ResultSetMapping();
40 //XXX: see vendor/doctrine/dbal/lib/Doctrine/DBAL/Types/Types.php
41 //addScalarResult($sqlColName, $resColName, $type = 'string');
42 $rsm->addScalarResult('id', 'id', 'integer')
43 ->addScalarResult('title', 'title', 'string')
44 ->addIndexByScalar('id');
48 ->createNativeQuery($req, $rsm)
55 foreach($res as $data) {
57 $slot = $this->translator
->trans($data['title']);
59 //XXX: ChoiceType use display string as key
60 $ret[$slot] = $data['id'];