Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/sedici/Celsius3 into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiMaceri committed Dec 21, 2018
2 parents 884a0d3 + fc8f524 commit b47da00
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 5 deletions.
15 changes: 14 additions & 1 deletion src/Celsius3/CoreBundle/Controller/AdminMailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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')
));
}

Expand All @@ -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')
));
}

/**
Expand Down
16 changes: 13 additions & 3 deletions src/Celsius3/CoreBundle/Form/Type/MailTemplateType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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' => [
'' => '',
Expand All @@ -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',
),
Expand All @@ -74,6 +83,7 @@ public function configureOptions(OptionsResolver $resolver)
$resolver->setDefaults(array(
'instance' => null,
'code' => null,
'super_admin' => false
));
}
}
1 change: 1 addition & 0 deletions src/Celsius3/CoreBundle/Manager/MailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions src/Celsius3/CoreBundle/Repository/MailTemplateRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
namespace Celsius3\CoreBundle\Repository;

use Celsius3\CoreBundle\Entity\Instance;
use Celsius3\CoreBundle\Entity\MailTemplate;
use Celsius3\CoreBundle\Manager\InstanceManager;

/**
* MailTemplateRepository.
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<ul class="list-unstyled pull-right actions">
{% if template_edited(element) %}
<li>
<a href="{{ path('admin_mails_edit', { 'id': element.id }) }}">
<span class="glyphicon glyphicon-pencil"></span> {{ 'Edit'|trans }}
</a>
</li>
{% endif %}
{% if element.instance.url != constant('Celsius3\\CoreBundle\\Manager\\InstanceManager::INSTANCE__DIRECTORY') %}
<li>
<a href="{{ path('admin_mails_change_state', { 'id': element.id }) }}">
Expand Down
21 changes: 20 additions & 1 deletion src/Celsius3/CoreBundle/Twig/InstanceExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Celsius3\CoreBundle\Twig;

use Celsius3\CoreBundle\Entity\MailTemplate;
use Celsius3\CoreBundle\Entity\Template;
use Doctrine\ORM\EntityManager;

class InstanceExtension extends \Twig_Extension
Expand All @@ -15,7 +17,10 @@ public function __construct(EntityManager $entityManager)

public function getFunctions()
{
return array(new \Twig_SimpleFunction('get_instance_url', array($this, 'getInstanceUrl')));
return array(
new \Twig_SimpleFunction('get_instance_url', array($this, 'getInstanceUrl')),
new \Twig_SimpleFunction('template_edited', array($this, 'templateEdited'))
);
}

public function getInstanceUrl($id)
Expand All @@ -24,4 +29,18 @@ public function getInstanceUrl($id)

return $instance->getUrl();
}

public function templateEdited(MailTemplate $template) {
if ($template->getInstance() !== null && $template->getInstance()->getUrl() !== 'directory') {
return true;
} else {
$templates = $this->entityManager->getRepository(MailTemplate::class)->templateEdited($template);

if (count($templates) > 0) {
return true;
}

return false;
}
}
}

0 comments on commit b47da00

Please sign in to comment.