Bladeren bron

Script d'import

develop
Fab 3 jaren geleden
bovenliggende
commit
2a14fac273
13 gewijzigde bestanden met toevoegingen van 424 en 9 verwijderingen
  1. +123
    -2
      Builder/Ticket/TicketBuilder.php
  2. +75
    -0
      Builder/Ticket/TicketMessageBuilder.php
  3. +4
    -2
      Builder/User/UserBuilder.php
  4. +2
    -0
      Component/FormComponent.php
  5. +102
    -0
      Container/ComponentContainer.php
  6. +10
    -1
      Container/Ticket/TicketMessageContainer.php
  7. +2
    -1
      Controller/AbstractAdminController.php
  8. +48
    -0
      Form/Newsletter/NewsletterType.php
  9. +6
    -0
      Repository/Ticket/TicketMessageRepositoryQuery.php
  10. +9
    -1
      Repository/Ticket/TicketMessageStore.php
  11. +1
    -1
      Repository/Ticket/TicketStore.php
  12. +29
    -0
      Twig/SettingTwigExtension.php
  13. +13
    -1
      Twig/TwigExtension.php

+ 123
- 2
Builder/Ticket/TicketBuilder.php Bestand weergeven

@@ -2,18 +2,139 @@

namespace Lc\SovBundle\Builder\Ticket;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Notification\MailMailjetNotification;
use Lc\SovBundle\Component\FormComponent;
use Lc\SovBundle\Factory\Ticket\TicketFactory;
use Lc\SovBundle\Model\Ticket\TicketInterface;
use Lc\SovBundle\Model\Ticket\TicketMessageInterface;
use Lc\SovBundle\Model\Ticket\TicketModel;
use Lc\SovBundle\Repository\User\UserStore;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;

