|
|
@@ -10,6 +10,8 @@ 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 |
|
|
@@ -18,13 +20,20 @@ class TicketUtils |
|
|
|
protected $merchantUtils ; |
|
|
|
protected $mailUtils ; |
|
|
|
protected $authorizationChecker ; |
|
|
|
|
|
|
|
public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils, MailUtils $mailUtils, AuthorizationCheckerInterface $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){ |
|
|
@@ -32,6 +41,31 @@ class TicketUtils |
|
|
|
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 ; |
|
|
|
} |
|
|
|
|
|
|
|
return false ; |
|
|
|
} |
|
|
|
|
|
|
|
public function createTicket($params): TicketInterface |
|
|
|
{ |
|
|
|
$classTicket = $this->em->getClassMetadata(TicketInterface::class)->getName() ; |
|
|
@@ -68,7 +102,14 @@ class TicketUtils |
|
|
|
$ticketMessage->setStatus(1) ; |
|
|
|
$ticketMessage->setTicket($ticket) ; |
|
|
|
$ticketMessage->setMessage($params['message']) ; |
|
|
|
if(isset($params['createByAdmin']) && $params['createByAdmin'])$ticketMessage->setAnswerByAdmin(true); |
|
|
|
|
|
|
|
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() ; |