Browse Source

Refactoring ControllerTrait + MailMailjetNotification

develop
Guillaume 3 years ago
parent
commit
83c80ab52f
9 changed files with 369 additions and 349 deletions
  1. +5
    -0
      Component/DateComponent.php
  2. +1
    -83
      Controller/AbstractAdminController.php
  3. +1
    -202
      Controller/AbstractController.php
  4. +244
    -0
      Controller/ControllerTrait.php
  5. +31
    -8
      Definition/Field/AbstractFieldDefinition.php
  6. +24
    -1
      Definition/SiteSettingDefinition.php
  7. +11
    -10
      Form/Common/CrudFormType.php
  8. +51
    -44
      Notification/MailMailjetNotification.php
  9. +1
    -1
      Resources/translations/admin.fr.yaml

+ 5
- 0
Component/DateComponent.php View File

@@ -21,6 +21,11 @@ class DateComponent
}

public function getDayByNumber($number, $lang = 'fr')
{
return self::getDayByNumberStatic($number, $lang);
}

public static function getDayByNumberStatic($number, $lang = 'fr')
{
if ($lang == 'fr') {
$daysArray = [

+ 1
- 83
Controller/AbstractAdminController.php View File

@@ -37,18 +37,6 @@ use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Security\Permission;
use Lc\SovBundle\Component\EntityComponent;
use Lc\SovBundle\Container\ComponentContainer;
use Lc\SovBundle\Container\File\FileContainer;
use Lc\SovBundle\Container\Newsletter\NewsletterContainer;
use Lc\SovBundle\Container\Reminder\ReminderContainer;
use Lc\SovBundle\Container\Setting\SiteSettingContainer;
use Lc\SovBundle\Container\Site\NewsContainer;
use Lc\SovBundle\Container\Site\PageContainer;
use Lc\SovBundle\Container\Site\SiteContainer;
use Lc\SovBundle\Container\Ticket\TicketContainer;
use Lc\SovBundle\Container\Ticket\TicketMessageContainer;
use Lc\SovBundle\Container\User\GroupUserContainer;
use Lc\SovBundle\Container\User\UserContainer;
use Lc\SovBundle\Definition\ActionDefinition;
use Lc\SovBundle\Doctrine\Extension\DevAliasInterface;
use Lc\SovBundle\Doctrine\Extension\SeoInterface;
@@ -59,8 +47,6 @@ use Lc\SovBundle\Field\CollectionField;
use Lc\SovBundle\Field\Filter\FilterManager;
use Lc\SovBundle\Form\Common\FiltersFormType;
use Lc\SovBundle\Form\Common\PositionType;
use Lc\SovBundle\Notification\MailMailjetNotification;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Lc\SovBundle\Translation\FlashBagTranslator;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\Form\Extension\Core\Type\CollectionType;
@@ -68,45 +54,13 @@ use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface;


abstract class AbstractAdminController extends EaAbstractCrudController
{
use ControllerTrait;

//TODO doit utiliser controllerTrait
protected FormInterface $filtersForm;

public static function getSubscribedServices()
{
return array_merge(
parent::getSubscribedServices(),
[
TranslatorAdmin::class => TranslatorAdmin::class,
FlashBagTranslator::class => FlashBagTranslator::class,
SessionInterface::class => SessionInterface::class,
RequestStack::class => RequestStack::class,
EntityManagerInterface::class => EntityManagerInterface::class,
FilterManager::class => FilterManager::class,
ComponentContainer::class => ComponentContainer::class,
FileContainer::class => FileContainer::class,
NewsletterContainer::class => NewsletterContainer::class,
ReminderContainer::class => ReminderContainer::class,
NewsContainer::class => NewsContainer::class,
PageContainer::class => PageContainer::class,
SiteContainer::class => SiteContainer::class,
TicketContainer::class => TicketContainer::class,
TicketMessageContainer::class => TicketMessageContainer::class,
GroupUserContainer::class => GroupUserContainer::class,
UserContainer::class => UserContainer::class,
SiteSettingContainer::class => SiteSettingContainer::class,
MailMailjetNotification::class => MailMailjetNotification::class,
SettingSolver::class => SettingSolver::class
]
);
}


public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore
{
if ($responseParameters->get('global_actions')) {
@@ -197,14 +151,6 @@ abstract class AbstractAdminController extends EaAbstractCrudController
return $crud;
}

public function addFlashTranslator(string $type, $translationKeyName, $translationEntityName = null, $translationParam = array()):void
{
if ($translationEntityName === null && method_exists($this, 'getTranslationEntityName')) {
$translationEntityName = $this->getTranslationEntityName();
}
$this->get(FlashBagTranslator::class)->add($type, $translationKeyName, $translationEntityName, $translationParam);
}

public function setMaxResults(Crud $crud): void
{
$entityClass = $this->getEntityFqcn();
@@ -379,7 +325,6 @@ abstract class AbstractAdminController extends EaAbstractCrudController
return $this->redirect($url);
}


public function createIndexQueryBuilder(
SearchDto $searchDto,
EntityDto $entityDto,
@@ -449,11 +394,6 @@ abstract class AbstractAdminController extends EaAbstractCrudController
return $response;
}

public function isInstanceOf(string $interfaceName): bool
{
return in_array($interfaceName, class_implements($this->getEntityFqcn()));
}

public function getControllerFqcnByInterface(string $interface): string
{
$context = $this->get(AdminContextProvider::class)->getContext();
@@ -485,8 +425,6 @@ abstract class AbstractAdminController extends EaAbstractCrudController

}



public function configureActions(Actions $actions): Actions
{
$this->buildIndexActions($actions);
@@ -827,25 +765,5 @@ abstract class AbstractAdminController extends EaAbstractCrudController
return $this->createForm($class, $data, $options);
}

public function generateEaUrl(string $controller =null, string $action=null, int $entityId=null, array $extraParam = array()): string
{
$adminUrlGenerator = $this->get(AdminUrlGenerator::class);
if ($controller) {
$adminUrlGenerator->setController($controller);
}
if ($action) {
$adminUrlGenerator->setAction($action);
}
if ($entityId) {
$adminUrlGenerator->setEntityId($entityId);
}
if($extraParam){
foreach ($extraParam as $key=>$value) {
$adminUrlGenerator->set($key, $value);
}
}
return $adminUrlGenerator->generateUrl();
}

}


+ 1
- 202
Controller/AbstractController.php View File

@@ -2,210 +2,9 @@

namespace Lc\SovBundle\Controller;

use Doctrine\ORM\EntityManagerInterface;
use Knp\Component\Pager\PaginatorInterface;
use Lc\SovBundle\Container\ComponentContainer;
use Lc\SovBundle\Container\File\FileContainer;
use Lc\SovBundle\Container\Newsletter\NewsletterContainer;
use Lc\SovBundle\Container\Reminder\ReminderContainer;
use Lc\SovBundle\Container\Setting\SiteSettingContainer;
use Lc\SovBundle\Container\Site\NewsContainer;
use Lc\SovBundle\Container\Site\PageContainer;
use Lc\SovBundle\Container\Site\SiteContainer;
use Lc\SovBundle\Container\Ticket\TicketContainer;
use Lc\SovBundle\Container\Ticket\TicketMessageContainer;
use Lc\SovBundle\Container\User\GroupUserContainer;
use Lc\SovBundle\Container\User\UserContainer;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Lc\SovBundle\Translation\FlashBagTranslator;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as SfAbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;

class AbstractController extends SfAbstractController
{

//TODO doit utiiliser un controller trait, et la totalité des méthodes de controller seront dans le trait

public static function getSubscribedServices()
{
return array_merge(
parent::getSubscribedServices(),
[
Environment::class => Environment::class,
Security::class => Security::class,
EntityManagerInterface::class => EntityManagerInterface::class,
UrlGeneratorInterface::class => UrlGeneratorInterface::class,
SessionInterface::class => SessionInterface::class,
PaginatorInterface::class => PaginatorInterface::class,
RequestStack::class => RequestStack::class,
EventDispatcherInterface::class => EventDispatcherInterface::class,
LoggerInterface::class => LoggerInterface::class,
TranslatorInterface::class => TranslatorInterface::class,
TranslatorAdmin::class => TranslatorAdmin::class,
FlashBagTranslator::class => FlashBagTranslator::class,
SettingSolver::class => SettingSolver::class,
ComponentContainer::class => ComponentContainer::class,
FileContainer::class => FileContainer::class,
NewsletterContainer::class => NewsletterContainer::class,
ReminderContainer::class => ReminderContainer::class,
NewsContainer::class => NewsContainer::class,
PageContainer::class => PageContainer::class,
SiteContainer::class => SiteContainer::class,
TicketContainer::class => TicketContainer::class,
TicketMessageContainer::class => TicketMessageContainer::class,
GroupUserContainer::class => GroupUserContainer::class,
UserContainer::class => UserContainer::class,
SiteSettingContainer::class => SiteSettingContainer::class,
]
);
}


public function addFlashTranslator(string $type, $translationKeyName, $translationEntityName = null, $translationParam = array()):void
{
if ($translationEntityName === null && method_exists($this, 'getTranslationEntityName')) {
$translationEntityName = $this->getTranslationEntityName();
}
$this->get(FlashBagTranslator::class)->add($type, $translationKeyName, $translationEntityName, $translationParam);
}


public function getReferer(Request $request): ?string
{
return $request->headers->get('referer');
}

public function getTemplating(): Environment
{
return $this->get(Environment::class);
}

public function getEntityManager(): EntityManagerInterface
{
return $this->get(EntityManagerInterface::class);
}

public function getRouter(): UrlGeneratorInterface
{
return $this->get(UrlGeneratorInterface::class);
}

public function getSession(): SessionInterface
{
return $this->get(SessionInterface::class);
}

public function getSecurity(): Security
{
return $this->get(Security::class);
}

public function getPaginator(): PaginatorInterface
{
return $this->get(PaginatorInterface::class);
}

public function getRequestStack(): RequestStack
{
return $this->get(RequestStack::class);
}

public function getEventDispatcher(): EventDispatcherInterface
{
return $this->get(EventDispatcherInterface::class);
}

public function getTranslator(): TranslatorInterface
{
return $this->get(TranslatorInterface::class);
}

public function getTranslatorAdmin(): TranslatorAdmin
{
return $this->get(TranslatorAdmin::class);
}

public function getLogger(): LoggerInterface
{
return $this->get(LoggerInterface::class);
}

public function getSettingSolver(): SettingSolver
{
return $this->get(SettingSolver::class);
}

public function getSettingValue($entity, $settingName)
{
return $this->getSettingSolver()->getSettingValue($entity, $settingName);
}

public function getComponentContainer(): ComponentContainer
{
return $this->get(ComponentContainer::class);
}

public function getFileContainer(): FileContainer
{
return $this->get(FileContainer::class);
}

public function getNewsletterContainer(): NewsletterContainer
{
return $this->get(NewsletterContainer::class);
}

public function getReminderContainer(): ReminderContainer
{
return $this->get(ReminderContainer::class);
}

public function getNewsContainer(): NewsContainer
{
return $this->get(NewsContainer::class);
}

public function getPageContainer(): PageContainer
{
return $this->get(PageContainer::class);
}

public function getSiteContainer(): SiteContainer
{
return $this->get(SiteContainer::class);
}

public function getTicketContainer(): TicketContainer
{
return $this->get(TicketContainer::class);
}

public function getTicketMessageContainer(): TicketMessageContainer
{
return $this->get(TicketMessageContainer::class);
}

public function getGroupUserContainer(): GroupUserContainer
{
return $this->get(GroupUserContainer::class);
}

public function getUserContainer(): UserContainer
{
return $this->get(UserContainer::class);
}

public function getSiteSettingContainer(): SiteSettingContainer
{
return $this->get(SiteSettingContainer::class);
}
use ControllerTrait;
}

+ 244
- 0
Controller/ControllerTrait.php View File

@@ -0,0 +1,244 @@
<?php

namespace Lc\SovBundle\Controller;

use Doctrine\ORM\EntityManagerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Knp\Component\Pager\PaginatorInterface;
use Lc\SovBundle\Container\ComponentContainer;
use Lc\SovBundle\Container\File\FileContainer;
use Lc\SovBundle\Container\Newsletter\NewsletterContainer;
use Lc\SovBundle\Container\Reminder\ReminderContainer;
use Lc\SovBundle\Container\Setting\SiteSettingContainer;
use Lc\SovBundle\Container\Site\NewsContainer;
use Lc\SovBundle\Container\Site\PageContainer;
use Lc\SovBundle\Container\Site\SiteContainer;
use Lc\SovBundle\Container\Ticket\TicketContainer;
use Lc\SovBundle\Container\Ticket\TicketMessageContainer;
use Lc\SovBundle\Container\User\GroupUserContainer;
use Lc\SovBundle\Container\User\UserContainer;
use Lc\SovBundle\Field\Filter\FilterManager;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Lc\SovBundle\Translation\FlashBagTranslator;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;

trait ControllerTrait
{
public static function getSubscribedServices()
{
return array_merge(
parent::getSubscribedServices(),
[
Environment::class => Environment::class,
Security::class => Security::class,
EntityManagerInterface::class => EntityManagerInterface::class,
UrlGeneratorInterface::class => UrlGeneratorInterface::class,
SessionInterface::class => SessionInterface::class,
PaginatorInterface::class => PaginatorInterface::class,
RequestStack::class => RequestStack::class,
EventDispatcherInterface::class => EventDispatcherInterface::class,
LoggerInterface::class => LoggerInterface::class,
TranslatorInterface::class => TranslatorInterface::class,
TranslatorAdmin::class => TranslatorAdmin::class,
FilterManager::class => FilterManager::class,
FlashBagTranslator::class => FlashBagTranslator::class,
SettingSolver::class => SettingSolver::class,
ComponentContainer::class => ComponentContainer::class,
FileContainer::class => FileContainer::class,
NewsletterContainer::class => NewsletterContainer::class,
ReminderContainer::class => ReminderContainer::class,
NewsContainer::class => NewsContainer::class,
PageContainer::class => PageContainer::class,
SiteContainer::class => SiteContainer::class,
TicketContainer::class => TicketContainer::class,
TicketMessageContainer::class => TicketMessageContainer::class,
GroupUserContainer::class => GroupUserContainer::class,
UserContainer::class => UserContainer::class,
SiteSettingContainer::class => SiteSettingContainer::class,
]
);
}


public function addFlashTranslator(
string $type,
$translationKeyName,
$translationEntityName = null,
$translationParam = array()
): void {
if ($translationEntityName === null && method_exists($this, 'getTranslationEntityName')) {
$translationEntityName = $this->getTranslationEntityName();
}
$this->get(FlashBagTranslator::class)->add(
$type,
$translationKeyName,
$translationEntityName,
$translationParam
);
}

public function isInstanceOf(string $interfaceName): bool
{
return in_array($interfaceName, class_implements($this->getEntityFqcn()));
}

public function generateEaUrl(string $controller =null, string $action=null, int $entityId=null, array $extraParam = array()): string
{
$adminUrlGenerator = $this->get(AdminUrlGenerator::class);
if ($controller) {
$adminUrlGenerator->setController($controller);
}
if ($action) {
$adminUrlGenerator->setAction($action);
}
if ($entityId) {
$adminUrlGenerator->setEntityId($entityId);
}
if($extraParam){
foreach ($extraParam as $key=>$value) {
$adminUrlGenerator->set($key, $value);
}
}
return $adminUrlGenerator->generateUrl();
}

public function getReferer(Request $request): ?string
{
return $request->headers->get('referer');
}

public function getTemplating(): Environment
{
return $this->get(Environment::class);
}

public function getEntityManager(): EntityManagerInterface
{
return $this->get(EntityManagerInterface::class);
}

public function getRouter(): UrlGeneratorInterface
{
return $this->get(UrlGeneratorInterface::class);
}

public function getSession(): SessionInterface
{
return $this->get(SessionInterface::class);
}

public function getSecurity(): Security
{
return $this->get(Security::class);
}

public function getPaginator(): PaginatorInterface
{
return $this->get(PaginatorInterface::class);
}

public function getRequestStack(): RequestStack
{
return $this->get(RequestStack::class);
}

public function getEventDispatcher(): EventDispatcherInterface
{
return $this->get(EventDispatcherInterface::class);
}

public function getTranslator(): TranslatorInterface
{
return $this->get(TranslatorInterface::class);
}

public function getTranslatorAdmin(): TranslatorAdmin
{
return $this->get(TranslatorAdmin::class);
}

public function getLogger(): LoggerInterface
{
return $this->get(LoggerInterface::class);
}

public function getSettingSolver(): SettingSolver
{
return $this->get(SettingSolver::class);
}

public function getSettingValue($entity, $settingName)
{
return $this->getSettingSolver()->getSettingValue($entity, $settingName);
}

public function getComponentContainer(): ComponentContainer
{
return $this->get(ComponentContainer::class);
}

public function getFileContainer(): FileContainer
{
return $this->get(FileContainer::class);
}

public function getNewsletterContainer(): NewsletterContainer
{
return $this->get(NewsletterContainer::class);
}

public function getReminderContainer(): ReminderContainer
{
return $this->get(ReminderContainer::class);
}

public function getNewsContainer(): NewsContainer
{
return $this->get(NewsContainer::class);
}

public function getPageContainer(): PageContainer
{
return $this->get(PageContainer::class);
}

public function getSiteContainer(): SiteContainer
{
return $this->get(SiteContainer::class);
}

public function getTicketContainer(): TicketContainer
{
return $this->get(TicketContainer::class);
}

public function getTicketMessageContainer(): TicketMessageContainer
{
return $this->get(TicketMessageContainer::class);
}

public function getGroupUserContainer(): GroupUserContainer
{
return $this->get(GroupUserContainer::class);
}

public function getUserContainer(): UserContainer
{
return $this->get(UserContainer::class);
}

public function getSiteSettingContainer(): SiteSettingContainer
{
return $this->get(SiteSettingContainer::class);
}

}

+ 31
- 8
Definition/Field/AbstractFieldDefinition.php View File

@@ -2,6 +2,7 @@

namespace Lc\SovBundle\Definition\Field;

use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
@@ -18,8 +19,8 @@ abstract class AbstractFieldDefinition
protected bool $isPopulate = false;
protected TranslatorAdmin $translatorAdmin;

abstract public function configureFieldsIndex(): array;
abstract public function configurePanels(): array;

abstract public function configureFields(): array;

public function __construct(TranslatorAdmin $translatorAdmin)
@@ -30,36 +31,58 @@ abstract class AbstractFieldDefinition
protected function populate(): void
{
if ($this->isPopulate === false) {
$this->fieldList = $this->configureFields();
$this->fieldList = [] ;
$allFieldArray = $this->configureFields();;
$this->panels = $this->configurePanels();

foreach ($this->panels as $panel) {

$method = 'configureFieldsPanel' . ucfirst($panel);
if (method_exists($this, $method)) {

$fieldArray = $this->$method();
foreach($fieldArray as $key => $field) {
if(is_string($field)) {
unset($fieldArray[$key]);
$fieldArray[$field] = $allFieldArray[$field];
}
}

$this->fieldsByPanel[$panel] = array_merge(
array('panel_' . $panel => FormField::addPanel($panel)),
$this->$method()
['panel_' . $panel => FormField::addPanel($panel)],
$fieldArray
);
$this->fieldList = array_merge($this->fieldList, $this->fieldsByPanel[$panel]);
}else{
throw new \Exception($method . ' n\'esxite pas ');
throw new \Exception($method . ' n\'existe pas ');
}
}

$this->fieldList = array_merge($this->fieldList, $allFieldArray);

$this->isPopulate = false;
}
}

public function getFieldList()
public function getFieldList(string $pageName = '')
{
$this->populate();
return $this->fieldList;

if($pageName == Crud::PAGE_INDEX) {
$fieldArray = [];
foreach($this->configureFieldsIndex() as $fieldName) {
$fieldArray[] = $this->fieldList[$fieldName];
}
return $fieldArray;
}
else {
return $this->fieldList;
}
}

public function getFieldListByPanel($panel)
{
$this->populate();

return $this->fieldsByPanel[$panel];
}


+ 24
- 1
Definition/SiteSettingDefinition.php View File

@@ -6,12 +6,18 @@ namespace Lc\SovBundle\Definition;
class SiteSettingDefinition extends AbstractSettingDefinition implements SiteSettingDefinitionInterface
{
const CATEGORY_GENERAL = 'general';
const CATEGORY_EMAIL = 'email';

const SETTING_MAINTENANCE = 'maintenance';
const SETTING_MAINTENANCE_IP_AUTHORIZED = 'maintenanceIpAuthorized';

const SETTING_EMAIL_SUBJECT_PREFIX = 'emailSubjectPrefix';
const SETTING_EMAIL_FROM = 'emailFrom';
const SETTING_EMAIL_FROM_NAME = 'emailFromName';

public function __construct()
{
// général
$this->addSettingSelect(
[
'category' => self::CATEGORY_GENERAL,
@@ -29,12 +35,29 @@ class SiteSettingDefinition extends AbstractSettingDefinition implements SiteSet
'name' => self::SETTING_MAINTENANCE_IP_AUTHORIZED,
]
);


// email
$this->addSettingText(
[
'category' => self::CATEGORY_EMAIL,
'name' => self::SETTING_EMAIL_FROM,
]
);

$this->addSettingText(
[
'category' => self::CATEGORY_EMAIL,
'name' => self::SETTING_EMAIL_FROM_NAME,
]
);
}

public function getCategories()
{
return [
self::CATEGORY_GENERAL
self::CATEGORY_GENERAL,
self::CATEGORY_EMAIL
];
}


+ 11
- 10
Form/Common/CrudFormType.php View File

@@ -47,20 +47,21 @@ class CrudFormType extends AbstractType

if (EaFormPanelType::class === $formFieldType) {
++$currentFormPanel;
$formPanels[$currentFormPanel] = [
'form_tab' => $currentFormTab ?? null,
'label' => $fieldDto->getLabel(),
'help' => $fieldDto->getHelp(),
'css_class' => $fieldDto->getCssClass(),
];
foreach ($fieldDto->getCustomOptions()->all() as $customOptionKey => $customOption) {
$formPanels[$currentFormPanel][$customOptionKey] = $customOption;
if($fieldDto->getLabel()) {
$formPanels[$currentFormPanel] = [
'form_tab' => null,
'label' => $fieldDto->getLabel(),
'help' => $fieldDto->getHelp(),
'css_class' => $fieldDto->getCssClass(),
];
foreach ($fieldDto->getCustomOptions()->all() as $customOptionKey => $customOption) {
$formPanels[$currentFormPanel][$customOptionKey] = $customOption;
}
}
continue;
}
}

$builder->setAttribute('ea_form_panels', $formPanels);
//$this->niche->buildForm($builder, $options);
}

public function finishView(FormView $view, FormInterface $form, array $options)

+ 51
- 44
Notification/MailMailjetNotification.php View File

@@ -4,6 +4,8 @@ namespace Lc\SovBundle\Notification;

use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\SovBundle\Definition\SiteSettingDefinition;
use Lc\SovBundle\Repository\Site\SiteStore;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
@@ -25,55 +27,64 @@ class MailMailjetNotification
const ATTACHMENT_DATA = 'attachment-data';
const ATTACHMENT_FILENAME = 'attachment-filename';
const ATTACHMENT_CONTENT_TYPE = 'attachment-content-type';
//const DISPOSITION_NOTIFICATION_TO = 'disposition-notification-to' ;

protected MailjetTransport $transport;
protected Environment $templating;
protected ParameterBagInterface $parameterBag;
protected MerchantResolver $merchantResolver;
protected SettingSolver $settingSolver;
protected SiteStore $siteStore;

public function __construct(
MailjetTransport $mailjetTransport,
Environment $templating,
ParameterBagInterface $parameterBag,
MerchantResolver $merchantResolver,
SettingSolver $settingSolver
)
{
MailjetTransport $mailjetTransport,
Environment $templating,
ParameterBagInterface $parameterBag,
SettingSolver $settingSolver,
SiteStore $siteStore
) {
$this->transport = $mailjetTransport;
$this->templating = $templating;
$this->parameterBag = $parameterBag;
$this->merchantResolver = $merchantResolver;
$this->settingSolver = $settingSolver;
$this->siteStore = $siteStore;
}

public function send($params = [])
{
$merchantCurrent = $this->merchantResolver->getCurrent();

$merchantConfigEmailFrom = $this->settingSolver->getSettingValue($merchantCurrent, MerchantSettingDefinition::SETTING_EMAIL_FROM);
$emailFrom = (isset($params[self::FROM_EMAIL]) && $params[self::FROM_EMAIL] && strlen($params[self::FROM_EMAIL])) ? $params[self::FROM_EMAIL] : $merchantConfigEmailFrom;

$merchantConfigEmailFromName = $this->settingSolver->getSettingValue($merchantCurrent, MerchantSettingDefinition::SETTING_EMAIL_FROM_NAME);
$emailFromName = isset($params[self::FROM_NAME]) ?? $merchantConfigEmailFromName;

$merchantConfigEmailSubjectPrefix = $this->settingSolver->getSettingValue($merchantCurrent, MerchantSettingDefinition::SETTING_EMAIL_SUBJECT_PREFIX);
$emailSubjectPrefix = isset($params[self::SUBJECT_PREFIX]) ?? $merchantConfigEmailSubjectPrefix;
if ($emailSubjectPrefix && strlen($emailSubjectPrefix)) {
$emailSubjectPrefix .= ' ';
}
$siteDefault = $this->siteStore->getOneDefault();

$emailSubjectPrefix = (isset($params[self::SUBJECT_PREFIX]) && $params[self::SUBJECT_PREFIX] && strlen($params[self::SUBJECT_PREFIX]) > 0)
? $params[self::SUBJECT_PREFIX]
: $this->settingSolver->getSettingValue(
$siteDefault,
SiteSettingDefinition::SETTING_EMAIL_SUBJECT_PREFIX
);

$emailFrom = (isset($params[self::FROM_EMAIL]) && $params[self::FROM_EMAIL] && strlen($params[self::FROM_EMAIL]) > 0)
? $params[self::FROM_EMAIL]
: $this->settingSolver->getSettingValue(
$siteDefault,
SiteSettingDefinition::SETTING_EMAIL_FROM
);

$emailFromName = (isset($params[self::FROM_NAME]) && $params[self::FROM_NAME] && strlen($params[self::FROM_NAME]) > 0)
? $params[self::FROM_NAME]
: $this->settingSolver->getSettingValue(
$siteDefault,
SiteSettingDefinition::SETTING_EMAIL_FROM_NAME
);

$message = new \Swift_Message($emailSubjectPrefix . $params[self::SUBJECT]);


if ($this->parameterBag->get('mailjet.dev.redirect.active') == 1) {
$message->addTo($this->parameterBag->get('mailjet.dev.redirect.email'),
isset($params[self::TO_NAME]) ?? null);
$message->addTo(
$this->parameterBag->get('mailjet.dev.redirect.email'),
isset($params[self::TO_NAME]) ?? null
);
} else {
$message->addTo(
$params[self::TO_EMAIL],
isset($params[self::TO_NAME]) ?? null);
$params[self::TO_EMAIL],
isset($params[self::TO_NAME]) ?? null
);
}

$contentData = [];
@@ -82,8 +93,11 @@ class MailMailjetNotification
}

$message->addFrom($emailFrom, $emailFromName)
->setBody($this->templating->render($params[self::CONTENT_TEMPLATE] . '-html.html.twig', $contentData), 'text/html')
->addPart($this->templating->render($params[self::CONTENT_TEMPLATE] . '-text.html.twig', $contentData));
->setBody(
$this->templating->render($params[self::CONTENT_TEMPLATE] . '-html.html.twig', $contentData),
'text/html'
)
->addPart($this->templating->render($params[self::CONTENT_TEMPLATE] . '-text.html.twig', $contentData));

if (isset($params[self::COPY_TO]) && strlen($params[self::COPY_TO])) {
$message->addCc($params[self::COPY_TO]);
@@ -98,22 +112,15 @@ class MailMailjetNotification
}

if (isset($params[self::ATTACHMENT_DATA]) && isset($params[self::ATTACHMENT_FILENAME]) && isset($params[self::ATTACHMENT_CONTENT_TYPE])) {
$message->attach(\Swift_Attachment::newInstance(
$params[self::ATTACHMENT_DATA],
$params[self::ATTACHMENT_FILENAME],
$params[self::ATTACHMENT_CONTENT_TYPE]
));
$message->attach(
\Swift_Attachment::newInstance(
$params[self::ATTACHMENT_DATA],
$params[self::ATTACHMENT_FILENAME],
$params[self::ATTACHMENT_CONTENT_TYPE]
)
);
}

/*if(isset($params[self::DISPOSITION_NOTIFICATION_TO]) && $params[self::DISPOSITION_NOTIFICATION_TO]) {
$emailFromDispositionNotificationTo = $emailFrom ;
if(isset($params[self::REPLY_TO]) && strlen($params[self::REPLY_TO])) {
$emailFromDispositionNotificationTo = $params[self::REPLY_TO] ;
}
$message->getHeaders()->addTextHeader('Disposition-Notification-To', $emailFromDispositionNotificationTo) ;
$message->getHeaders()->addMailboxHeader('Disposition-Notification-To', $emailFromDispositionNotificationTo);
}*/

return $this->transport->send($message);
}
}

+ 1
- 1
Resources/translations/admin.fr.yaml View File

@@ -113,7 +113,7 @@ entity:
position: Position
description: Description
file: Fichier
status: Status
status: Statut
email: Email
value: Valeur
metaTitle: Meta title

Loading…
Cancel
Save