Browse Source

Merge branch 'develop'

master
Guillaume 4 years ago
parent
commit
d9428d3b0a
4 changed files with 118 additions and 1 deletions
  1. +54
    -0
      ShopBundle/Form/Backend/User/TicketTypesNotificationType.php
  2. +20
    -0
      ShopBundle/Model/User.php
  3. +11
    -0
      ShopBundle/Repository/UserRepository.php
  4. +33
    -1
      ShopBundle/Services/TicketUtils.php

+ 54
- 0
ShopBundle/Form/Backend/User/TicketTypesNotificationType.php View File

<?php

namespace Lc\ShopBundle\Form\Backend\User;

use App\Entity\Supplier;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Lc\ShopBundle\Model\Ticket;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
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\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;

class TicketTypesNotificationType extends AbstractType
{
protected $em;

public function __construct(EntityManagerInterface $entityManager)
{
$this->em = $entityManager;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{

$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) {
$builder = $event->getForm()->getParent();

$builder->add('ticketTypesNotification', ChoiceType::class, [
'choices'=> array(
'field.Ticket.typeOptions.'.Ticket::TYPE_GENERAL_QUESTION => Ticket::TYPE_GENERAL_QUESTION,
'field.Ticket.typeOptions.'.Ticket::TYPE_PRODUCT_ERROR=> Ticket::TYPE_PRODUCT_ERROR ,
'field.Ticket.typeOptions.'.Ticket::TYPE_PRODUCT_UNAVAILABLE => Ticket::TYPE_PRODUCT_UNAVAILABLE,
'field.Ticket.typeOptions.'.Ticket::TYPE_TECHNICAL_PROBLEM => Ticket::TYPE_TECHNICAL_PROBLEM
),
'required' => false,
'expanded' => false,
'multiple' => true,
'translation_domain'=>'lcshop',
]);
});
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
// 'translation_domain' => 'lcshop',
]);
}
}

+ 20
- 0
ShopBundle/Model/User.php View File

*/ */
protected $updatedAt; protected $updatedAt;


/**
* @ORM\Column(type="array", nullable=true)
*/
protected $ticketTypesNotification = [];



public function __construct() public function __construct()
{ {
parent::__construct(); parent::__construct();


return $this; return $this;
} }


public function getTicketTypesNotification(): ?array
{
return $this->ticketTypesNotification;
}

public function setTicketTypesNotification(?array $ticketTypesNotification): self
{
$this->ticketTypesNotification = $ticketTypesNotification;

return $this;
}
} }

+ 11
- 0
ShopBundle/Repository/UserRepository.php View File

return $qb->getQuery()->getResult(); return $qb->getQuery()->getResult();
} }


public function findByTicketTypesNotification($ticketType){

$qb = $this->createQueryBuilder('u')
->where('u.ticketTypesNotification LIKE :ticketType')
->setParameter('ticketType', '%"' . $ticketType . '"%');


return $qb->getQuery()->getResult();

}

} }

+ 33
- 1
ShopBundle/Services/TicketUtils.php View File

use Lc\ShopBundle\Context\OrderShopInterface; use Lc\ShopBundle\Context\OrderShopInterface;
use Lc\ShopBundle\Context\TicketInterface; use Lc\ShopBundle\Context\TicketInterface;
use Lc\ShopBundle\Context\TicketMessageInterface; use Lc\ShopBundle\Context\TicketMessageInterface;
use Lc\ShopBundle\Context\UserInterface;
use Lc\ShopBundle\Model\Ticket; use Lc\ShopBundle\Model\Ticket;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;


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


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


public function createTicket($params): TicketInterface public function createTicket($params): TicketInterface
], ],
]) ; ]) ;



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

return $ticket ; return $ticket ;
} }




return $ticketMessage ; return $ticketMessage ;
} }

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


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