Просмотр исходного кода

Merge branch 'develop'

master^2
Guillaume 3 лет назад
Родитель
Сommit
5b712d8568
10 измененных файлов: 266 добавлений и 144 удалений
  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 Просмотреть файл

@@ -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',

+ 19
- 0
ShopBundle/Form/Frontend/TicketType.php Просмотреть файл

@@ -11,11 +11,13 @@ use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
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 TicketType extends AbstractType
{
@@ -95,6 +97,23 @@ class TicketType extends AbstractType
])
->add('message', TextareaType::class, [
'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 Просмотреть файл

@@ -44,6 +44,11 @@ abstract class TicketMessage extends AbstractEntity
*/
protected $answerByAdmin;

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

public function __toString()
{
return $this->message;
@@ -84,4 +89,16 @@ abstract class TicketMessage extends AbstractEntity

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
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 2
- 0
ShopBundle/Resources/public/js/backend/plugin/ekko-lightbox/ekko-lightbox.min.js
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


+ 5
- 0
ShopBundle/Resources/public/js/backend/script/default/init-common.js Просмотреть файл

@@ -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 Просмотреть файл

@@ -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 Просмотреть файл

@@ -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>

+ 1
- 10
ShopBundle/Services/MailjetSmsUtils.php Просмотреть файл

@@ -86,16 +86,7 @@ class MailjetSmsUtils
]
);

$statusCode = $response->getStatusCode();

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

+ 183
- 132
ShopBundle/Services/TicketUtils.php Просмотреть файл

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

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

use App\Entity\TicketMessage;
use Doctrine\ORM\EntityManagerInterface;
@@ -10,159 +10,210 @@ use Lc\ShopBundle\Context\TicketInterface;
use Lc\ShopBundle\Context\TicketMessageInterface;
use Lc\ShopBundle\Context\UserInterface;
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;

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


Загрузка…
Отмена
Сохранить