Browse Source

Script d'import

develop
Fab 3 years ago
parent
commit
2a14fac273
13 changed files with 424 additions and 9 deletions
  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 View File



namespace Lc\SovBundle\Builder\Ticket; namespace Lc\SovBundle\Builder\Ticket;


use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Notification\MailMailjetNotification;
use Lc\SovBundle\Component\FormComponent; 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\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;


class TicketBuilder class TicketBuilder
{ {
protected EntityManagerInterface $entityManager;
protected MailMailjetNotification $mailMailjetNotification;
protected FormComponent $formComponent; protected FormComponent $formComponent;
protected ParameterBagInterface $parameterBag; 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->formComponent = $formComponent;
$this->parameterBag = $parameterBag; $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 // uploadImageTicketMessage

+ 75
- 0
Builder/Ticket/TicketMessageBuilder.php View File

<?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 View File

use Lc\SovBundle\Model\Newsletter\NewsletterInterface; use Lc\SovBundle\Model\Newsletter\NewsletterInterface;
use Lc\SovBundle\Model\User\UserInterface; use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\User\UserStore; use Lc\SovBundle\Repository\User\UserStore;
use Lc\SovBundle\Solver\User\UserSolver;


class UserBuilder class UserBuilder
{ {
protected EntityManagerInterface $entityManager; protected EntityManagerInterface $entityManager;
protected UserStore $userStore; 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->entityManager = $entityManager;
$this->userStore = $userStore; $this->userStore = $userStore;
$this->userSolver = $userSolver;
} }


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

+ 2
- 0
Component/FormComponent.php View File

use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\File\Exception\FileException; use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\Validator\Constraints\EqualTo;
use Symfony\Component\Validator\Constraints\NotNull;


class FormComponent class FormComponent
{ {

+ 102
- 0
Container/ComponentContainer.php View File

<?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 View File



namespace Lc\SovBundle\Container\Ticket; namespace Lc\SovBundle\Container\Ticket;


use Lc\SovBundle\Builder\Ticket\TicketMessageBuilder;
use Lc\SovBundle\Factory\Ticket\TicketMessageFactory; use Lc\SovBundle\Factory\Ticket\TicketMessageFactory;
use Lc\SovBundle\Repository\Ticket\TicketMessageRepositoryQuery; use Lc\SovBundle\Repository\Ticket\TicketMessageRepositoryQuery;
use Lc\SovBundle\Repository\Ticket\TicketMessageStore; use Lc\SovBundle\Repository\Ticket\TicketMessageStore;
protected TicketMessageFactory $factory; protected TicketMessageFactory $factory;
protected TicketMessageRepositoryQuery $repositoryQuery; protected TicketMessageRepositoryQuery $repositoryQuery;
protected TicketMessageStore $store; protected TicketMessageStore $store;
protected TicketMessageBuilder $builder;


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


public function getFactory(): TicketMessageFactory public function getFactory(): TicketMessageFactory
{ {
return $this->store; return $this->store;
} }

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

+ 2
- 1
Controller/AbstractAdminController.php View File

use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator; use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Security\Permission; use EasyCorp\Bundle\EasyAdminBundle\Security\Permission;
use Lc\SovBundle\Component\EntityComponent; use Lc\SovBundle\Component\EntityComponent;
use Lc\SovBundle\Container\ComponentContainer;
use Lc\SovBundle\Container\File\FileContainer; use Lc\SovBundle\Container\File\FileContainer;
use Lc\SovBundle\Container\Newsletter\NewsletterContainer; use Lc\SovBundle\Container\Newsletter\NewsletterContainer;
use Lc\SovBundle\Container\Reminder\ReminderContainer; use Lc\SovBundle\Container\Reminder\ReminderContainer;
RequestStack::class => RequestStack::class, RequestStack::class => RequestStack::class,
EntityManagerInterface::class => EntityManagerInterface::class, EntityManagerInterface::class => EntityManagerInterface::class,
FilterManager::class => FilterManager::class, FilterManager::class => FilterManager::class,
ComponentContainer::class => ComponentContainer::class,
FileContainer::class => FileContainer::class, FileContainer::class => FileContainer::class,
NewsletterContainer::class => NewsletterContainer::class, NewsletterContainer::class => NewsletterContainer::class,
ReminderContainer::class => ReminderContainer::class, ReminderContainer::class => ReminderContainer::class,
GroupUserContainer::class => GroupUserContainer::class, GroupUserContainer::class => GroupUserContainer::class,
UserContainer::class => UserContainer::class, UserContainer::class => UserContainer::class,
SiteSettingContainer::class => SiteSettingContainer::class, SiteSettingContainer::class => SiteSettingContainer::class,

] ]
); );
} }

