|
|
@@ -0,0 +1,88 @@ |
|
|
|
<?php |
|
|
|
|
|
|
|
namespace Lc\ShopBundle\Form; |
|
|
|
|
|
|
|
use Lc\ShopBundle\Context\MerchantConfigInterface; |
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; |
|
|
|
use Symfony\Component\Form\Extension\Core\Type\HiddenType; |
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType; |
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
use Symfony\Component\Form\AbstractType; |
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
|
|
use Symfony\Component\Form\FormEvent; |
|
|
|
use Symfony\Component\Form\FormEvents; |
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
|
|
|
use Symfony\Component\Security\Core\Security; |
|
|
|
|
|
|
|
class MerchantConfigType extends AbstractType |
|
|
|
{ |
|
|
|
protected $em; |
|
|
|
|
|
|
|
public function __construct(EntityManagerInterface $entityManager, Security $security) |
|
|
|
{ |
|
|
|
$this->em = $entityManager; |
|
|
|
} |
|
|
|
|
|
|
|
public function buildForm(FormBuilderInterface $builder, array $options) |
|
|
|
{ |
|
|
|
|
|
|
|
$builder->addEventListener(FormEvents::PRE_SET_DATA, function (FormEvent $event) { |
|
|
|
$form = $event->getForm(); |
|
|
|
$merchantConfig = $event->getData(); |
|
|
|
|
|
|
|
if ($merchantConfig) { |
|
|
|
|
|
|
|
switch ($merchantConfig->getName()) { |
|
|
|
case 'order-open-day' : |
|
|
|
$label = 'Jour d\'ouverture des commandes'; |
|
|
|
break; |
|
|
|
case 'order-open-time' : |
|
|
|
$label = 'Heure d\'ouverture des commandes'; |
|
|
|
break; |
|
|
|
case 'order-close-day' : |
|
|
|
$label = 'Jour de fermeture des commandes'; |
|
|
|
break; |
|
|
|
case 'order-close-time' : |
|
|
|
$label = 'Heure de fermeture des commandes'; |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
$choicesArray = [] ; |
|
|
|
|
|
|
|
if (strpos($merchantConfig->getName(), 'time') !== false) { |
|
|
|
for($i = 0; $i < 24 ; $i++) { |
|
|
|
$choicesArray[$i.'h'] = $i.':00' ; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (strpos($merchantConfig->getName(), 'day') !== false) { |
|
|
|
$choicesArray = [ |
|
|
|
'Lundi' => 1, |
|
|
|
'Mardi' => 2, |
|
|
|
'Mercredi' => 3, |
|
|
|
'Jeudi' => 4, |
|
|
|
'Vendredi' => 5, |
|
|
|
'Samedi' => 6, |
|
|
|
'Dimanche' => 7, |
|
|
|
] ; |
|
|
|
} |
|
|
|
|
|
|
|
$form->add('name', HiddenType::class) |
|
|
|
->add('value', ChoiceType::class, [ |
|
|
|
'label' => $label, |
|
|
|
'choices' => $choicesArray |
|
|
|
]); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public function configureOptions(OptionsResolver $resolver) |
|
|
|
{ |
|
|
|
$resolver->setDefaults([ |
|
|
|
'label' => false, |
|
|
|
'data_class' => $this->em->getClassMetadata(MerchantConfigInterface::class)->getName(), |
|
|
|
]); |
|
|
|
} |
|
|
|
} |
|
|
|
|