namespace Lc\SovBundle\Builder\Ticket; | namespace Lc\SovBundle\Builder\Ticket; | ||||
use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use Lc\CaracoleBundle\Notification\MailMailjetNotification; | |||||
use Lc\SovBundle\Notification\MailMailjetNotification; | |||||
use Lc\SovBundle\Component\FormComponent; | use Lc\SovBundle\Component\FormComponent; | ||||
use Lc\SovBundle\Factory\Ticket\TicketFactory; | use Lc\SovBundle\Factory\Ticket\TicketFactory; | ||||
use Lc\SovBundle\Model\Ticket\TicketInterface; | use Lc\SovBundle\Model\Ticket\TicketInterface; |
namespace Lc\SovBundle\Builder\Ticket; | namespace Lc\SovBundle\Builder\Ticket; | ||||
use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use Lc\CaracoleBundle\Notification\MailMailjetNotification; | |||||
use Lc\SovBundle\Notification\MailMailjetNotification; | |||||
use Lc\SovBundle\Component\FormComponent; | use Lc\SovBundle\Component\FormComponent; | ||||
use Lc\SovBundle\Factory\Ticket\TicketFactory; | use Lc\SovBundle\Factory\Ticket\TicketFactory; | ||||
use Lc\SovBundle\Factory\Ticket\TicketMessageFactory; | use Lc\SovBundle\Factory\Ticket\TicketMessageFactory; |
use Lc\SovBundle\Field\Filter\FilterManager; | use Lc\SovBundle\Field\Filter\FilterManager; | ||||
use Lc\SovBundle\Form\Common\FiltersFormType; | use Lc\SovBundle\Form\Common\FiltersFormType; | ||||
use Lc\SovBundle\Form\Common\PositionType; | use Lc\SovBundle\Form\Common\PositionType; | ||||
use Lc\SovBundle\Notification\MailMailjetNotification; | |||||
use Lc\SovBundle\Translation\TranslatorAdmin; | use Lc\SovBundle\Translation\TranslatorAdmin; | ||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType; | use Symfony\Component\Form\Extension\Core\Type\CollectionType; | ||||
GroupUserContainer::class => GroupUserContainer::class, | GroupUserContainer::class => GroupUserContainer::class, | ||||
UserContainer::class => UserContainer::class, | UserContainer::class => UserContainer::class, | ||||
SiteSettingContainer::class => SiteSettingContainer::class, | SiteSettingContainer::class => SiteSettingContainer::class, | ||||
MailMailjetNotification::class => MailMailjetNotification::class, | |||||
] | ] | ||||
); | ); | ||||
} | } |
use Symfony\Component\Form\Extension\Core\Type\DateTimeType; | use Symfony\Component\Form\Extension\Core\Type\DateTimeType; | ||||
use Symfony\Component\Form\Extension\Core\Type\DateType; | use Symfony\Component\Form\Extension\Core\Type\DateType; | ||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType; | use Symfony\Component\Form\Extension\Core\Type\IntegerType; | ||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType; | |||||
use Symfony\Component\Form\Extension\Core\Type\TextType; | use Symfony\Component\Form\Extension\Core\Type\TextType; | ||||
use Symfony\Component\Form\Form; | use Symfony\Component\Form\Form; | ||||
use Symfony\Component\HttpFoundation\RequestStack; | use Symfony\Component\HttpFoundation\RequestStack; | ||||
public function handleFiltersForm(QueryBuilder $queryBuilder, Form $filtersForm, $fields, EntityDto $entityDto) | public function handleFiltersForm(QueryBuilder $queryBuilder, Form $filtersForm, $fields, EntityDto $entityDto) | ||||
{ | { | ||||
foreach ($fields as $field) { | foreach ($fields as $field) { | ||||
$filteredValue = array(); | |||||
if ($field instanceof FieldInterface) { | if ($field instanceof FieldInterface) { | ||||
$fieldDto = $field->getAsDto(); | $fieldDto = $field->getAsDto(); | ||||
} else { | } else { | ||||
if ($fieldDto->isDisplayedOn(Crud::PAGE_INDEX)) { | if ($fieldDto->isDisplayedOn(Crud::PAGE_INDEX)) { | ||||
if ($filtersForm->has($this->getFieldPropertySnake($fieldDto->getProperty()))) { | if ($filtersForm->has($this->getFieldPropertySnake($fieldDto->getProperty()))) { | ||||
if ($fieldDto->getFormType() === DateTimeType::class || $fieldDto->getFormType( | |||||
) === DateType::class) { | |||||
if ($fieldDto->getFormType() === DateTimeType::class || $fieldDto->getFormType() === DateType::class) { | |||||
$filteredValue['dateStart'] = $this->getFilteredValue( | $filteredValue['dateStart'] = $this->getFilteredValue( | ||||
$filtersForm, | |||||
$entityDto->getFqcn(), | |||||
$fieldDto->getProperty(), | |||||
'dateStart' | |||||
$filtersForm, | |||||
$entityDto->getFqcn(), | |||||
$fieldDto->getProperty(), | |||||
'dateStart' | |||||
); | ); | ||||
$filteredValue['dateEnd'] = $this->getFilteredValue( | $filteredValue['dateEnd'] = $this->getFilteredValue( | ||||
$filtersForm, | |||||
$entityDto->getFqcn(), | |||||
$fieldDto->getProperty(), | |||||
'dateEnd' | |||||
$filtersForm, | |||||
$entityDto->getFqcn(), | |||||
$fieldDto->getProperty(), | |||||
'dateEnd' | |||||
); | ); | ||||
}else{ | |||||
$filteredValue = $this->getFilteredValue( | |||||
$filtersForm, | |||||
$entityDto->getFqcn(), | |||||
$fieldDto->getProperty() | |||||
} else { | |||||
$filteredValue['value'] = $this->getFilteredValue( | |||||
$filtersForm, | |||||
$entityDto->getFqcn(), | |||||
$fieldDto->getProperty() | |||||
); | ); | ||||
} | } | ||||
$this->applyFilter($queryBuilder, $fieldDto, $filteredValue); | $this->applyFilter($queryBuilder, $fieldDto, $filteredValue); | ||||
} | } | ||||
} | } | ||||
public function applyFilter(QueryBuilder $queryBuilder, FieldDto $fieldDto, $filteredValue) | |||||
public function applyFilter(QueryBuilder $queryBuilder, FieldDto $fieldDto, array $filteredValue) | |||||
{ | { | ||||
switch ($fieldDto->getFormType()) { | switch ($fieldDto->getFormType()) { | ||||
case CheckboxType::class: | case CheckboxType::class: | ||||
$checkboxFilter = new CheckboxFilter(); | $checkboxFilter = new CheckboxFilter(); | ||||
$checkboxFilter->applyFilter($queryBuilder, $fieldDto->getProperty(), $filteredValue); | |||||
$checkboxFilter->applyFilter($queryBuilder, $fieldDto->getProperty(), $filteredValue['value']); | |||||
break; | break; | ||||
case ChoiceType::class: | case ChoiceType::class: | ||||
$choiceFilter = new ChoiceFilter(); | $choiceFilter = new ChoiceFilter(); | ||||
$choiceFilter->applyFilter($queryBuilder, $fieldDto->getProperty(), $filteredValue); | |||||
$choiceFilter->applyFilter($queryBuilder, $fieldDto->getProperty(), $filteredValue['value']); | |||||
break; | break; | ||||
case IntegerType::class: | case IntegerType::class: | ||||
$integerFilter = new IntegerFilter(); | $integerFilter = new IntegerFilter(); | ||||
$integerFilter->applyFilter($queryBuilder, $fieldDto->getProperty(), $filteredValue); | |||||
$integerFilter->applyFilter($queryBuilder, $fieldDto->getProperty(), $filteredValue['value']); | |||||
break; | break; | ||||
case TextareaType::class: | |||||
case TextType::class: | case TextType::class: | ||||
$textFilter = new TextFilter(); | $textFilter = new TextFilter(); | ||||
$textFilter->applyFilter($queryBuilder, $fieldDto->getProperty(), $filteredValue); | |||||
$textFilter->applyFilter($queryBuilder, $fieldDto->getProperty(), $filteredValue['value']); | |||||
break; | break; | ||||
case EntityType::class: | case EntityType::class: | ||||
$textFilter = new AssociationFilter(); | $textFilter = new AssociationFilter(); | ||||
$textFilter->applyFilter($queryBuilder, $fieldDto->getProperty(), $filteredValue); | |||||
$textFilter->applyFilter($queryBuilder, $fieldDto->getProperty(), $filteredValue['value']); | |||||
break; | break; | ||||
case DateTimeType::class: | case DateTimeType::class: | ||||
case DateType::class: | case DateType::class: | ||||
$textFilter = new DateFilter(); | $textFilter = new DateFilter(); | ||||
$textFilter->applyFilter( | $textFilter->applyFilter( | ||||
$queryBuilder, | |||||
$fieldDto->getProperty(), | |||||
$filteredValue['dateStart'], | |||||
$filteredValue['dateEnd'] | |||||
$queryBuilder, | |||||
$fieldDto->getProperty(), | |||||
$filteredValue['dateStart'], | |||||
$filteredValue['dateEnd'] | |||||
); | ); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
public function getFilteredValue( | public function getFilteredValue( | ||||
Form $filtersForm, | |||||
string $entityFqcn, | |||||
string $field, | |||||
string $dateExtraField = null | |||||
) { | |||||
Form $filtersForm, | |||||
string $entityFqcn, | |||||
string $field, | |||||
string $dateExtraField = null | |||||
) | |||||
{ | |||||
$field = $this->getFieldPropertySnake($field); | $field = $this->getFieldPropertySnake($field); | ||||
$sessionParam = $entityFqcn.$field.$dateExtraField; | |||||
$sessionParam = $entityFqcn . $field . $dateExtraField; | |||||
$formField = $this->getFormField($filtersForm, $field, $dateExtraField); | $formField = $this->getFormField($filtersForm, $field, $dateExtraField); | ||||
//Champ association | //Champ association | ||||
} elseif ($formField->getConfig()->getOption('class')) { | } elseif ($formField->getConfig()->getOption('class')) { | ||||
$valFormated = $this->em->getRepository( | $valFormated = $this->em->getRepository( | ||||
$formField->getConfig()->getOption('class') | |||||
$formField->getConfig()->getOption('class') | |||||
)->find($value); | )->find($value); | ||||
$filtersForm->get($field)->setData($valFormated); | $filtersForm->get($field)->setData($valFormated); | ||||
} else { | } else { | ||||
public | public | ||||
function getFormField( | function getFormField( | ||||
Form $filtersForm, | |||||
string $field, | |||||
string $extraField = null | |||||
): Form { | |||||
Form $filtersForm, | |||||
string $field, | |||||
string $extraField = null | |||||
): Form | |||||
{ | |||||
if ($extraField) { | if ($extraField) { | ||||
return $filtersForm->get($field)->get($extraField); | return $filtersForm->get($field)->get($extraField); | ||||
} else { | } else { |
$formPanels = []; | $formPanels = []; | ||||
$currentFormPanel = 0; | $currentFormPanel = 0; | ||||
foreach ($entityDto->getFields() as $fieldDto) { | foreach ($entityDto->getFields() as $fieldDto) { | ||||
dump($fieldDto); | |||||
dump( $fieldDto->getFormType()); | |||||
if (null === $formFieldType = $fieldDto->getFormType()) { | if (null === $formFieldType = $fieldDto->getFormType()) { | ||||
$guessType = $this->doctrineOrmTypeGuesser->guessType($entityDto->getFqcn(), $fieldDto->getProperty()); | $guessType = $this->doctrineOrmTypeGuesser->guessType($entityDto->getFqcn(), $fieldDto->getProperty()); | ||||
$formFieldType = $guessType->getType(); | $formFieldType = $guessType->getType(); |
use Symfony\Component\Form\Extension\Core\Type\HiddenType; | use Symfony\Component\Form\Extension\Core\Type\HiddenType; | ||||
use Symfony\Component\Form\Extension\Core\Type\IntegerType; | use Symfony\Component\Form\Extension\Core\Type\IntegerType; | ||||
use Symfony\Component\Form\Extension\Core\Type\SubmitType; | use Symfony\Component\Form\Extension\Core\Type\SubmitType; | ||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType; | |||||
use Symfony\Component\Form\Extension\Core\Type\TextType; | use Symfony\Component\Form\Extension\Core\Type\TextType; | ||||
use Symfony\Component\Form\FormBuilderInterface; | use Symfony\Component\Form\FormBuilderInterface; | ||||
use Symfony\Component\OptionsResolver\OptionsResolver; | use Symfony\Component\OptionsResolver\OptionsResolver; | ||||
$fieldDto = $field; | $fieldDto = $field; | ||||
} | } | ||||
if ($fieldDto->isDisplayedOn(Crud::PAGE_INDEX)) { | if ($fieldDto->isDisplayedOn(Crud::PAGE_INDEX)) { | ||||
dump($fieldDto); | |||||
switch ($fieldDto->getFormType()) { | switch ($fieldDto->getFormType()) { | ||||
case CheckboxType::class: | case CheckboxType::class: | ||||
$checkboxFilter = new CheckboxFilter(); | $checkboxFilter = new CheckboxFilter(); | ||||
break; | break; | ||||
case TextType::class: | case TextType::class: | ||||
case TextareaType::class: | |||||
$textFilter = new TextFilter(); | $textFilter = new TextFilter(); | ||||
$textFilter->buildProperty($builder, $fieldDto); | $textFilter->buildProperty($builder, $fieldDto); | ||||
break; | break; | ||||
$textFilter->buildProperty($builder, $fieldDto); | $textFilter->buildProperty($builder, $fieldDto); | ||||
break; | break; | ||||
case EntityType::class: | case EntityType::class: | ||||
// $associationFilter = new AssociationFilter(); | |||||
// $associationFilter->buildProperty($builder, $fieldDto, $options); | |||||
//$associationFilter = new AssociationFilter(); | |||||
//$associationFilter->buildProperty($builder, $fieldDto, $options); | |||||
break; | break; | ||||
case 'dateinterval': | case 'dateinterval': | ||||
} | } | ||||
} | } | ||||
$builder->add( | $builder->add( | ||||
'action_apply', | |||||
SubmitType::class, | |||||
array( | |||||
'label_html'=> true, | |||||
'label'=> '<i class="fa fa-search"></i>', | |||||
'attr' => array( | |||||
'class' => 'btn btn-sm btn-info', | |||||
'form' => 'filters-form', | |||||
'data-toggle'=>"tooltip", | |||||
'title'=> $this->translatorAdmin->transAction("apply"), | |||||
'aria-label'=> $this->translatorAdmin->transAction("apply") | |||||
), | |||||
) | |||||
'action_apply', | |||||
SubmitType::class, | |||||
array( | |||||
'label_html' => true, | |||||
'label' => '<i class="fa fa-search"></i>', | |||||
'attr' => array( | |||||
'class' => 'btn btn-sm btn-info', | |||||
'form' => 'filters-form', | |||||
'data-toggle' => "tooltip", | |||||
'title' => $this->translatorAdmin->transAction("apply"), | |||||
'aria-label' => $this->translatorAdmin->transAction("apply") | |||||
), | |||||
) | |||||
); | ); | ||||
$builder->add( | $builder->add( | ||||
'action_reset', | |||||
ButtonType::class, | |||||
array( | |||||
'label_html'=> true, | |||||
'label'=> '<i class="fa fa-eraser"></i>', | |||||
'attr' => array( | |||||
'class' => 'btn btn-sm btn-warning lc-reset-filters', | |||||
'form' => 'filters-form', | |||||
'data-toggle'=>"tooltip", | |||||
'title'=> $this->translatorAdmin->transAction("reset"), | |||||
'aria-label'=> $this->translatorAdmin->transAction("reset") | |||||
), | |||||
) | |||||
'action_reset', | |||||
SubmitType::class, | |||||
array( | |||||
'label_html' => true, | |||||
'label' => '<i class="fa fa-eraser"></i>', | |||||
'attr' => array( | |||||
'class' => 'btn btn-sm btn-warning lc-reset-filters', | |||||
'form' => 'filters-form', | |||||
'data-toggle' => "tooltip", | |||||
'title' => $this->translatorAdmin->transAction("reset"), | |||||
'aria-label' => $this->translatorAdmin->transAction("reset") | |||||
), | |||||
) | |||||
); | ); | ||||
$builder->add('reset', HiddenType::class); | $builder->add('reset', HiddenType::class); | ||||
} | } | ||||
public function configureOptions(OptionsResolver $resolver) | public function configureOptions(OptionsResolver $resolver) | ||||
{ | { | ||||
$resolver->setDefaults( | $resolver->setDefaults( | ||||
[ | |||||
'label' => false, | |||||
'csrf_protection' => false, | |||||
'entity_dto' => null, | |||||
//'translation_domain' => 'lcshop', | |||||
'fields' => false, | |||||
'entity_name' => false, | |||||
'entity_class' => false, | |||||
//'entityClass' => false | |||||
] | |||||
[ | |||||
'label' => false, | |||||
'csrf_protection' => false, | |||||
'entity_dto' => null, | |||||
//'translation_domain' => 'lcshop', | |||||
'fields' => false, | |||||
'entity_name' => false, | |||||
'entity_class' => false, | |||||
//'entityClass' => false | |||||
] | |||||
); | ); | ||||
} | } | ||||
} | } |
<?php | |||||
namespace Lc\SovBundle\Notification; | |||||
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition; | |||||
use Lc\CaracoleBundle\Resolver\MerchantResolver; | |||||
use Lc\SovBundle\Solver\Setting\SettingSolver; | |||||
use Mailjet\MailjetSwiftMailer\SwiftMailer\MailjetTransport; | |||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | |||||
use Twig\Environment; | |||||
class MailMailjetNotification | |||||
{ | |||||
const SUBJECT = 'subject'; | |||||
const SUBJECT_PREFIX = 'subject-prefix'; | |||||
const TO_EMAIL = 'to-email'; | |||||
const COPY_TO = 'copy-to'; | |||||
const COPY_HIDDEN_TO = 'copy-hidden-to'; | |||||
const TO_NAME = 'to-name'; | |||||
const FROM_EMAIL = 'from-email'; | |||||
const FROM_NAME = 'from-name'; | |||||
const REPLY_TO = 'reply-to'; | |||||
const CONTENT_TEMPLATE = 'content-template'; | |||||
const CONTENT_DATA = 'content-data'; | |||||
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; | |||||
public function __construct( | |||||
MailjetTransport $mailjetTransport, | |||||
Environment $templating, | |||||
ParameterBagInterface $parameterBag, | |||||
MerchantResolver $merchantResolver, | |||||
SettingSolver $settingSolver | |||||
) | |||||
{ | |||||
$this->transport = $mailjetTransport; | |||||
$this->templating = $templating; | |||||
$this->parameterBag = $parameterBag; | |||||
$this->merchantResolver = $merchantResolver; | |||||
$this->settingSolver = $settingSolver; | |||||
} | |||||
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 .= ' '; | |||||
} | |||||
$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); | |||||
} else { | |||||
$message->addTo( | |||||
$params[self::TO_EMAIL], | |||||
isset($params[self::TO_NAME]) ?? null); | |||||
} | |||||
$contentData = []; | |||||
if (isset($params[self::CONTENT_DATA])) { | |||||
$contentData = $params[self::CONTENT_DATA]; | |||||
} | |||||
dump($emailFrom); | |||||
$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)); | |||||
if (isset($params[self::COPY_TO]) && strlen($params[self::COPY_TO])) { | |||||
$message->addCc($params[self::COPY_TO]); | |||||
} | |||||
if (isset($params[self::COPY_HIDDEN_TO]) && strlen($params[self::COPY_HIDDEN_TO])) { | |||||
$message->addBcc($params[self::COPY_HIDDEN_TO]); | |||||
} | |||||
if (isset($params[self::REPLY_TO]) && strlen($params[self::REPLY_TO])) { | |||||
$message->addReplyTo($params[self::REPLY_TO]); | |||||
} | |||||
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] | |||||
)); | |||||
} | |||||
/*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); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\SovBundle\Notification; | |||||
use Lc\SovBundle\Component\StringComponent; | |||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | |||||
use Symfony\Contracts\HttpClient\HttpClientInterface; | |||||
use Twig\Environment; | |||||
class SmsFactorNotification | |||||
{ | |||||
const TO_USER = 'to-user'; | |||||
const CONTENT_MESSAGE = 'content-message'; | |||||
const CONTENT_TEMPLATE = 'content-template'; | |||||
const CONTENT_DATA = 'content-data'; | |||||
protected HttpClientInterface $client; | |||||
protected ParameterBagInterface $parameterBag; | |||||
protected MailMailjetNotification $mailMailjetNotification; | |||||
protected StringComponent $stringComponent; | |||||
protected Environment $templating; | |||||
public function __construct( | |||||
HttpClientInterface $client, | |||||
ParameterBagInterface $parameterBag, | |||||
MailMailjetNotification $mailMailjetNotification, | |||||
StringComponent $stringComponent, | |||||
Environment $templating | |||||
) | |||||
{ | |||||
$this->client = $client; | |||||
$this->parameterBag = $parameterBag; | |||||
$this->mailMailjetNotification = $mailMailjetNotification; | |||||
$this->stringComponent = $stringComponent; | |||||
$this->templating = $templating; | |||||
} | |||||
public function send($params = []) | |||||
{ | |||||
$user = isset($params[self::TO_USER]) ? $params[self::TO_USER] : null; | |||||
if ($user) { | |||||
$phone = $this->stringComponent->formatPhoneNumber($user->getPhone()); | |||||
$message = ''; | |||||
if (isset($params[self::CONTENT_MESSAGE])) { | |||||
$message = $params[self::CONTENT_MESSAGE]; | |||||
} elseif (isset($params[self::CONTENT_TEMPLATE])) { | |||||
$template = $params[self::CONTENT_TEMPLATE]; | |||||
$paramsTemplate = []; | |||||
if (isset($params[self::CONTENT_DATA]) && is_array($params[self::CONTENT_DATA])) { | |||||
$paramsTemplate = $params[self::CONTENT_DATA]; | |||||
} | |||||
$message = $this->templating->render($template, $paramsTemplate); | |||||
} | |||||
if ($this->parameterBag->get('mailjet.dev.redirect.active') == 1) { | |||||
$this->mailMailjetNotification->send([ | |||||
MailMailjetNotification::SUBJECT => 'Notification par SMS à ' . $phone, | |||||
MailMailjetNotification::TO_EMAIL => $user->getEmail(), | |||||
MailMailjetNotification::CONTENT_TEMPLATE => 'mail/notification', | |||||
MailMailjetNotification::CONTENT_DATA => [ | |||||
'message' => $message | |||||
], | |||||
]); | |||||
return true; | |||||
} else { | |||||
$token = $this->parameterBag->get('smsfactor.token'); | |||||
$from = $this->parameterBag->get('smsfactor.from'); | |||||
if ($token && strlen($token) > 0) { | |||||
$response = $this->client->request( | |||||
'GET', | |||||
'https://api.smsfactor.com/send', | |||||
[ | |||||
'headers' => [ | |||||
'Authorization' => 'Bearer ' . $token, | |||||
'Content-Type' => 'application/json; charset=utf-8', | |||||
'Accept' => 'application/json' | |||||
], | |||||
'query' => [ | |||||
'sender' => $from, | |||||
'to' => $phone, | |||||
'text' => $message, | |||||
], | |||||
] | |||||
); | |||||
return $response; | |||||
} else { | |||||
throw new \ErrorException('Le token SMS SmsFactor n\'est pas défini.'); | |||||
} | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
} |
{% trans_default_domain ea.i18n.translationDomain %} | {% trans_default_domain ea.i18n.translationDomain %} | ||||
{% block content_title %} | {% block content_title %} | ||||
{{ 'detail'|sov_trans_admin_title(ea.getEntity().getFqcn()) }} | |||||
{{ 'detail'|sov_trans_admin_title(ea.getEntity().getFqcn(), {id: ea.getEntity().getInstance().getId()}) }} | |||||
{% endblock %} | {% endblock %} | ||||
{% block content_breadcrumb %} | {% block content_breadcrumb %} |
<div class="card {% block class %}{% endblock %}" id="{% block id %}{% endblock %}"> | |||||
<div class="card {% block class %}{% endblock %}" id="{% block id %}{% endblock %}" {% block attr %}{% endblock %}> | |||||
{% block header_wrapper %} | {% block header_wrapper %} | ||||
<div class="card-header {% block header_class %}{% endblock %}"> | <div class="card-header {% block header_class %}{% endblock %}"> | ||||
{% block header %} | {% block header %} |
<div class="info-box-content"> | <div class="info-box-content"> | ||||
<span class="info-box-text">{% block title %}{% endblock %}</span> | <span class="info-box-text">{% block title %}{% endblock %}</span> | ||||
<span class="info-box-number">{% block content %}{% endblock %}</span> | <span class="info-box-number">{% block content %}{% endblock %}</span> | ||||
<div class="float-right"> | |||||
<div class="text-right"> | |||||
{% block button %}{% endblock %} | {% block button %}{% endblock %} | ||||
</div> | </div> | ||||
</div> | </div> |
); | ); | ||||
} | } | ||||
public function transModal($modalName, $entityClass): string | |||||
{ | |||||
return $this->transEntityThenDefault( | |||||
$this->buildTransIdModal($modalName, $entityClass), | |||||
$this->buildTransIdModal($modalName, $entityClass, true) | |||||
); | |||||
} | |||||
public function transCard($cardName, $entityClass): string | public function transCard($cardName, $entityClass): string | ||||
{ | { | ||||
return $this->transEntityThenDefault( | return $this->transEntityThenDefault( | ||||
return $this->buildTransIdEntitySection($panelName, $entityClass, 'panels', $default); | return $this->buildTransIdEntitySection($panelName, $entityClass, 'panels', $default); | ||||
} | } | ||||
private function buildTransIdModal($modalName, $entityClass, $default = false): string | |||||
{ | |||||
return $this->buildTransIdEntitySection($modalName, $entityClass, 'modals', $default); | |||||
} | |||||
private function buildTransIdCard($cardName, $entityClass, $default = false): string | private function buildTransIdCard($cardName, $entityClass, $default = false): string | ||||
{ | { | ||||
return $this->buildTransIdEntitySection($cardName, $entityClass, 'cards', $default); | return $this->buildTransIdEntitySection($cardName, $entityClass, 'cards', $default); |
new TwigFilter('sov_trans_admin_field', [$this, 'transAdminField']), | new TwigFilter('sov_trans_admin_field', [$this, 'transAdminField']), | ||||
new TwigFilter('sov_trans_admin_help', [$this, 'transAdminHelp']), | new TwigFilter('sov_trans_admin_help', [$this, 'transAdminHelp']), | ||||
new TwigFilter('sov_trans_admin_panel', [$this, 'transAdminPanel']), | new TwigFilter('sov_trans_admin_panel', [$this, 'transAdminPanel']), | ||||
new TwigFilter('sov_trans_admin_modal', [$this, 'transAdminModal']), | |||||
new TwigFilter('sov_trans_admin_card', [$this, 'transAdminCard']), | new TwigFilter('sov_trans_admin_card', [$this, 'transAdminCard']), | ||||
new TwigFilter('sov_trans_admin_box', [$this, 'transAdminBox']), | new TwigFilter('sov_trans_admin_box', [$this, 'transAdminBox']), | ||||
new TwigFilter('sov_trans_admin_menu', [$this, 'transAdminMenu']), | new TwigFilter('sov_trans_admin_menu', [$this, 'transAdminMenu']), | ||||
new TwigFilter('sov_trans_admin_title', [$this, 'transAdminTitle']), | new TwigFilter('sov_trans_admin_title', [$this, 'transAdminTitle']), | ||||
new TwigFilter('sov_trans_admin_action', [$this, 'transAdminAction']), | new TwigFilter('sov_trans_admin_action', [$this, 'transAdminAction']), | ||||
new TwigFilter('sov_trans_admin_choice', [$this, 'transAdminChoice']), | |||||
]; | ]; | ||||
} | } | ||||
return $this->translatorAdmin->transField($fieldName, $entityClass); | return $this->translatorAdmin->transField($fieldName, $entityClass); | ||||
} | } | ||||
public function transAdminChoice($choice, $fieldName, $entityClass) | |||||
{ | |||||
return $this->translatorAdmin->transChoice($entityClass, $fieldName, $choice); | |||||
} | |||||
public function transAdminHelp($fieldName, $entityClass) | public function transAdminHelp($fieldName, $entityClass) | ||||
{ | { | ||||
return $this->translatorAdmin->transHelp($fieldName, $entityClass); | return $this->translatorAdmin->transHelp($fieldName, $entityClass); | ||||
{ | { | ||||
return $this->translatorAdmin->transPanel($panelName, $entityClass); | return $this->translatorAdmin->transPanel($panelName, $entityClass); | ||||
} | } | ||||
public function transAdminModal($modalName, $entityClass) | |||||
{ | |||||
return $this->translatorAdmin->transModal($modalName, $entityClass); | |||||
} | |||||
public function transAdminBox($boxName, $entityClass= 'default') | public function transAdminBox($boxName, $entityClass= 'default') | ||||
{ | { |