class TicketBuilder
{
protected EntityManagerInterface $entityManager;
protected MailMailjetNotification $mailMailjetNotification;
protected FormComponent $formComponent;
protected ParameterBagInterface $parameterBag;
protected TicketFactory $ticketFactory;
protected AuthorizationCheckerInterface $authorizationChecker;
protected UserStore $userStore;

public function __construct(FormComponent $formComponent, ParameterBagInterface $parameterBag)
{
public function __construct(
EntityManagerInterface $entityManager,
MailMailjetNotification $mailMailjetNotification,
FormComponent $formComponent,
ParameterBagInterface $parameterBag,
AuthorizationCheckerInterface $authorizationChecker,
TicketFactory $ticketFactory,
UserStore $userStore
) {
$this->entityManager = $entityManager;
$this->mailMailjetNotification = $mailMailjetNotification;
$this->formComponent = $formComponent;
$this->parameterBag = $parameterBag;
$this->ticketFactory = $ticketFactory;
$this->userStore = $userStore;
}

public function create(array $params = []): TicketInterface
{
$ticket = $this->ticketFactory->create();

$this->init($ticket, $params);

$user = $ticket->getUser();
if ($ticket->getUser()) {
$email = $user->getEmail();
$firstname = $user->getFirstname();
} else {
$email = $params['visitorEmail'];
$firstname = $params['visitorFirstname'];
}

if (isset($params['createByAdmin']) && $params['createByAdmin']) {
// envoi email au client
$this->mailMailjetNotification->send(
[
MailMailjetNotification::SUBJECT => 'Vous avez reçu un nouveau message',
MailMailjetNotification::TO_EMAIL => $email,
MailMailjetNotification::CONTENT_TEMPLATE => 'mail/ticket-new-by-admin',
MailMailjetNotification::CONTENT_DATA => [
'firstname' => $firstname,
'ticket' => $ticket,
],
]
);
} else {
$this->mailMailjetNotification->send(
[
MailMailjetNotification::SUBJECT => 'Nouvelle demande',
MailMailjetNotification::TO_EMAIL => $email,
MailMailjetNotification::CONTENT_TEMPLATE => 'mail/ticket-new',
MailMailjetNotification::CONTENT_DATA => [
'firstname' => $firstname,
'ticket' => $ticket,
],
]
);
}

$this->entityManager->persist($ticket);
$this->entityManager->flush();

// notifyAdmin
$usersToNotify = $this->userStore->getByTicketTypesNotification($ticket->getType());

foreach ($usersToNotify as $userToNotify) {
if ($this->authorizationChecker->isGranted('ROLE_ADMIN', $userToNotify)) {
$this->mailMailjetNotification->send(
[
MailMailjetNotification::SUBJECT => 'Nouveau ticket sur Place du Local',
MailMailjetNotification::TO_EMAIL => $userToNotify->getEmail(),
MailMailjetNotification::CONTENT_TEMPLATE => 'mail/ticket-notification',
MailMailjetNotification::CONTENT_DATA => [
'firstname' => $userToNotify->getFirstname(),
'ticket' => $ticket,
'ticketMessage' => $ticket->getTicketMessage(),
],
]
);
}
}

return $ticket;
}

public function init(TicketInterface $ticket, array $params = []): void
{
if (isset($params['user'])) {
$ticket->setUser($params['user']);
} else {
$ticket->setVisitorFirstname($params['visitorFirstname']);
$ticket->setVisitorLastname($params['visitorLastname']);
$ticket->setVisitorEmail($params['visitorEmail']);
$ticket->setVisitorToken(uniqid());
}

$ticket
->setStatus(TicketModel::TICKET_STATUS_OPEN)
->setType($params['type'])
->setSubject($params['subject']);

$ticketMessage = $ticket->getTicketMessage();
$ticketMessage->setStatus(1);
$ticketMessage->setMessage($params['message']);

if (isset($params['imageFilename']) && $params['imageFilename']) {
$ticketMessage->setImageFilename($params['imageFilename']);
}

if (isset($params['createByAdmin']) && $params['createByAdmin']) {
$ticketMessage->setAnswerByAdmin(true);
}
}

// uploadImageTicketMessage

+ 75
- 0
Builder/Ticket/TicketMessageBuilder.php Bestand weergeven

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

namespace Lc\SovBundle\Builder\Ticket;

use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Notification\MailMailjetNotification;
use Lc\SovBundle\Component\FormComponent;
use Lc\SovBundle\Factory\Ticket\TicketFactory;
use Lc\SovBundle\Factory\Ticket\TicketMessageFactory;
use Lc\SovBundle\Model\Ticket\TicketInterface;
use Lc\SovBundle\Model\Ticket\TicketMessageInterface;
use Lc\SovBundle\Model\Ticket\TicketModel;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;

class TicketMessageBuilder
{
protected EntityManagerInterface $entityManager;
protected MailMailjetNotification $mailMailjetNotification;
protected TicketMessageFactory $ticketMessageFactory;

public function __construct(
EntityManagerInterface $entityManager,
MailMailjetNotification $mailMailjetNotification,
TicketMessageFactory $ticketMessageFactory
) {
$this->entityManager = $entityManager;
$this->mailMailjetNotification = $mailMailjetNotification;
$this->ticketMessageFactory = $ticketMessageFactory;
}

public function create(array $params = []): TicketMessageInterface
{
$ticket = $params['ticket'];
$ticketMessage = $this->ticketMessageFactory->create($ticket);

$ticketMessage->setStatus(1);
$ticketMessage->setTicket($ticket);
$ticketMessage->setMessage($params['message']);

if (isset($params['answerByAdmin']) && $params['answerByAdmin']) {
$ticketMessage->setAnswerByAdmin($params['answerByAdmin']);

// envoi email au client
$this->mailMailjetNotification->send(
[
MailMailjetNotification::SUBJECT => 'Réponse à votre demande',
MailMailjetNotification::TO_EMAIL => $ticket->getUser() ? $ticket->getUser()->getEmail(
) : $ticket->getVisitorEmail(),
MailMailjetNotification::CONTENT_TEMPLATE => 'mail/ticket-response',
MailMailjetNotification::CONTENT_DATA => [
'firstname' => $ticket->getUser() ? $ticket->getUser()->getFirstname(
) : $ticket->getVisitorFirstname(),
'ticket' => $ticket,
],
]
);
}
$this->entityManager->persist($ticketMessage);

if (isset($params['imageFilename']) && $params['imageFilename']) {
$ticketMessage->setImageFilename($params['imageFilename']);
}
if (isset($params['closeTicket']) && $params['closeTicket']) {
$ticket->setStatus(TicketModel::TICKET_STATUS_CLOSED);
}

$ticket->setUpdatedAt(new \DateTime());

$this->entityManager->persist($ticket);
$this->entityManager->flush();

return $ticketMessage;
}

}

+ 4
- 2
Builder/User/UserBuilder.php Bestand weergeven

@@ -8,16 +8,18 @@ use Lc\SovBundle\Doctrine\Extension\BlameableInterface;
use Lc\SovBundle\Model\Newsletter\NewsletterInterface;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\User\UserStore;
use Lc\SovBundle\Solver\User\UserSolver;

class UserBuilder
{
protected EntityManagerInterface $entityManager;
protected UserStore $userStore;
public function __construct(EntityManagerInterface $entityManager, UserStore $userStore)
protected UserSolver $userSolver;
public function __construct(EntityManagerInterface $entityManager, UserStore $userStore, UserSolver $userSolver)
{
$this->entityManager = $entityManager;
$this->userStore = $userStore;
$this->userSolver = $userSolver;
}

public function setNewsletter(UserInterface $user, NewsletterInterface $newsletter, bool $subscribeNewsletter): void

+ 2
- 0
Component/FormComponent.php Bestand weergeven

@@ -6,6 +6,8 @@ use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\Validator\Constraints\EqualTo;
use Symfony\Component\Validator\Constraints\NotNull;

class FormComponent
{

+ 102
- 0
Container/ComponentContainer.php Bestand weergeven

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

namespace Lc\SovBundle\Container;

use Lc\SovBundle\Component\CitiesComponent;
use Lc\SovBundle\Component\CookieComponent;
use Lc\SovBundle\Component\DateComponent;
use Lc\SovBundle\Component\EntityComponent;
use Lc\SovBundle\Component\FileComponent;
use Lc\SovBundle\Component\FormComponent;
use Lc\SovBundle\Component\MetaComponent;
use Lc\SovBundle\Component\NumberComponent;
use Lc\SovBundle\Component\PointLocationComponent;
use Lc\SovBundle\Component\StringComponent;

class ComponentContainer
{
protected CitiesComponent $citiesComponent;
protected CookieComponent $cookieComponent;
protected DateComponent $dateComponent;
protected EntityComponent $entityComponent;
protected FileComponent $fileComponent;
protected FormComponent $formComponent;
protected MetaComponent $metaComponent;
protected NumberComponent $numberComponent;
protected PointLocationComponent $pointLocationComponent;
protected StringComponent $stringComponent;

public function __construct(
CitiesComponent $citiesComponent,
CookieComponent $cookieComponent,
DateComponent $dateComponent,
EntityComponent $entityComponent,
FileComponent $fileComponent,
FormComponent $formComponent,
MetaComponent $metaComponent,
NumberComponent $numberComponent,
PointLocationComponent $pointLocationComponent,
StringComponent $stringComponent
) {
$this->citiesComponent = $citiesComponent;
$this->cookieComponent = $cookieComponent;
$this->dateComponent = $dateComponent;
$this->entityComponent = $entityComponent;
$this->fileComponent = $fileComponent;
$this->formComponent = $formComponent;
$this->metaComponent = $metaComponent;
$this->numberComponent = $numberComponent;
$this->pointLocationComponent = $pointLocationComponent;
$this->stringComponent = $stringComponent;
}

public function getCitiesComponent(): CitiesComponent
{
return $this->citiesComponent;
}

public function getCookieComponent(): CookieComponent
{
return $this->cookieComponent;
}

public function getDateComponent(): DateComponent
{
return $this->dateComponent;
}

public function getEntityComponent(): EntityComponent
{
return $this->entityComponent;
}

public function getFileComponent(): FileComponent
{
return $this->fileComponent;
}

public function getFormComponent(): FormComponent
{
return $this->formComponent;
}

public function getMetaComponent(): MetaComponent
{
return $this->metaComponent;
}

public function getNumberComponent(): NumberComponent
{
return $this->numberComponent;
}

public function getPointLocationComponent(): PointLocationComponent
{
return $this->pointLocationComponent;
}

public function getStringComponent(): StringComponent
{
return $this->stringComponent;
}
}

+ 10
- 1
Container/Ticket/TicketMessageContainer.php Bestand weergeven

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

namespace Lc\SovBundle\Container\Ticket;

use Lc\SovBundle\Builder\Ticket\TicketMessageBuilder;
use Lc\SovBundle\Factory\Ticket\TicketMessageFactory;
use Lc\SovBundle\Repository\Ticket\TicketMessageRepositoryQuery;
use Lc\SovBundle\Repository\Ticket\TicketMessageStore;
@@ -11,15 +12,18 @@ class TicketMessageContainer
protected TicketMessageFactory $factory;
protected TicketMessageRepositoryQuery $repositoryQuery;
protected TicketMessageStore $store;
protected TicketMessageBuilder $builder;

public function __construct(
TicketMessageFactory $factory,
TicketMessageRepositoryQuery $repositoryQuery,
TicketMessageStore $store
TicketMessageStore $store,
TicketMessageBuilder $builder
) {
$this->factory = $factory;
$this->repositoryQuery = $repositoryQuery;
$this->store = $store;
$this->builder = $builder;
}

public function getFactory(): TicketMessageFactory
@@ -36,4 +40,9 @@ class TicketMessageContainer
{
return $this->store;
}

public function getBuilder(): TicketMessageBuilder
{
return $this->builder;
}
}

+ 2
- 1
Controller/AbstractAdminController.php Bestand weergeven

@@ -37,6 +37,7 @@ 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;
@@ -84,6 +85,7 @@ abstract class AbstractAdminController extends EaAbstractCrudController
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,
@@ -95,7 +97,6 @@ abstract class AbstractAdminController extends EaAbstractCrudController
GroupUserContainer::class => GroupUserContainer::class,
UserContainer::class => UserContainer::class,
SiteSettingContainer::class => SiteSettingContainer::class,

]
);
}

