@@ -0,0 +1,54 @@ | |||
<?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', | |||
]); | |||
} | |||
} |
@@ -102,6 +102,13 @@ abstract class User extends UserModelFOS | |||
*/ | |||
protected $updatedAt; | |||
/** | |||
* @ORM\Column(type="array", nullable=true) | |||
*/ | |||
protected $ticketTypesNotification = []; | |||
public function __construct() | |||
{ | |||
parent::__construct(); | |||
@@ -433,4 +440,17 @@ abstract class User extends UserModelFOS | |||
return $this; | |||
} | |||
public function getTicketTypesNotification(): ?array | |||
{ | |||
return $this->ticketTypesNotification; | |||
} | |||
public function setTicketTypesNotification(?array $ticketTypesNotification): self | |||
{ | |||
$this->ticketTypesNotification = $ticketTypesNotification; | |||
return $this; | |||
} | |||
} |
@@ -49,4 +49,15 @@ class UserRepository extends BaseRepository implements DefaultRepositoryInterfac | |||
return $qb->getQuery()->getResult(); | |||
} | |||
public function findByTicketTypesNotification($ticketType){ | |||
$qb = $this->createQueryBuilder('u') | |||
->where('u.ticketTypesNotification LIKE :ticketType') | |||
->setParameter('ticketType', '%"' . $ticketType . '"%'); | |||
return $qb->getQuery()->getResult(); | |||
} | |||
} |
@@ -8,19 +8,23 @@ use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||
use Lc\ShopBundle\Context\OrderShopInterface; | |||
use Lc\ShopBundle\Context\TicketInterface; | |||
use Lc\ShopBundle\Context\TicketMessageInterface; | |||
use Lc\ShopBundle\Context\UserInterface; | |||
use Lc\ShopBundle\Model\Ticket; | |||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; | |||
class TicketUtils | |||
{ | |||
protected $em ; | |||
protected $merchantUtils ; | |||
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->merchantUtils = $merchantUtils ; | |||
$this->mailUtils = $mailUtils ; | |||
$this->authorizationChecker = $authorizationChecker ; | |||
} | |||
public function createTicket($params): TicketInterface | |||
@@ -74,6 +78,9 @@ class TicketUtils | |||
], | |||
]) ; | |||
$this->notifyAdmin($ticket, $ticketMessage); | |||
return $ticket ; | |||
} | |||
@@ -114,5 +121,33 @@ class TicketUtils | |||
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 | |||
], | |||
]) ; | |||
dump($userToNotify->getEmail()); | |||
die(); | |||
} | |||
} | |||
} | |||
} | |||