|
|
|
|
|
|
|
|
{ |
|
|
{ |
|
|
protected $em ; |
|
|
protected $em ; |
|
|
protected $merchantUtils ; |
|
|
protected $merchantUtils ; |
|
|
|
|
|
protected $mailUtils ; |
|
|
|
|
|
|
|
|
public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils) |
|
|
|
|
|
|
|
|
public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils, MailUtils $mailUtils) |
|
|
{ |
|
|
{ |
|
|
$this->em = $em ; |
|
|
$this->em = $em ; |
|
|
$this->merchantUtils = $merchantUtils ; |
|
|
$this->merchantUtils = $merchantUtils ; |
|
|
|
|
|
$this->mailUtils = $mailUtils ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function createTicket($params): TicketInterface |
|
|
public function createTicket($params): TicketInterface |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(isset($params['user'])) { |
|
|
if(isset($params['user'])) { |
|
|
$ticket->setUser($params['user']) ; |
|
|
$ticket->setUser($params['user']) ; |
|
|
|
|
|
|
|
|
|
|
|
$email = $params['user']->getEmail() ; |
|
|
|
|
|
$firstname = $params['user']->getFirstname() ; |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
$ticket->setVisitorFirstname($params['visitorFirstname']) ; |
|
|
$ticket->setVisitorFirstname($params['visitorFirstname']) ; |
|
|
$ticket->setVisitorLastname($params['visitorLastname']) ; |
|
|
$ticket->setVisitorLastname($params['visitorLastname']) ; |
|
|
$ticket->setVisitorEmail($params['visitorEmail']) ; |
|
|
$ticket->setVisitorEmail($params['visitorEmail']) ; |
|
|
$ticket->setVisitorToken(uniqid()) ; |
|
|
$ticket->setVisitorToken(uniqid()) ; |
|
|
|
|
|
|
|
|
|
|
|
$email = $params['visitorEmail'] ; |
|
|
|
|
|
$firstname = $params['visitorFirstname'] ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$ticket->setStatus(Ticket::TICKET_STATUS_OPEN) ; |
|
|
$ticket->setStatus(Ticket::TICKET_STATUS_OPEN) ; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->em->flush() ; |
|
|
$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 ; |
|
|
return $ticket ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$ticketMessage->setMessage($params['message']) ; |
|
|
$ticketMessage->setMessage($params['message']) ; |
|
|
if(isset($params['answerByAdmin']) && $params['answerByAdmin']) { |
|
|
if(isset($params['answerByAdmin']) && $params['answerByAdmin']) { |
|
|
$ticketMessage->setAnswerByAdmin($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); |
|
|
$this->em->persist($ticketMessage); |
|
|
|
|
|
|
|
|
if(isset($params['closeTicket']) && $params['closeTicket']) { |
|
|
if(isset($params['closeTicket']) && $params['closeTicket']) { |
|
|
$ticket->setTicketStatus(Ticket::TICKET_STATUS_CLOSED) ; |
|
|
|
|
|
|
|
|
$ticket->setStatus(Ticket::TICKET_STATUS_CLOSED) ; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$ticket->setUpdatedAt(new \DateTime()) ; |
|
|
$ticket->setUpdatedAt(new \DateTime()) ; |
|
|
$this->em->persist($ticket); |
|
|
$this->em->persist($ticket); |
|
|
|
|
|
|