Sfoglia il codice sorgente

Tickets : gestion des pièces jointes

develop
Guillaume 3 anni fa
parent
commit
c1d10ca115
3 ha cambiato i file con 81 aggiunte e 4 eliminazioni
  1. +19
    -0
      ShopBundle/Form/Frontend/TicketType.php
  2. +17
    -0
      ShopBundle/Model/TicketMessage.php
  3. +45
    -4
      ShopBundle/Services/TicketUtils.php

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

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

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

+ 45
- 4
ShopBundle/Services/TicketUtils.php Vedi File

@@ -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() ;

Loading…
Annulla
Salva