Browse Source

Tickets : évolution (envoi email + affichage info dernier message)

feature/export_comptable
Guillaume 4 years ago
parent
commit
4f20faad3b
4 changed files with 49 additions and 3 deletions
  1. +1
    -0
      ShopBundle/Model/Ticket.php
  2. +5
    -0
      ShopBundle/Resources/views/backend/default/block/list_tickets.html.twig
  3. +11
    -0
      ShopBundle/Resources/views/backend/default/list-fields/field_ticket_last_message.html.twig
  4. +32
    -3
      ShopBundle/Services/TicketUtils.php

+ 1
- 0
ShopBundle/Model/Ticket.php View File



/** /**
* @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\TicketMessageInterface", mappedBy="ticket", orphanRemoval=true) * @ORM\OneToMany(targetEntity="Lc\ShopBundle\Context\TicketMessageInterface", mappedBy="ticket", orphanRemoval=true)
* @ORM\OrderBy({"id" = "ASC"})
*/ */
protected $ticketMessages; protected $ticketMessages;



+ 5
- 0
ShopBundle/Resources/views/backend/default/block/list_tickets.html.twig View File

<tr> <tr>
<th>Sujet</th> <th>Sujet</th>
<th>Statut</th> <th>Statut</th>
<th>Dernier message</th>
<th></th> <th></th>
</tr> </tr>
</thead> </thead>
{% set value = ticket.status %} {% set value = ticket.status %}
{% include '@LcShop/backend/default/list-fields/field_ticket_status.html.twig' %} {% include '@LcShop/backend/default/list-fields/field_ticket_status.html.twig' %}
</td> </td>
<td>
{% set item = ticket %}
{% include '@LcShop/backend/default/list-fields/field_ticket_last_message.html.twig' %}
</td>
<td> <td>
<a class="btn-sm btn-success" href="{{ path('easyadmin', {id: ticket.id, entity: 'Ticket', action: 'show'}) }}"> <a class="btn-sm btn-success" href="{{ path('easyadmin', {id: ticket.id, entity: 'Ticket', action: 'show'}) }}">
<i class="fas fa-eye"></i> <i class="fas fa-eye"></i>

+ 11
- 0
ShopBundle/Resources/views/backend/default/list-fields/field_ticket_last_message.html.twig View File

{% if item.ticketMessages %}
{% for message in item.ticketMessages %}
{% if loop.last %}
{% if message.answerByAdmin %}
Place du Local
{% else %}
Client
{% endif %}
{% endif %}
{% endfor %}
{% endif %}

+ 32
- 3
ShopBundle/Services/TicketUtils.php View File

{ {
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);



Loading…
Cancel
Save