]> Raphaël G. Git Repositories - airbundle/blob - Repository.php
Replace dropped calls with checker, factory and security replacements
[airbundle] / Repository.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;
13
14 use Doctrine\ORM\EntityManagerInterface;
15 use Doctrine\ORM\EntityRepository;
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 * Repository
24 *
25 * {@inheritdoc}
26 */
27 class Repository extends EntityRepository {
28 /**
29 * The table keys array
30 *
31 * @var array
32 */
33 protected array $tableKeys;
34
35 /**
36 * The table values array
37 *
38 * @var array
39 */
40 protected array $tableValues;
41
42 /**
43 * Initializes a new LocationRepository instance
44 *
45 * @param EntityManagerInterface $manager The EntityManagerInterface instance
46 * @param ClassMetadata $class The ClassMetadata instance
47 * @param RouterInterface $router The router instance
48 * @param SluggerUtil $slugger The SluggerUtil instance
49 * @param TranslatorInterface $translator The TranslatorInterface instance
50 * @param string $locale The current locale
51 * @param array $languages The languages list
52 */
53 public function __construct(protected EntityManagerInterface $manager, protected ClassMetadata $class, protected RouterInterface $router, protected SluggerUtil $slugger, protected TranslatorInterface $translator, protected string $locale, protected array $languages) {
54 //Call parent constructor
55 parent::__construct($manager, $class);
56
57 //Get quote strategy
58 $qs = $this->manager->getConfiguration()->getQuoteStrategy();
59 $dp = $this->manager->getConnection()->getDatabasePlatform();
60
61 //Set quoted table names
62 //XXX: this allow to make this code table name independent
63 //XXX: remember to place longer prefix before shorter to avoid strange replacings
64 //XXX: entity short syntax removed in doctrine/persistence 3.x: https://github.com/doctrine/orm/issues/8818
65 $tables = [
66 'Rapsys\AirBundle\Entity\UserDance' => $qs->getJoinTableName($manager->getClassMetadata('Rapsys\AirBundle\Entity\User')->getAssociationMapping('dances'), $manager->getClassMetadata('Rapsys\AirBundle\Entity\User'), $dp),
67 'Rapsys\AirBundle\Entity\UserGroup' => $qs->getJoinTableName($manager->getClassMetadata('Rapsys\AirBundle\Entity\User')->getAssociationMapping('groups'), $manager->getClassMetadata('Rapsys\AirBundle\Entity\User'), $dp),
68 'Rapsys\AirBundle\Entity\UserLocation' => $qs->getJoinTableName($manager->getClassMetadata('Rapsys\AirBundle\Entity\User')->getAssociationMapping('locations'), $manager->getClassMetadata('Rapsys\AirBundle\Entity\User'), $dp),
69 'Rapsys\AirBundle\Entity\UserSubscription' => $qs->getJoinTableName($manager->getClassMetadata('Rapsys\AirBundle\Entity\User')->getAssociationMapping('subscriptions'), $manager->getClassMetadata('Rapsys\AirBundle\Entity\User'), $dp),
70 'Rapsys\AirBundle\Entity\Application' => $qs->getTableName($manager->getClassMetadata('Rapsys\AirBundle\Entity\Application'), $dp),
71 'Rapsys\AirBundle\Entity\Civility' => $qs->getTableName($manager->getClassMetadata('Rapsys\AirBundle\Entity\Civility'), $dp),
72 'Rapsys\AirBundle\Entity\Country' => $qs->getTableName($manager->getClassMetadata('Rapsys\AirBundle\Entity\Country'), $dp),
73 'Rapsys\AirBundle\Entity\Dance' => $qs->getTableName($manager->getClassMetadata('Rapsys\AirBundle\Entity\Dance'), $dp),
74 'Rapsys\AirBundle\Entity\GoogleCalendar' => $qs->getTableName($manager->getClassMetadata('Rapsys\AirBundle\Entity\GoogleCalendar'), $dp),
75 'Rapsys\AirBundle\Entity\GoogleToken' => $qs->getTableName($manager->getClassMetadata('Rapsys\AirBundle\Entity\GoogleToken'), $dp),
76 'Rapsys\AirBundle\Entity\Group' => $qs->getTableName($manager->getClassMetadata('Rapsys\AirBundle\Entity\Group'), $dp),
77 'Rapsys\AirBundle\Entity\Location' => $qs->getTableName($manager->getClassMetadata('Rapsys\AirBundle\Entity\Location'), $dp),
78 'Rapsys\AirBundle\Entity\Session' => $qs->getTableName($manager->getClassMetadata('Rapsys\AirBundle\Entity\Session'), $dp),
79 'Rapsys\AirBundle\Entity\Slot' => $qs->getTableName($manager->getClassMetadata('Rapsys\AirBundle\Entity\Slot'), $dp),
80 'Rapsys\AirBundle\Entity\Snippet' => $qs->getTableName($manager->getClassMetadata('Rapsys\AirBundle\Entity\Snippet'), $dp),
81 'Rapsys\AirBundle\Entity\User' => $qs->getTableName($manager->getClassMetadata('Rapsys\AirBundle\Entity\User'), $dp),
82 //Set accuweather max number of daily pages
83 ':accudaily' => 12,
84 //Set accuweather max number of hourly pages
85 ':accuhourly' => 3,
86 //Set guest delay
87 ':guestdelay' => 2 * 24 * 3600,
88 //Set regular delay
89 ':regulardelay' => 3 * 24 * 3600,
90 //Set senior delay
91 ':seniordelay' => 4 * 24 * 3600,
92 //Set guest group id
93 ':guestid' => 2,
94 //Set regular group id
95 ':regularid' => 3,
96 //Set senior group id
97 ':seniorid' => 4,
98 //Set afternoon slot id
99 ':afternoonid' => 2,
100 //Set evening slot id
101 ':eveningid' => 3,
102 //Set after slot id
103 ':afterid' => 4,
104 //XXX: days since last session after which guest regain normal priority
105 ':guestwait' => 30,
106 //XXX: session count until considered at regular delay
107 ':scount' => 5,
108 //XXX: pn_ratio over which considered at regular delay
109 ':pnratio' => 1,
110 //XXX: tr_ratio diff over which considered at regular delay
111 ':trdiff' => 5,
112 //Set locale
113 //XXX: or $manager->getConnection()->quote($this->locale) ???
114 ':locale' => $dp->quoteStringLiteral($this->locale),
115 //XXX: Set limit used to workaround mariadb subselect optimization
116 ':limit' => PHP_INT_MAX,
117 "\t" => '',
118 "\n" => ' '
119 ];
120
121 //Set quoted table name keys
122 $this->tableKeys = array_keys($tables);
123
124 //Set quoted table name values
125 $this->tableValues = array_values($tables);
126 }
127 }