]> Raphaël G. Git Repositories - airbundle/blob - Repository/EntityRepository.php
Strict types
[airbundle] / Repository / EntityRepository.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys AirBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Rapsys\AirBundle\Repository;
13
14 use Doctrine\ORM\EntityManagerInterface;
15 use Doctrine\ORM\EntityRepository as BaseEntityRepository;
16 use Doctrine\ORM\Mapping\ClassMetadata;
17 use Symfony\Component\Routing\RouterInterface;
18 use Symfony\Contracts\Translation\TranslatorInterface;
19
20 use Rapsys\PackBundle\Util\SluggerUtil;
21
22 /**
23 * EntityRepository
24 *
25 * {@inheritdoc}
26 */
27 class EntityRepository extends BaseEntityRepository {
28 /**
29 * The RouterInterface instance
30 *
31 * @var RouterInterface
32 */
33 protected RouterInterface $router;
34
35 /**
36 * The SluggerUtil instance
37 *
38 * @var SluggerUtil
39 */
40 protected SluggerUtil $slugger;
41
42 /**
43 * The table keys array
44 *
45 * @var array
46 */
47 protected array $tableKeys;
48
49 /**
50 * The table values array
51 *
52 * @var array
53 */
54 protected array $tableValues;
55
56 /**
57 * The TranslatorInterface instance
58 *
59 * @var TranslatorInterface
60 */
61 protected TranslatorInterface $translator;
62
63 /**
64 * The list of languages
65 *
66 * @var string[]
67 */
68 protected array $languages = [];
69
70 /**
71 * The current locale
72 *
73 * @var string
74 */
75 protected string $locale;
76
77 /**
78 * Initializes a new LocationRepository instance
79 *
80 * @param EntityManagerInterface $manager The EntityManagerInterface instance
81 * @param ClassMetadata $class The ClassMetadata instance
82 * @param RouterInterface $router The router instance
83 * @param SluggerUtil $slugger The SluggerUtil instance
84 * @param TranslatorInterface $translator The TranslatorInterface instance
85 * @param array $languages The languages list
86 * @param string $locale The current locale
87 */
88 public function __construct(EntityManagerInterface $manager, ClassMetadata $class, RouterInterface $router, SluggerUtil $slugger, TranslatorInterface $translator, array $languages, string $locale) {
89 //Call parent constructor
90 parent::__construct($manager, $class);
91
92 //Set languages
93 $this->languages = $languages;
94
95 //Set locale
96 $this->locale = $locale;
97
98 //Set router
99 $this->router = $router;
100
101 //Set slugger
102 $this->slugger = $slugger;
103
104 //Set translator
105 $this->translator = $translator;
106
107 //Get quote strategy
108 $qs = $manager->getConfiguration()->getQuoteStrategy();
109 $dp = $manager->getConnection()->getDatabasePlatform();
110
111 //Set quoted table names
112 //XXX: this allow to make this code table name independent
113 //XXX: remember to place longer prefix before shorter to avoid strange replacings
114 $tables = [
115 'RapsysAirBundle:UserDance' => $qs->getJoinTableName($manager->getClassMetadata('RapsysAirBundle:User')->getAssociationMapping('dances'), $manager->getClassMetadata('RapsysAirBundle:User'), $dp),
116 'RapsysAirBundle:UserGroup' => $qs->getJoinTableName($manager->getClassMetadata('RapsysAirBundle:User')->getAssociationMapping('groups'), $manager->getClassMetadata('RapsysAirBundle:User'), $dp),
117 'RapsysAirBundle:UserLocation' => $qs->getJoinTableName($manager->getClassMetadata('RapsysAirBundle:User')->getAssociationMapping('locations'), $manager->getClassMetadata('RapsysAirBundle:User'), $dp),
118 'RapsysAirBundle:Application' => $qs->getTableName($manager->getClassMetadata('RapsysAirBundle:Application'), $dp),
119 'RapsysAirBundle:Civility' => $qs->getTableName($manager->getClassMetadata('RapsysAirBundle:Civility'), $dp),
120 'RapsysAirBundle:Country' => $qs->getTableName($manager->getClassMetadata('RapsysAirBundle:Country'), $dp),
121 'RapsysAirBundle:Dance' => $qs->getTableName($manager->getClassMetadata('RapsysAirBundle:Dance'), $dp),
122 'RapsysAirBundle:Group' => $qs->getTableName($manager->getClassMetadata('RapsysAirBundle:Group'), $dp),
123 'RapsysAirBundle:Location' => $qs->getTableName($manager->getClassMetadata('RapsysAirBundle:Location'), $dp),
124 'RapsysAirBundle:Session' => $qs->getTableName($manager->getClassMetadata('RapsysAirBundle:Session'), $dp),
125 'RapsysAirBundle:Slot' => $qs->getTableName($manager->getClassMetadata('RapsysAirBundle:Slot'), $dp),
126 'RapsysAirBundle:Snippet' => $qs->getTableName($manager->getClassMetadata('RapsysAirBundle:Snippet'), $dp),
127 'RapsysAirBundle:User' => $qs->getTableName($manager->getClassMetadata('RapsysAirBundle:User'), $dp),
128 //Set accuweather max number of daily pages
129 ':accudaily' => 12,
130 //Set accuweather max number of hourly pages
131 ':accuhourly' => 3,
132 //Set guest delay
133 ':guestdelay' => 2 * 24 * 3600,
134 //Set regular delay
135 ':regulardelay' => 3 * 24 * 3600,
136 //Set senior delay
137 ':seniordelay' => 4 * 24 * 3600,
138 //Set guest group id
139 ':guestid' => 2,
140 //Set regular group id
141 ':regularid' => 3,
142 //Set senior group id
143 ':seniorid' => 4,
144 //Set afternoon slot id
145 ':afternoonid' => 2,
146 //Set evening slot id
147 ':eveningid' => 3,
148 //Set after slot id
149 ':afterid' => 4,
150 //XXX: days since last session after which guest regain normal priority
151 ':guestwait' => 30,
152 //XXX: session count until considered at regular delay
153 ':scount' => 5,
154 //XXX: pn_ratio over which considered at regular delay
155 ':pnratio' => 1,
156 //XXX: tr_ratio diff over which considered at regular delay
157 ':trdiff' => 5,
158 //Set locale
159 //XXX: or $manager->getConnection()->quote($this->locale) ???
160 ':locale' => $dp->quoteStringLiteral($this->locale),
161 //XXX: Set limit used to workaround mariadb subselect optimization
162 ':limit' => PHP_INT_MAX,
163 "\t" => '',
164 "\n" => ' '
165 ];
166
167 //Set quoted table name keys
168 $this->tableKeys = array_keys($tables);
169
170 //Set quoted table name values
171 $this->tableValues = array_values($tables);
172 }
173 }