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