+ 48
- 0
Form/Newsletter/NewsletterType.php Bestand weergeven

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

namespace Lc\SovBundle\Form\Newsletter;

use Lc\SovBundle\Component\FormComponent;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\NotNull;

class NewsletterType extends AbstractType
{
protected FormComponent $formComponent;

public function __construct(FormComponent $formComponent)
{
$this->formComponent = $formComponent;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add(
'email',
EmailType::class,
[
'label' => 'Renseignez votre adresse email :',
'constraints' => [
new Email(),
new NotNull()
]
]
);

// captcha
$this->formComponent->addCaptchaType($builder);
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[

]
);
}
}

+ 6
- 0
Repository/Ticket/TicketMessageRepositoryQuery.php Bestand weergeven

@@ -3,6 +3,7 @@
namespace Lc\SovBundle\Repository\Ticket;

use Knp\Component\Pager\PaginatorInterface;
use Lc\SovBundle\Model\Ticket\TicketInterface;
use Lc\SovBundle\Repository\AbstractRepositoryQuery;

class TicketMessageRepositoryQuery extends AbstractRepositoryQuery implements TicketMessageRepositoryQueryInterface
@@ -11,4 +12,9 @@ class TicketMessageRepositoryQuery extends AbstractRepositoryQuery implements Ti
{
parent::__construct($repository, 'r', $paginator);
}

