Browse Source

[Global] Fichier joint dans ticket

develop
Fab 3 years ago
parent
commit
045252743a
7 changed files with 226 additions and 172 deletions
  1. +19
    -0
      ShopBundle/Form/Frontend/TicketMessageType.php
  2. +2
    -0
      ShopBundle/Resources/public/css/backend/ekko-lightbox/ekko-ligthbox.min.css
  3. +2
    -0
      ShopBundle/Resources/public/js/backend/plugin/ekko-lightbox/ekko-lightbox.min.js
  4. +5
    -0
      ShopBundle/Resources/public/js/backend/script/default/init-common.js
  5. +1
    -1
      ShopBundle/Resources/views/backend/productfamily/macros.html.twig
  6. +17
    -1
      ShopBundle/Resources/views/backend/ticket/show.html.twig
  7. +180
    -170
      ShopBundle/Services/TicketUtils.php

+ 19
- 0
ShopBundle/Form/Frontend/TicketMessageType.php View File

@@ -12,11 +12,13 @@ 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\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Validator\Constraints\File;

class TicketMessageType extends AbstractType
{
@@ -28,6 +30,23 @@ class TicketMessageType extends AbstractType
'label' => 'field.Ticket.yourAnswer',
'translation_domain' => 'lcshop',
])
->add('image', FileType::class, [
'label' => 'Photo',
'mapped' => false,
'required' => false,
'constraints' => [
new File([
'maxSize' => '2048k',
'mimeTypes' => [
'image/png',
'image/jpeg',
'image/jpg',
'image/gif',
],
'mimeTypesMessage' => "Mauvais format d'image (formats acceptés : jpeg, png, gif)",
])
],
])
->add('closeTicket', CheckboxType::class, [
'label' => 'field.Ticket.closeTicket',
'translation_domain' => 'lcshop',

+ 2
- 0
ShopBundle/Resources/public/css/backend/ekko-lightbox/ekko-ligthbox.min.css
File diff suppressed because it is too large
View File


+ 2
- 0
ShopBundle/Resources/public/js/backend/plugin/ekko-lightbox/ekko-lightbox.min.js
File diff suppressed because it is too large
View File


+ 5
- 0
ShopBundle/Resources/public/js/backend/script/default/init-common.js View File

@@ -156,6 +156,11 @@ function initAdminLtePlugin() {
});


$(document).on('click', '[data-toggle="lightbox"]', function(event) {
event.preventDefault();
$(this).ekkoLightbox();
});

}

