|
|
@@ -14,11 +14,13 @@ class TicketUtils |
|
|
|
{ |
|
|
|
protected $em ; |
|
|
|
protected $merchantUtils ; |
|
|
|
protected $mailUtils ; |
|
|
|
|
|
|
|
public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils) |
|
|
|
public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils, MailUtils $mailUtils) |
|
|
|
{ |
|
|
|
$this->em = $em ; |
|
|
|
$this->merchantUtils = $merchantUtils ; |
|
|
|
$this->mailUtils = $mailUtils ; |
|
|
|
} |
|
|
|
|
|
|
|
public function createTicket($params): TicketInterface |
|
|
@@ -30,12 +32,18 @@ class TicketUtils |
|
|
|
|
|
|
|
if(isset($params['user'])) { |
|
|
|
$ticket->setUser($params['user']) ; |
|
|
|
|
|
|
|
$email = $params['user']->getEmail() ; |
|
|
|
$firstname = $params['user']->getFirstname() ; |
|
|
|
} |
|
|
|
else { |
|
|
|
$ticket->setVisitorFirstname($params['visitorFirstname']) ; |
|
|
|
$ticket->setVisitorLastname($params['visitorLastname']) ; |
|
|
|
$ticket->setVisitorEmail($params['visitorEmail']) ; |
|
|
|
$ticket->setVisitorToken(uniqid()) ; |
|
|
|
|
|
|
|
$email = $params['visitorEmail'] ; |
|
|
|
$firstname = $params['visitorFirstname'] ; |
|
|
|
} |
|
|
|
|
|
|
|
$ticket->setStatus(Ticket::TICKET_STATUS_OPEN) ; |
|
|
@@ -55,6 +63,17 @@ class TicketUtils |
|
|
|
|
|
|
|
$this->em->flush() ; |
|
|
|
|
|
|
|
// envoi email au client |
|
|
|
$this->mailUtils->send([ |
|
|
|
MailUtils::SUBJECT => 'Nouvelle demande', |
|
|
|
MailUtils::TO_EMAIL => $email, |
|
|
|
MailUtils::CONTENT_TEMPLATE => 'mail/ticket-new', |
|
|
|
MailUtils::CONTENT_DATA => [ |
|
|
|
'firstname' => $firstname, |
|
|
|
'ticket' => $ticket |
|
|
|
], |
|
|
|
]) ; |
|
|
|
|
|
|
|
return $ticket ; |
|
|
|
} |
|
|
|
|
|
|
@@ -70,14 +89,24 @@ class TicketUtils |
|
|
|
$ticketMessage->setMessage($params['message']) ; |
|
|
|
if(isset($params['answerByAdmin']) && $params['answerByAdmin']) { |
|
|
|
$ticketMessage->setAnswerByAdmin($params['answerByAdmin']) ; |
|
|
|
|
|
|
|
// envoi email au client |
|
|
|
$this->mailUtils->send([ |
|
|
|
MailUtils::SUBJECT => 'Réponse à votre demande', |
|
|
|
MailUtils::TO_EMAIL => $ticket->getUser() ? $ticket->getUser()->getEmail() : $ticket->getVisitorEmail(), |
|
|
|
MailUtils::CONTENT_TEMPLATE => 'mail/ticket-response', |
|
|
|
MailUtils::CONTENT_DATA => [ |
|
|
|
'firstname' => $ticket->getUser() ? $ticket->getUser()->getFirstname() : $ticket->getVisitorFirstname(), |
|
|
|
'ticket' => $ticket |
|
|
|
], |
|
|
|
]) ; |
|
|
|
} |
|
|
|
$this->em->persist($ticketMessage); |
|
|
|
|
|
|
|
if(isset($params['closeTicket']) && $params['closeTicket']) { |
|
|
|
$ticket->setTicketStatus(Ticket::TICKET_STATUS_CLOSED) ; |
|
|
|
$ticket->setStatus(Ticket::TICKET_STATUS_CLOSED) ; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$ticket->setUpdatedAt(new \DateTime()) ; |
|
|
|
$this->em->persist($ticket); |
|
|
|
|