public function filterByTicket(TicketInterface $ticket)
{
return $this->andWhereEqual('ticket', $ticket);
}
}

+ 9
- 1
Repository/Ticket/TicketMessageStore.php Bestand weergeven

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

namespace Lc\SovBundle\Repository\Ticket;

use Lc\SovBundle\Model\Ticket\TicketInterface;
use Lc\SovBundle\Repository\AbstractStore;
use Lc\SovBundle\Repository\RepositoryQueryInterface;

@@ -15,7 +16,7 @@ class TicketMessageStore extends AbstractStore implements TicketMessageStoreInte
}
public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
$query->orderBy('createdAt', 'ASC');
return $query;
}

@@ -29,4 +30,11 @@ class TicketMessageStore extends AbstractStore implements TicketMessageStoreInte
{
return $query;
}

public function getByTicket(TicketInterface $ticket, $query = null)
{
$query = $this->createDefaultQuery($query);
$query->filterByTicket($ticket);
return $query->find();
}
}

+ 1
- 1
Repository/Ticket/TicketStore.php Bestand weergeven

@@ -20,7 +20,7 @@ class TicketStore extends AbstractStore implements TicketStoreInterface

public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
$query->orderBy('id');
$query->orderBy('updatedAt', 'DESC');
return $query;
}


