Browse Source

Merge branch 'develop'

master^2
Guillaume 3 years ago
parent
commit
5b712d8568
10 changed files with 266 additions and 144 deletions
  1. +19
    -0
      ShopBundle/Form/Frontend/TicketMessageType.php
  2. +19
    -0
      ShopBundle/Form/Frontend/TicketType.php
  3. +17
    -0
      ShopBundle/Model/TicketMessage.php
  4. +2
    -0
      ShopBundle/Resources/public/css/backend/ekko-lightbox/ekko-ligthbox.min.css
  5. +2
    -0
      ShopBundle/Resources/public/js/backend/plugin/ekko-lightbox/ekko-lightbox.min.js
  6. +5
    -0
      ShopBundle/Resources/public/js/backend/script/default/init-common.js
  7. +1
    -1
      ShopBundle/Resources/views/backend/productfamily/macros.html.twig
  8. +17
    -1
      ShopBundle/Resources/views/backend/ticket/show.html.twig
  9. +1
    -10
      ShopBundle/Services/MailjetSmsUtils.php
  10. +183
    -132
      ShopBundle/Services/TicketUtils.php

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

use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType; 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\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use Symfony\Component\Validator\Constraints\File;


class TicketMessageType extends AbstractType class TicketMessageType extends AbstractType
{ {
'label' => 'field.Ticket.yourAnswer', 'label' => 'field.Ticket.yourAnswer',
'translation_domain' => 'lcshop', '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, [ ->add('closeTicket', CheckboxType::class, [
'label' => 'field.Ticket.closeTicket', 'label' => 'field.Ticket.closeTicket',
'translation_domain' => 'lcshop', 'translation_domain' => 'lcshop',

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

use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\EmailType; 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\TextareaType;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Security; use Symfony\Component\Security\Core\Security;
use Symfony\Component\Validator\Constraints\File;


class TicketType extends AbstractType class TicketType extends AbstractType
{ {
]) ])
->add('message', TextareaType::class, [ ->add('message', TextareaType::class, [
'label' => 'Message' 'label' => 'Message'
])
->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)",
])
],
]); ]);
} }



+ 17
- 0
ShopBundle/Model/TicketMessage.php View File

*/ */
protected $answerByAdmin; protected $answerByAdmin;


/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
protected $imageFilename;

public function __toString() public function __toString()
{ {
return $this->message; return $this->message;


return $this; return $this;
} }

public function getImageFilename(): ?string
{
return $this->imageFilename;
}

public function setImageFilename(?string $imageFilename): self
{
$this->imageFilename = $imageFilename;

return $this;
}
} }

+ 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

}); });




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

} }


function moment() { function moment() {

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

class="lc-show-products-sales-statistic btn btn-sm" class="lc-show-products-sales-statistic btn btn-sm"
data-toggle="tooltip" title="{{ 'action.product.statSales'|trans }}" data-toggle="tooltip" title="{{ 'action.product.statSales'|trans }}"
data-url="{{ path('easyadmin', { action: 'showSalesStatistic', entity: 'ProductFamily', id: productFamily.id }) }}"> 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-success"><i class="fa fa-calendar"></i> {{ weekNumber }}</span>
<span class="text-info"><i class="fa fa-shopping-basket"></i> <span class="text-info"><i class="fa fa-shopping-basket"></i>
<strong> <strong>

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

</div> </div>
{% endif %} {% endif %}
<div class="direct-chat-text"> <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>
</div> </div>
{% endfor %} {% endfor %}


{% endblock %} {% 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 %} {% block script_javascript %}
{{ parent() }} {{ parent() }}
<script src="{{ asset('bundles/lcshop/js/backend/script/ticket/init-edit.js')|lc_cache }}"></script> <script src="{{ asset('bundles/lcshop/js/backend/script/ticket/init-edit.js')|lc_cache }}"></script>

+ 1
- 10
ShopBundle/Services/MailjetSmsUtils.php View File

] ]
); );


$statusCode = $response->getStatusCode();

if ($statusCode == 200) {
$content = $response->getContent();
$content = $response->toArray();
return $content;
} else {
// log
return $response->getContent() ;
}
return $response ;
} }
else { else {
throw new \ErrorException('Le token SMS Mailjet n\'est pas défini.'); throw new \ErrorException('Le token SMS Mailjet n\'est pas défini.');

+ 183
- 132
ShopBundle/Services/TicketUtils.php View File

<?php <?php


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


use App\Entity\TicketMessage; use App\Entity\TicketMessage;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\TicketMessageInterface; use Lc\ShopBundle\Context\TicketMessageInterface;
use Lc\ShopBundle\Context\UserInterface; use Lc\ShopBundle\Context\UserInterface;
use Lc\ShopBundle\Model\Ticket; use Lc\ShopBundle\Model\Ticket;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;


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

public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils, MailUtils $mailUtils, AuthorizationCheckerInterface $authorizationChecker)
{
$this->em = $em ;
$this->merchantUtils = $merchantUtils ;
$this->mailUtils = $mailUtils ;
$this->authorizationChecker = $authorizationChecker ;
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 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['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->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);


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


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