<?php | |||||
namespace Lc\ShopBundle\Form\Backend\User; | |||||
use App\Entity\Supplier; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Doctrine\ORM\EntityRepository; | |||||
use Lc\ShopBundle\Model\Ticket; | |||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | |||||
use Symfony\Component\Form\AbstractType; | |||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | |||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | |||||
use Symfony\Component\Form\FormBuilderInterface; | |||||
use Symfony\Component\Form\FormEvent; | |||||
use Symfony\Component\Form\FormEvents; | |||||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||||
class TicketTypesNotificationType extends AbstractType | |||||
{ | |||||
protected $em; | |||||
public function __construct(EntityManagerInterface $entityManager) | |||||
{ | |||||
$this->em = $entityManager; | |||||
} | |||||
public function buildForm(FormBuilderInterface $builder, array $options) | |||||
{ | |||||
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { | |||||
$builder = $event->getForm()->getParent(); | |||||
$builder->add('ticketTypesNotification', ChoiceType::class, [ | |||||
'choices'=> array( | |||||
'field.Ticket.typeOptions.'.Ticket::TYPE_GENERAL_QUESTION => Ticket::TYPE_GENERAL_QUESTION, | |||||
'field.Ticket.typeOptions.'.Ticket::TYPE_PRODUCT_ERROR=> Ticket::TYPE_PRODUCT_ERROR , | |||||
'field.Ticket.typeOptions.'.Ticket::TYPE_PRODUCT_UNAVAILABLE => Ticket::TYPE_PRODUCT_UNAVAILABLE, | |||||
'field.Ticket.typeOptions.'.Ticket::TYPE_TECHNICAL_PROBLEM => Ticket::TYPE_TECHNICAL_PROBLEM | |||||
), | |||||
'required' => false, | |||||
'expanded' => false, | |||||
'multiple' => true, | |||||
'translation_domain'=>'lcshop', | |||||
]); | |||||
}); | |||||
} | |||||
public function configureOptions(OptionsResolver $resolver) | |||||
{ | |||||
$resolver->setDefaults([ | |||||
// 'translation_domain' => 'lcshop', | |||||
]); | |||||
} | |||||
} |
*/ | */ | ||||
protected $updatedAt; | protected $updatedAt; | ||||
/** | |||||
* @ORM\Column(type="array", nullable=true) | |||||
*/ | |||||
protected $ticketTypesNotification = []; | |||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
parent::__construct(); | parent::__construct(); | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getTicketTypesNotification(): ?array | |||||
{ | |||||
return $this->ticketTypesNotification; | |||||
} | |||||
public function setTicketTypesNotification(?array $ticketTypesNotification): self | |||||
{ | |||||
$this->ticketTypesNotification = $ticketTypesNotification; | |||||
return $this; | |||||
} | |||||
} | } |
return $qb->getQuery()->getResult(); | return $qb->getQuery()->getResult(); | ||||
} | } | ||||
public function findByTicketTypesNotification($ticketType){ | |||||
$qb = $this->createQueryBuilder('u') | |||||
->where('u.ticketTypesNotification LIKE :ticketType') | |||||
->setParameter('ticketType', '%"' . $ticketType . '"%'); | |||||
return $qb->getQuery()->getResult(); | |||||
} | |||||
} | } |
use Lc\ShopBundle\Context\OrderShopInterface; | use Lc\ShopBundle\Context\OrderShopInterface; | ||||
use Lc\ShopBundle\Context\TicketInterface; | use Lc\ShopBundle\Context\TicketInterface; | ||||
use Lc\ShopBundle\Context\TicketMessageInterface; | use Lc\ShopBundle\Context\TicketMessageInterface; | ||||
use Lc\ShopBundle\Context\UserInterface; | |||||
use Lc\ShopBundle\Model\Ticket; | use Lc\ShopBundle\Model\Ticket; | ||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; | |||||
class TicketUtils | class TicketUtils | ||||
{ | { | ||||
protected $em ; | protected $em ; | ||||
protected $merchantUtils ; | protected $merchantUtils ; | ||||
protected $mailUtils ; | protected $mailUtils ; | ||||
protected $authorizationChecker ; | |||||
public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils, MailUtils $mailUtils) | |||||
public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils, MailUtils $mailUtils, AuthorizationCheckerInterface $authorizationChecker) | |||||
{ | { | ||||
$this->em = $em ; | $this->em = $em ; | ||||
$this->merchantUtils = $merchantUtils ; | $this->merchantUtils = $merchantUtils ; | ||||
$this->mailUtils = $mailUtils ; | $this->mailUtils = $mailUtils ; | ||||
$this->authorizationChecker = $authorizationChecker ; | |||||
} | } | ||||
public function createTicket($params): TicketInterface | public function createTicket($params): TicketInterface | ||||
], | ], | ||||
]) ; | ]) ; | ||||
$this->notifyAdmin($ticket, $ticketMessage); | |||||
return $ticket ; | return $ticket ; | ||||
} | } | ||||
return $ticketMessage ; | return $ticketMessage ; | ||||
} | } | ||||
public function notifyAdmin($ticket, $ticketMessage){ | |||||
$userRepo = $this->em->getRepository(UserInterface::class); | |||||
$usersToNotify = $userRepo->findByTicketTypesNotification($ticket->getType()); | |||||
foreach ($usersToNotify as $userToNotify){ | |||||
if($this->authorizationChecker->isGranted('ROLE_ADMIN', $userToNotify)){ | |||||
// envoi email au client | |||||
$this->mailUtils->send([ | |||||
MailUtils::SUBJECT => 'Nouveau ticket sur placedulocal', | |||||
MailUtils::TO_EMAIL => $userToNotify->getEmail(), | |||||
MailUtils::CONTENT_TEMPLATE => 'mail/ticket-notification', | |||||
MailUtils::CONTENT_DATA => [ | |||||
'firstname' => $userToNotify->getFirstname(), | |||||
'ticket' => $ticket, | |||||
'ticketMessage' => $ticketMessage | |||||
], | |||||
]) ; | |||||
} | |||||
} | |||||
} | |||||
} | } | ||||