diff --git a/src/Celsius3/CoreBundle/Controller/AdminMailController.php b/src/Celsius3/CoreBundle/Controller/AdminMailController.php index b741caf3b..6bc3442dd 100644 --- a/src/Celsius3/CoreBundle/Controller/AdminMailController.php +++ b/src/Celsius3/CoreBundle/Controller/AdminMailController.php @@ -22,6 +22,8 @@ namespace Celsius3\CoreBundle\Controller; +use Celsius3\CoreBundle\Helper\InstanceHelper; +use Celsius3\CoreBundle\Manager\InstanceManager; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; @@ -78,6 +80,7 @@ public function newAction() { return $this->baseNew('MailTemplate', new MailTemplate(), MailTemplateType::class, array( 'instance' => $this->getInstance(), + 'super_admin' => $this->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN') )); } @@ -102,13 +105,23 @@ public function editAction($id) if ($template->getInstance() !== $this->getDirectory()) { $route = $this->generateUrl('admin_mails_update', ['id' => $id]); } else { + $result = $this->getDoctrine()->getManager() + ->getRepository(MailTemplate::class) + ->findBy(['code' => $template->getCode(), 'instance' => $this->getInstance()]); + + if (count($result) > 0) { + return $this->redirectToRoute('admin_mails'); + } + $route = $this->generateUrl('admin_mails_create'); } return $this->baseEdit('MailTemplate', $id, MailTemplateType::class, array( 'instance' => $this->getInstance(), 'code' => $template->getCode(), - 'action' => $route, )); + 'action' => $route, + 'super_admin' => $this->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN') + )); } /** diff --git a/src/Celsius3/CoreBundle/Form/Type/MailTemplateType.php b/src/Celsius3/CoreBundle/Form/Type/MailTemplateType.php index a1491c889..ea4fec88b 100644 --- a/src/Celsius3/CoreBundle/Form/Type/MailTemplateType.php +++ b/src/Celsius3/CoreBundle/Form/Type/MailTemplateType.php @@ -23,6 +23,7 @@ namespace Celsius3\CoreBundle\Form\Type; use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\TextareaType; @@ -34,7 +35,10 @@ class MailTemplateType extends AbstractType public function buildForm(FormBuilderInterface $builder, array $options) { $builder - ->add('title') + ->add('title'); + + if($options['super_admin']) { + $builder ->add('code', ChoiceType::class, [ 'choices' => [ '' => '', @@ -48,9 +52,14 @@ public function buildForm(FormBuilderInterface $builder, array $options) MailManager::MAIL__NO_HIVE => MailManager::MAIL__NO_HIVE, MailManager::MAIL__RESETTING => MailManager::MAIL__RESETTING, MailManager::MAIL__USER_CONFIRMATION => MailManager::MAIL__USER_CONFIRMATION, + MailManager::MAIL__CUSTOM => MailManager::MAIL__CUSTOM, ], - ]) - ->add('text', TextareaType::class, array( + ]); + } else { + $builder->add('code', HiddenType::class, ['data' => MailManager::MAIL__CUSTOM]); + } + + $builder->add('text', TextareaType::class, array( 'attr' => array( 'class' => 'summernote', ), @@ -74,6 +83,7 @@ public function configureOptions(OptionsResolver $resolver) $resolver->setDefaults(array( 'instance' => null, 'code' => null, + 'super_admin' => false )); } } diff --git a/src/Celsius3/CoreBundle/Manager/MailManager.php b/src/Celsius3/CoreBundle/Manager/MailManager.php index 6efed7225..f8d18d870 100644 --- a/src/Celsius3/CoreBundle/Manager/MailManager.php +++ b/src/Celsius3/CoreBundle/Manager/MailManager.php @@ -42,6 +42,7 @@ class MailManager const MAIL__NO_HIVE = 'no_hive'; const MAIL__RESETTING = 'resetting'; const MAIL__USER_CONFIRMATION = 'user_confirmation'; + const MAIL__CUSTOM = 'custom'; private $em; private $im; diff --git a/src/Celsius3/CoreBundle/Repository/MailTemplateRepository.php b/src/Celsius3/CoreBundle/Repository/MailTemplateRepository.php index ccf9a5b17..331de2a08 100644 --- a/src/Celsius3/CoreBundle/Repository/MailTemplateRepository.php +++ b/src/Celsius3/CoreBundle/Repository/MailTemplateRepository.php @@ -23,6 +23,8 @@ namespace Celsius3\CoreBundle\Repository; use Celsius3\CoreBundle\Entity\Instance; +use Celsius3\CoreBundle\Entity\MailTemplate; +use Celsius3\CoreBundle\Manager\InstanceManager; /** * MailTemplateRepository. @@ -63,4 +65,20 @@ public function findAllEnabled() ->setParameter('enabled', true) ->getQuery()->getResult(); } + + public function templateEdited(MailTemplate $template) + { + $qb = $this->createQueryBuilder('mt'); + + $qb->select('mt') + ->innerJoin('mt.instance', 'i') + ->where('mt.code = :code') + ->setParameter('code', $template->getCode()) + ->andWhere('mt.instance = :instance') + ->setParameter('instance', $template->getInstance()) + ->andWhere('i.url != :directory') + ->setParameter('directory', 'directory'); + + return $qb->getQuery()->getResult(); + } } diff --git a/src/Celsius3/CoreBundle/Resources/views/AdminMail/_index_list_actions.html.twig b/src/Celsius3/CoreBundle/Resources/views/AdminMail/_index_list_actions.html.twig index d330f96c8..53945b453 100644 --- a/src/Celsius3/CoreBundle/Resources/views/AdminMail/_index_list_actions.html.twig +++ b/src/Celsius3/CoreBundle/Resources/views/AdminMail/_index_list_actions.html.twig @@ -1,9 +1,11 @@