function moment() {

+ 1
- 1
ShopBundle/Resources/views/backend/productfamily/macros.html.twig View File

@@ -19,7 +19,7 @@
class="lc-show-products-sales-statistic btn btn-sm"
data-toggle="tooltip" title="{{ 'action.product.statSales'|trans }}"
data-url="{{ path('easyadmin', { action: 'showSalesStatistic', entity: 'ProductFamily', id: productFamily.id }) }}">
{% for weekNumber, weekNumberQuantity in productsSalesStatistic['data']['total_sales']['data'] %}
{% for weekNumber, weekNumberQuantity in productsSalesStatistic['data']['total_sales']['data']|reverse(true) %}
<span class="text-success"><i class="fa fa-calendar"></i> {{ weekNumber }}</span>
<span class="text-info"><i class="fa fa-shopping-basket"></i>
<strong>

+ 17
- 1
ShopBundle/Resources/views/backend/ticket/show.html.twig View File

@@ -60,7 +60,13 @@
</div>
{% endif %}
<div class="direct-chat-text">
{{ message.message|nl2br }}
<p>{{ message.message|nl2br }}</p>
{% if message.imageFilename is not null %}
<i>Photo jointe au message : </i> <br />
<a href="{{ lc_liip(message.imageFilename, 'big') }}" data-toggle="lightbox">
<img src="{{ lc_liip(message.imageFilename, 'thumb') }}" alt="Illustration ticket" />
</a>
{% endif %}
</div>
</div>
{% endfor %}
@@ -85,6 +91,16 @@

{% endblock %}

{% block head_stylesheets %}
{{ parent() }}
<link rel="stylesheet"
href="{{ asset('bundles/lcshop/css/backend/ekko-lightbox/ekko-ligthbox.min.css') }}">
{% endblock head_stylesheets %}

{% block plugin_javascript %}
{{ parent() }}
<script src="{{ asset('bundles/lcshop/js/backend/plugin/ekko-lightbox/ekko-lightbox.min.js')|lc_cache }}"></script>
{% endblock plugin_javascript %}
{% block script_javascript %}
{{ parent() }}
<script src="{{ asset('bundles/lcshop/js/backend/script/ticket/init-edit.js')|lc_cache }}"></script>

+ 180
- 170
ShopBundle/Services/TicketUtils.php View File

@@ -1,6 +1,6 @@
<?php

namespace Lc\ShopBundle\Services ;
namespace Lc\ShopBundle\Services;

use App\Entity\TicketMessage;
use Doctrine\ORM\EntityManagerInterface;
@@ -16,194 +16,204 @@ use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;

class TicketUtils
{
protected $em ;
protected $merchantUtils ;
protected $mailUtils ;
protected $authorizationChecker ;
protected $parameterBag ;

public function __construct(
EntityManagerInterface $em,
MerchantUtilsInterface $merchantUtils,
MailUtils $mailUtils,
AuthorizationCheckerInterface $authorizationChecker,
ParameterBagInterface $parameterBag
) {
$this->em = $em ;
$this->merchantUtils = $merchantUtils ;
$this->mailUtils = $mailUtils ;
$this->authorizationChecker = $authorizationChecker ;
$this->parameterBag = $parameterBag ;
protected $em;
protected $merchantUtils;
protected $mailUtils;
protected $authorizationChecker;
protected $parameterBag;

public function __construct(
EntityManagerInterface $em,
MerchantUtilsInterface $merchantUtils,
MailUtils $mailUtils,
AuthorizationCheckerInterface $authorizationChecker,
ParameterBagInterface $parameterBag
) {
$this->em = $em;
$this->merchantUtils = $merchantUtils;
$this->mailUtils = $mailUtils;
$this->authorizationChecker = $authorizationChecker;
$this->parameterBag = $parameterBag;
}

public function getTicketsByUser($user)
{
$ticketRepo = $this->em->getRepository(TicketInterface::class);

return $ticketRepo->findBy(array('user' => $user));
}

public function uploadImageTicketMessage($formTicket)
{
$image = $formTicket->get('image')->getData();

if ($image) {
$originalFilename = pathinfo($image->getClientOriginalName(), PATHINFO_FILENAME);
$newFilename = uniqid().'.'.$image->guessExtension();

try {
$image->move(
$this->parameterBag->get('app.ticket_images_directory'),
$newFilename
);
} catch (FileException $e) {
throw new \ErrorException("Une erreur est survenue lors de l'upload du fichier.");
}

return $this->parameterBag->get('app.ticket_images_subdirectory').$newFilename;
}

public function getTicketsByUser($user){
$ticketRepo = $this->em->getRepository(TicketInterface::class);
return $ticketRepo->findBy(array('user'=>$user));

return false;
}

public function createTicket($params): TicketInterface
{
$classTicket = $this->em->getClassMetadata(TicketInterface::class)->getName();
$ticket = new $classTicket;
$ticket->setMerchant($this->merchantUtils->getMerchantCurrent());
$ticket->setStatus(1);

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'];
}

public function uploadImageTicketMessage($formTicket)
{
$image = $formTicket->get('image')->getData();

if ($image) {
$originalFilename = pathinfo($image->getClientOriginalName(), PATHINFO_FILENAME);
$newFilename = uniqid().'.' . $image->guessExtension();

try {
$image->move(
$this->parameterBag->get('app.ticket_images_directory'),
$newFilename
);
}
catch (FileException $e) {
throw new \ErrorException("Une erreur est survenue lors de l'upload du fichier.");
}

return $this->parameterBag->get('app.ticket_images_subdirectory').$newFilename ;
}

return false ;
$ticket->setStatus(Ticket::TICKET_STATUS_OPEN);
$ticket->setType($params['type']);
if (isset($params['orderShop']) && $params['orderShop'] && $params['orderShop'] instanceof OrderShopInterface) {
$ticket->setOrderShop($params['orderShop']);
}
$ticket->setSubject($params['subject']);
$this->em->persist($ticket);

public function createTicket($params): TicketInterface
{
$classTicket = $this->em->getClassMetadata(TicketInterface::class)->getName() ;
$ticket = new $classTicket ;
$ticket->setMerchant($this->merchantUtils->getMerchantCurrent()) ;
$ticket->setStatus(1) ;

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) ;
$ticket->setType($params['type']) ;
if(isset($params['orderShop']) && $params['orderShop'] && $params['orderShop'] instanceof OrderShopInterface) {
$ticket->setOrderShop($params['orderShop']) ;
}
$ticket->setSubject($params['subject']) ;
$this->em->persist($ticket);

$classTicketMessage = $this->em->getClassMetadata(TicketMessageInterface::class)->getName() ;
$ticketMessage = new $classTicketMessage ;
$ticketMessage->setStatus(1) ;
$ticketMessage->setTicket($ticket) ;
$ticketMessage->setMessage($params['message']) ;

if(isset($params['imageFilename']) && $params['imageFilename']) {
$ticketMessage->setImageFilename($params['imageFilename']);
}

if(isset($params['createByAdmin']) && $params['createByAdmin']) {
$ticketMessage->setAnswerByAdmin(true);
}
$this->em->persist($ticketMessage);

$this->em->flush() ;

if(isset($params['createByAdmin']) && $params['createByAdmin']) {
// envoi email au client
$this->mailUtils->send([
MailUtils::SUBJECT => 'Vous avez reçu un nouveau message',
MailUtils::TO_EMAIL => $email,
MailUtils::CONTENT_TEMPLATE => 'mail/ticket-new-by-admin',
MailUtils::CONTENT_DATA => [
'firstname' => $firstname,
'ticket' => $ticket
],
]);
}else{
$this->mailUtils->send([
MailUtils::SUBJECT => 'Nouvelle demande',
MailUtils::TO_EMAIL => $email,
MailUtils::CONTENT_TEMPLATE => 'mail/ticket-new',
MailUtils::CONTENT_DATA => [
'firstname' => $firstname,
'ticket' => $ticket
],
]);
}

$classTicketMessage = $this->em->getClassMetadata(TicketMessageInterface::class)->getName();
$ticketMessage = new $classTicketMessage;
$ticketMessage->setStatus(1);
$ticketMessage->setTicket($ticket);
$ticketMessage->setMessage($params['message']);

$this->notifyAdmin($ticket, $ticketMessage);

return $ticket ;
if (isset($params['imageFilename']) && $params['imageFilename']) {
$ticketMessage->setImageFilename($params['imageFilename']);
}

public function createTicketMessage($params)
{
$classTicketMessage = $this->em->getClassMetadata(TicketMessageInterface::class)->getName() ;
$ticketMessage = new $classTicketMessage ;

$ticket = $params['ticket'] ;

$ticketMessage->setStatus(1) ;
$ticketMessage->setTicket($ticket) ;
$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->setStatus(Ticket::TICKET_STATUS_CLOSED) ;
}
if (isset($params['createByAdmin']) && $params['createByAdmin']) {
$ticketMessage->setAnswerByAdmin(true);
}
$this->em->persist($ticketMessage);

$this->em->flush();

if (isset($params['createByAdmin']) && $params['createByAdmin']) {
// envoi email au client
$this->mailUtils->send(
[
MailUtils::SUBJECT => 'Vous avez reçu un nouveau message',
MailUtils::TO_EMAIL => $email,
MailUtils::CONTENT_TEMPLATE => 'mail/ticket-new-by-admin',
MailUtils::CONTENT_DATA => [
'firstname' => $firstname,
'ticket' => $ticket,
],
]
);
} else {
$this->mailUtils->send(
[
MailUtils::SUBJECT => 'Nouvelle demande',
MailUtils::TO_EMAIL => $email,
MailUtils::CONTENT_TEMPLATE => 'mail/ticket-new',
MailUtils::CONTENT_DATA => [
'firstname' => $firstname,
'ticket' => $ticket,
],
]
);
}

$ticket->setUpdatedAt(new \DateTime()) ;
$this->em->persist($ticket);

$this->em->flush() ;
$this->notifyAdmin($ticket, $ticketMessage);

return $ticket;
}

public function createTicketMessage($params)
{
$classTicketMessage = $this->em->getClassMetadata(TicketMessageInterface::class)->getName();
$ticketMessage = new $classTicketMessage;

$ticket = $params['ticket'];

$ticketMessage->setStatus(1);
$ticketMessage->setTicket($ticket);
$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);

return $ticketMessage ;
if (isset($params['imageFilename']) && $params['imageFilename']) {
$ticketMessage->setImageFilename($params['imageFilename']);
}
if (isset($params['closeTicket']) && $params['closeTicket']) {
$ticket->setStatus(Ticket::TICKET_STATUS_CLOSED);
}

public function notifyAdmin($ticket, $ticketMessage){
$userRepo = $this->em->getRepository(UserInterface::class);
$usersToNotify = $userRepo->findByTicketTypesNotification($ticket->getType());
$ticket->setUpdatedAt(new \DateTime());
$this->em->persist($ticket);

$this->em->flush();

foreach ($usersToNotify as $userToNotify){
return $ticketMessage;
}

if($this->authorizationChecker->isGranted('ROLE_ADMIN', $userToNotify)){
public function notifyAdmin($ticket, $ticketMessage)
{
$userRepo = $this->em->getRepository(UserInterface::class);
$usersToNotify = $userRepo->findByTicketTypesNotification($ticket->getType());

// 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
],
]) ;
}
}

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,
],
]
);
}
}
}
}


Loading…
Cancel
Save