]> Raphaël G. Git Repositories - airbundle/blob - Repository/EntityRepository.php
fb07c0b0537ff45cd5f319da2227f34140a4c687
[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 * Initializes a new LocationRepository instance
72 *
73 * @param EntityManagerInterface $manager The EntityManagerInterface instance
74 * @param ClassMetadata $class The ClassMetadata instance
75 * @param RouterInterface $router The router instance
76 * @param SluggerUtil $slugger The SluggerUtil instance
77 * @param TranslatorInterface $translator The TranslatorInterface instance
78 * @param array $languages The languages list
79 */
80 public function __construct(EntityManagerInterface $manager, ClassMetadata $class, RouterInterface $router, SluggerUtil $slugger, TranslatorInterface $translator, array $languages) {
81 //Call parent constructor
82 parent::__construct($manager, $class);
83
84 //Set languages
85 $this->languages = $languages;
86
87 //Set router
88 $this->router = $router;
89
90 //Set slugger
91 $this->slugger = $slugger;
92
93 //Set translator
94 $this->translator = $translator;
95
96 //Get quote strategy
97 $qs = $manager->getConfiguration()->getQuoteStrategy();
98 $dp = $manager->getConnection()->getDatabasePlatform();
99
100 //Set quoted table names
101 //XXX: this allow to make this code table name independent
102 //XXX: remember to place longer prefix before shorter to avoid strange replacings
103 $tables = [
104 'RapsysAirBundle:UserGroup' => $qs->getJoinTableName($manager->getClassMetadata('RapsysAirBundle:User')->getAssociationMapping('groups'), $manager->getClassMetadata('RapsysAirBundle:User'), $dp),
105 'RapsysAirBundle:UserLocation' => $qs->getJoinTableName($manager->getClassMetadata('RapsysAirBundle:User')->getAssociationMapping('locations'), $manager->getClassMetadata('RapsysAirBundle:User'), $dp),
106 'RapsysAirBundle:Application' => $qs->getTableName($manager->getClassMetadata('RapsysAirBundle:Application'), $dp),
107 'RapsysAirBundle:Civility' => $qs->getTableName($manager->getClassMetadata('RapsysAirBundle:Civility'), $dp),
108 'RapsysAirBundle:Country' => $qs->getTableName($manager->getClassMetadata('RapsysAirBundle:Country'), $dp),
109 'RapsysAirBundle:Dance' => $qs->getTableName($manager->getClassMetadata('RapsysAirBundle:Dance'), $dp),
110 'RapsysAirBundle:Group' => $qs->getTableName($manager->getClassMetadata('RapsysAirBundle:Group'), $dp),
111 'RapsysAirBundle:Location' => $qs->getTableName($manager->getClassMetadata('RapsysAirBundle:Location'), $dp),
112 'RapsysAirBundle:Session' => $qs->getTableName($manager->getClassMetadata('RapsysAirBundle:Session'), $dp),
113 'RapsysAirBundle:Slot' => $qs->getTableName($manager->getClassMetadata('RapsysAirBundle:Slot'), $dp),
114 'RapsysAirBundle:Snippet' => $qs->getTableName($manager->getClassMetadata('RapsysAirBundle:Snippet'), $dp),
115 'RapsysAirBundle:User' => $qs->getTableName($manager->getClassMetadata('RapsysAirBundle:User'), $dp),
116 //Set accuweather max number of daily pages
117 ':accudaily' => 12,
118 //Set accuweather max number of hourly pages
119 ':accuhourly' => 3,
120 //Set guest delay
121 ':guestdelay' => 2 * 24 * 3600,
122 //Set regular delay
123 ':regulardelay' => 3 * 24 * 3600,
124 //Set senior delay
125 ':seniordelay' => 4 * 24 * 3600,
126 //Set guest group id
127 ':guestid' => 2,
128 //Set regular group id
129 ':regularid' => 3,
130 //Set senior group id
131 ':seniorid' => 4,
132 //Set afternoon slot id
133 ':afternoonid' => 2,
134 //Set evening slot id
135 ':eveningid' => 3,
136 //Set after slot id
137 ':afterid' => 4,
138 //XXX: days since last session after which guest regain normal priority
139 ':guestwait' => 30,
140 //XXX: session count until considered at regular delay
141 ':scount' => 5,
142 //XXX: pn_ratio over which considered at regular delay
143 ':pnratio' => 1,
144 //XXX: tr_ratio diff over which considered at regular delay
145 ':trdiff' => 5,
146 //XXX: Set limit used to workaround mariadb subselect optimization
147 ':limit' => PHP_INT_MAX,
148 "\t" => '',
149 "\n" => ' '
150 ];
151
152 //Set quoted table name keys
153 $this->tableKeys = array_keys($tables);
154
155 //Set quoted table name values
156 $this->tableValues = array_values($tables);
157 }
158 }