+ 48
- 0
Form/Newsletter/NewsletterType.php View File

<?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 View File

namespace Lc\SovBundle\Repository\Ticket; namespace Lc\SovBundle\Repository\Ticket;


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


class TicketMessageRepositoryQuery extends AbstractRepositoryQuery implements TicketMessageRepositoryQueryInterface class TicketMessageRepositoryQuery extends AbstractRepositoryQuery implements TicketMessageRepositoryQueryInterface
{ {
parent::__construct($repository, 'r', $paginator); parent::__construct($repository, 'r', $paginator);
} }

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

+ 9
- 1
Repository/Ticket/TicketMessageStore.php View File



namespace Lc\SovBundle\Repository\Ticket; namespace Lc\SovBundle\Repository\Ticket;


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


} }
public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{ {
$query->orderBy('createdAt', 'ASC');
return $query; return $query;
} }


{ {
return $query; 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 View File



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



+ 29
- 0
Twig/SettingTwigExtension.php View File

<?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 View File



use App\Repository\ReminderRepository; use App\Repository\ReminderRepository;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Lc\SovBundle\Form\Newsletter\NewsletterType;
use Lc\SovBundle\Repository\Reminder\ReminderStore; use Lc\SovBundle\Repository\Reminder\ReminderStore;
use Lc\SovBundle\Translation\TranslatorAdmin; use Lc\SovBundle\Translation\TranslatorAdmin;
use Liip\ImagineBundle\Imagine\Cache\CacheManager; use Liip\ImagineBundle\Imagine\Cache\CacheManager;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\KernelInterface; use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
protected $translatorAdmin; protected $translatorAdmin;
protected $reminderStore; protected $reminderStore;
protected $security; protected $security;
protected FormFactoryInterface $formFactory;


public function __construct( public function __construct(
KernelInterface $kernel, KernelInterface $kernel,
TranslatorInterface $translator, TranslatorInterface $translator,
TranslatorAdmin $translatorAdmin, TranslatorAdmin $translatorAdmin,
ReminderStore $reminderStore, ReminderStore $reminderStore,
Security $security
Security $security,
FormFactoryInterface $formFactory
) { ) {
$this->kernel = $kernel; $this->kernel = $kernel;
$this->parameterBag = $parameterBag; $this->parameterBag = $parameterBag;
$this->translatorAdmin = $translatorAdmin; $this->translatorAdmin = $translatorAdmin;
$this->reminderStore = $reminderStore; $this->reminderStore = $reminderStore;
$this->security = $security; $this->security = $security;
$this->formFactory = $formFactory;
} }


public function getFunctions() public function getFunctions()
new TwigFunction('sov_homepage_route', [$this, 'getHomepageRoute']), new TwigFunction('sov_homepage_route', [$this, 'getHomepageRoute']),
new TwigFunction('lc_format_price', [$this, 'formatPrice']), new TwigFunction('lc_format_price', [$this, 'formatPrice']),
new TwigFunction('die', [$this, 'die']), new TwigFunction('die', [$this, 'die']),
new TwigFunction('get_form_newsletter', [$this, 'getFormNewsletter']),
]; ];
} }


return $this->parameterBag->get($name); return $this->parameterBag->get($name);
} }


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

} }

Loading…
Cancel
Save