1 | <?php |
||
24 | final class EmailTemplateRepository extends EntityRepository |
||
25 | { |
||
26 | /** |
||
27 | * @param string $name |
||
28 | * @param string $preferredLocale |
||
29 | * @param string $fallbackLocale |
||
30 | * @return \Surfnet\StepupMiddleware\ManagementBundle\Configuration\Entity\EmailTemplate|null |
||
31 | */ |
||
32 | public function findOneByName($name, $preferredLocale, $fallbackLocale) |
||
33 | { |
||
34 | return $this |
||
35 | ->createQueryBuilder('tpl') |
||
36 | ->where('tpl.name = :name') |
||
37 | ->setParameter('name', $name) |
||
38 | ->addSelect( |
||
39 | 'CASE WHEN tpl.locale = :preferredLocale THEN 2 |
||
40 | WHEN tpl.locale = :fallbackLocale THEN 1 |
||
41 | ELSE 0 |
||
42 | END AS HIDDEN localePreference' |
||
43 | ) |
||
44 | ->setParameter('preferredLocale', $preferredLocale) |
||
45 | ->setParameter('fallbackLocale', $fallbackLocale) |
||
46 | ->orderBy('localePreference', 'DESC') |
||
47 | ->setMaxResults(1) |
||
48 | ->getQuery() |
||
49 | ->getOneOrNullResult(); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Removes all email templates. |
||
54 | * |
||
55 | * We hydrate all templates and remove them through the entitymanager so that they get |
||
56 | * removed from the IdentityMap. This to prevent issues when replaying the events, where |
||
57 | * deleting them with a delete query would cause errors due to templates not being found. |
||
58 | */ |
||
59 | public function removeAll() |
||
72 | |||
73 | public function save(EmailTemplate $template) |
||
79 | } |
||
80 |