+ 29
- 0
Twig/SettingTwigExtension.php Bestand weergeven

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

namespace Lc\SovBundle\Twig;

use Lc\SovBundle\Solver\Setting\SettingSolver;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class SettingTwigExtension extends AbstractExtension
{
protected SettingSolver $settingSolver;

public function __construct(SettingSolver $settingSolver)
{
$this->settingSolver = $settingSolver;
}

public function getFunctions()
{
return array(
new TwigFunction('sov_setting', [$this, 'getSettingValue']),
);
}

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

+ 13
- 1
Twig/TwigExtension.php Bestand weergeven

@@ -4,10 +4,12 @@ namespace Lc\SovBundle\Twig;

use App\Repository\ReminderRepository;
use Doctrine\ORM\EntityManagerInterface;
use Lc\SovBundle\Form\Newsletter\NewsletterType;
use Lc\SovBundle\Repository\Reminder\ReminderStore;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@@ -29,6 +31,7 @@ class TwigExtension extends AbstractExtension
protected $translatorAdmin;
protected $reminderStore;
protected $security;
protected FormFactoryInterface $formFactory;

public function __construct(
KernelInterface $kernel,
@@ -40,7 +43,8 @@ class TwigExtension extends AbstractExtension
TranslatorInterface $translator,
TranslatorAdmin $translatorAdmin,
ReminderStore $reminderStore,
Security $security
Security $security,
FormFactoryInterface $formFactory
) {
$this->kernel = $kernel;
$this->parameterBag = $parameterBag;
@@ -52,6 +56,7 @@ class TwigExtension extends AbstractExtension
$this->translatorAdmin = $translatorAdmin;
$this->reminderStore = $reminderStore;
$this->security = $security;
$this->formFactory = $formFactory;
}

public function getFunctions()
@@ -63,6 +68,7 @@ class TwigExtension extends AbstractExtension
new TwigFunction('sov_homepage_route', [$this, 'getHomepageRoute']),
new TwigFunction('lc_format_price', [$this, 'formatPrice']),
new TwigFunction('die', [$this, 'die']),
new TwigFunction('get_form_newsletter', [$this, 'getFormNewsletter']),
];
}

@@ -140,4 +146,10 @@ class TwigExtension extends AbstractExtension
return $this->parameterBag->get($name);
}

public function getFormNewsletter()
{
$form = $this->formFactory->create(NewsletterType::class);
return $form->createView();
}

}

Laden…
Annuleren
Opslaan