|
|
@@ -4,7 +4,9 @@ namespace Lc\ShopBundle\Form\Frontend; |
|
|
|
|
|
|
|
use App\Entity\Address; |
|
|
|
use App\Entity\OrderShop; |
|
|
|
use Captcha\Bundle\CaptchaBundle\Form\Type\CaptchaType; |
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
use Lc\ShopBundle\Context\TicketInterface; |
|
|
|
use Lc\ShopBundle\Model\Ticket; |
|
|
|
use Lc\ShopBundle\Services\UtilsManager; |
|
|
|
use Symfony\Bridge\Doctrine\Form\Type\EntityType; |
|
|
@@ -21,106 +23,158 @@ use Symfony\Component\Validator\Constraints\File; |
|
|
|
|
|
|
|
class TicketType extends AbstractType |
|
|
|
{ |
|
|
|
protected $orderShopRepository ; |
|
|
|
protected $security ; |
|
|
|
protected $em ; |
|
|
|
protected $priceUtils ; |
|
|
|
protected $utils ; |
|
|
|
protected $orderShopRepository; |
|
|
|
protected $security; |
|
|
|
protected $em; |
|
|
|
protected $priceUtils; |
|
|
|
protected $utils; |
|
|
|
|
|
|
|
public function __construct(Security $security, EntityManagerInterface $em, UtilsManager $utilsManager) |
|
|
|
{ |
|
|
|
$this->security = $security ; |
|
|
|
$this->em = $em ; |
|
|
|
$this->orderShopRepository = $this->em->getRepository(OrderShop::class) ; |
|
|
|
$this->priceUtils = $utilsManager->getPriceUtils() ; |
|
|
|
$this->utils = $utilsManager->getUtils() ; |
|
|
|
} |
|
|
|
public function __construct(Security $security, EntityManagerInterface $em, UtilsManager $utilsManager) |
|
|
|
{ |
|
|
|
$this->security = $security; |
|
|
|
$this->em = $em; |
|
|
|
$this->orderShopRepository = $this->em->getRepository(OrderShop::class); |
|
|
|
$this->priceUtils = $utilsManager->getPriceUtils(); |
|
|
|
$this->utils = $utilsManager->getUtils(); |
|
|
|
} |
|
|
|
|
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
|
|
|
{ |
|
|
|
$isConnected = $this->security->getUser() ; |
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
|
|
|
{ |
|
|
|
$isConnected = $this->security->getUser(); |
|
|
|
|
|
|
|
if(!$isConnected) { |
|
|
|
$builder->add('visitorFirstname', TextType::class, [ |
|
|
|
'label' => 'Prénom' |
|
|
|
]) |
|
|
|
->add('visitorLastname', TextType::class, [ |
|
|
|
'label' => 'Nom' |
|
|
|
]) |
|
|
|
->add('visitorEmail', EmailType::class, [ |
|
|
|
'label' => 'Email' |
|
|
|
]) ; |
|
|
|
} |
|
|
|
if (!$isConnected) { |
|
|
|
$builder->add( |
|
|
|
'visitorFirstname', |
|
|
|
TextType::class, |
|
|
|
[ |
|
|
|
'label' => 'Prénom' |
|
|
|
] |
|
|
|
) |
|
|
|
->add( |
|
|
|
'visitorLastname', |
|
|
|
TextType::class, |
|
|
|
[ |
|
|
|
'label' => 'Nom' |
|
|
|
] |
|
|
|
) |
|
|
|
->add( |
|
|
|
'visitorEmail', |
|
|
|
EmailType::class, |
|
|
|
[ |
|
|
|
'label' => 'Email' |
|
|
|
] |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
$builder |
|
|
|
->add('type', ChoiceType::class, [ |
|
|
|
$builder |
|
|
|
->add( |
|
|
|
'type', |
|
|
|
ChoiceType::class, |
|
|
|
[ |
|
|
|
'label' => 'field.Ticket.type', |
|
|
|
'multiple' => false, |
|
|
|
'expanded' => false, |
|
|
|
'choices' => [ |
|
|
|
'field.Ticket.typeOptions.'.Ticket::TYPE_GENERAL_QUESTION => Ticket::TYPE_GENERAL_QUESTION, |
|
|
|
'field.Ticket.typeOptions.'.Ticket::TYPE_PRODUCT_UNAVAILABLE => Ticket::TYPE_PRODUCT_UNAVAILABLE, |
|
|
|
'field.Ticket.typeOptions.'.Ticket::TYPE_PRODUCT_ERROR => Ticket::TYPE_PRODUCT_ERROR, |
|
|
|
'field.Ticket.typeOptions.'.Ticket::TYPE_TECHNICAL_PROBLEM => Ticket::TYPE_TECHNICAL_PROBLEM, |
|
|
|
'field.Ticket.typeOptions.'.Ticket::TYPE_POULTRY_BOOKING => Ticket::TYPE_POULTRY_BOOKING, |
|
|
|
'field.Ticket.typeOptions.' . Ticket::TYPE_GENERAL_QUESTION => Ticket::TYPE_GENERAL_QUESTION, |
|
|
|
'field.Ticket.typeOptions.' . Ticket::TYPE_PRODUCT_UNAVAILABLE => Ticket::TYPE_PRODUCT_UNAVAILABLE, |
|
|
|
'field.Ticket.typeOptions.' . Ticket::TYPE_PRODUCT_ERROR => Ticket::TYPE_PRODUCT_ERROR, |
|
|
|
'field.Ticket.typeOptions.' . Ticket::TYPE_TECHNICAL_PROBLEM => Ticket::TYPE_TECHNICAL_PROBLEM, |
|
|
|
'field.Ticket.typeOptions.' . Ticket::TYPE_POULTRY_BOOKING => Ticket::TYPE_POULTRY_BOOKING, |
|
|
|
], |
|
|
|
'translation_domain' => 'lcshop', |
|
|
|
]) ; |
|
|
|
] |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if($isConnected) { |
|
|
|
$builder->add('orderShop', EntityType::class, [ |
|
|
|
'class' => $this->em->getClassMetadata(OrderShop::class)->getName(), |
|
|
|
'multiple' => false, |
|
|
|
'expanded' => false, |
|
|
|
'choices' => $this->orderShopRepository->findAllBy([ |
|
|
|
'user' => $this->security->getUser(), |
|
|
|
'isValid' => true |
|
|
|
]), |
|
|
|
'label' => 'field.default.order', |
|
|
|
'placeholder' => '-- Choisissez une commande --', |
|
|
|
'required' => false, |
|
|
|
'choice_label' => function ($orderShop, $key, $value) { |
|
|
|
return 'Commande du '.$orderShop->getValidationDate()->format('d/m/Y').' ('.number_format($this->priceUtils->getTotalWithTax($orderShop), 2).' €)' ; |
|
|
|
}, |
|
|
|
'translation_domain' => 'lcshop', |
|
|
|
]) ; |
|
|
|
} |
|
|
|
else { |
|
|
|
// captcha |
|
|
|
$this->utils->addCaptchaType($builder); |
|
|
|
} |
|
|
|
|
|
|
|
if ($isConnected) { |
|
|
|
$builder->add( |
|
|
|
'orderShop', |
|
|
|
EntityType::class, |
|
|
|
[ |
|
|
|
'class' => $this->em->getClassMetadata(OrderShop::class)->getName(), |
|
|
|
'multiple' => false, |
|
|
|
'expanded' => false, |
|
|
|
'choices' => $this->orderShopRepository->findAllBy( |
|
|
|
[ |
|
|
|
'user' => $this->security->getUser(), |
|
|
|
'isValid' => true |
|
|
|
] |
|
|
|
), |
|
|
|
'label' => 'field.default.order', |
|
|
|
'placeholder' => '-- Choisissez une commande --', |
|
|
|
'required' => false, |
|
|
|
'choice_label' => function ($orderShop, $key, $value) { |
|
|
|
return 'Commande du ' . $orderShop->getValidationDate()->format( |
|
|
|
'd/m/Y' |
|
|
|
) . ' (' . number_format( |
|
|
|
$this->priceUtils->getTotalWithTax($orderShop), |
|
|
|
2 |
|
|
|
) . ' €)'; |
|
|
|
}, |
|
|
|
'translation_domain' => 'lcshop', |
|
|
|
] |
|
|
|
); |
|
|
|
} else { |
|
|
|
// captcha |
|
|
|
//$this->utils->addCaptchaType($builder); |
|
|
|
} |
|
|
|
|
|
|
|
$builder->add('subject', TextType::class, [ |
|
|
|
'label' => 'Sujet' |
|
|
|
]) |
|
|
|
->add('message', TextareaType::class, [ |
|
|
|
$builder->add( |
|
|
|
'subject', |
|
|
|
TextType::class, |
|
|
|
[ |
|
|
|
'label' => 'Sujet' |
|
|
|
] |
|
|
|
) |
|
|
|
->add( |
|
|
|
'message', |
|
|
|
TextareaType::class, |
|
|
|
[ |
|
|
|
'mapped' => false, |
|
|
|
'label' => 'Message' |
|
|
|
]) |
|
|
|
->add('image', FileType::class, [ |
|
|
|
] |
|
|
|
) |
|
|
|
->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)", |
|
|
|
]) |
|
|
|
new File( |
|
|
|
[ |
|
|
|
'maxSize' => '2048k', |
|
|
|
'mimeTypes' => [ |
|
|
|
'image/png', |
|
|
|
'image/jpeg', |
|
|
|
'image/jpg', |
|
|
|
'image/gif', |
|
|
|
], |
|
|
|
'mimeTypesMessage' => "Mauvais format d'image (formats acceptés : jpeg, png, gif)", |
|
|
|
] |
|
|
|
) |
|
|
|
], |
|
|
|
]); |
|
|
|
} |
|
|
|
] |
|
|
|
); |
|
|
|
|
|
|
|
public function configureOptions(OptionsResolver $resolver) |
|
|
|
{ |
|
|
|
$resolver->setDefaults([ |
|
|
|
// Configure your form options here |
|
|
|
]); |
|
|
|
} |
|
|
|
$builder->add( |
|
|
|
'captchaCode', |
|
|
|
CaptchaType::class, |
|
|
|
array( |
|
|
|
'captchaConfig' => 'TicketCaptcha', |
|
|
|
'label' => 'Recopiez les caractères de l\'image' |
|
|
|
) |
|
|
|
); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public function configureOptions(OptionsResolver $resolver) |
|
|
|
{ |
|
|
|
$resolver->setDefaults( |
|
|
|
[ |
|
|
|
'data_class' => $this->em->getClassMetadata(TicketInterface::class)->getName() |
|
|
|
] |
|
|
|
); |
|
|
|
} |
|
|
|
} |