@@ -3,11 +3,8 @@ | |||
namespace Lc\CaracoleBundle\Controller\Merchant; | |||
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType; | |||
use Lc\CaracoleBundle\Resolver\MerchantResolver; | |||
use Lc\SovBundle\Doctrine\EntityManager; | |||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | |||
use Symfony\Component\HttpFoundation\Request; | |||
use Symfony\Component\Security\Core\Security; | |||
class SwitchMerchantController extends AbstractController | |||
{ |
@@ -0,0 +1,86 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Controller\Setting; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface; | |||
use Lc\CaracoleBundle\Form\Setting\MerchantSettingsFormType; | |||
use Lc\CaracoleBundle\Form\Setting\SectionSettingsFormType; | |||
use Lc\CaracoleBundle\Resolver\MerchantResolver; | |||
use Lc\CaracoleBundle\Resolver\SectionResolver; | |||
use Lc\CaracoleBundle\Definition\SectionSettingDefinitionInterface; | |||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | |||
use Symfony\Component\HttpFoundation\Request; | |||
class SettingAdminController extends AbstractController | |||
{ | |||
protected $em; | |||
protected $merchantResolver; | |||
protected $merchantSettingDefinition; | |||
protected $sectionResolver; | |||
protected $sectionSettingDefinition; | |||
public function __construct( | |||
EntityManagerInterface $em, | |||
MerchantResolver $merchantResolver, | |||
SectionResolver $sectionResolver, | |||
MerchantSettingDefinitionInterface $merchantSettingDefinition, | |||
SectionSettingDefinitionInterface $sectionSettingDefinition | |||
) { | |||
$this->em = $em; | |||
$this->merchantResolver = $merchantResolver; | |||
$this->sectionResolver = $sectionResolver; | |||
$this->merchantSettingDefinition = $merchantSettingDefinition; | |||
$this->sectionSettingDefinition = $sectionSettingDefinition; | |||
} | |||
public function manageMerchant(Request $request) | |||
{ | |||
return $this->manage($request, 'merchant'); | |||
} | |||
public function manageSection(Request $request) | |||
{ | |||
return $this->manage($request, 'section'); | |||
} | |||
public function manage(Request $request, $type) | |||
{ | |||
$entity = null ; | |||
if ($type == 'merchant') { | |||
$resolver = $this->merchantResolver ; | |||
$formClass = MerchantSettingsFormType::class; | |||
$settingDefinition = $this->merchantSettingDefinition ; | |||
} elseif ($type == 'section') { | |||
$resolver = $this->sectionResolver ; | |||
$formClass = SectionSettingsFormType::class; | |||
$settingDefinition = $this->sectionSettingDefinition ; | |||
} | |||
$entity = $resolver->getCurrent(); | |||
if ($entity) { | |||
$form = $this->createForm($formClass, $entity); | |||
$form->handleRequest($request); | |||
if ($form->isSubmitted() && $form->isValid()) { | |||
$this->em->update($entity); | |||
$this->em->flush(); | |||
$this->addFlash('success', 'Paramètres mis à jour'); | |||
} | |||
return $this->render( | |||
'@LcCaracole/admin/setting/' . $type . '.html.twig', | |||
[ | |||
'resolver' => $resolver, | |||
'setting_definition' => $settingDefinition, | |||
'form' => $form->createView() | |||
] | |||
); | |||
} | |||
} | |||
} |
@@ -0,0 +1,129 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Definition; | |||
abstract class AbstractSettingDefinition | |||
{ | |||
protected $settings = []; | |||
public function addSettingText(array $params): self | |||
{ | |||
$params['type'] = 'text' ; | |||
$params['field'] = 'text' ; | |||
return $this->addSetting($params); | |||
} | |||
public function addSettingTextarea(array $params): self | |||
{ | |||
$params['type'] = 'textarea' ; | |||
$params['field'] = 'text' ; | |||
return $this->addSetting($params); | |||
} | |||
public function addSettingTextareaAdvanced(array $params): self | |||
{ | |||
$params['type'] = 'textarea_advanced' ; | |||
$params['field'] = 'text' ; | |||
return $this->addSetting($params); | |||
} | |||
public function addSettingDate(array $params): self | |||
{ | |||
$params['type'] = 'date' ; | |||
$params['field'] = 'date' ; | |||
return $this->addSetting($params); | |||
} | |||
public function addSettingTime(array $params): self | |||
{ | |||
$params['type'] = 'time' ; | |||
$params['field'] = 'date' ; | |||
return $this->addSetting($params); | |||
} | |||
public function addSettingFile(array $params): self | |||
{ | |||
$params['type'] = 'file' ; | |||
$params['field'] = 'file' ; | |||
return $this->addSetting($params); | |||
} | |||
public function addSettingImage(array $params): self | |||
{ | |||
$params['type'] = 'image' ; | |||
$params['field'] = 'file' ; | |||
return $this->addSetting($params); | |||
} | |||
public function addSettingSelect(array $params): self | |||
{ | |||
$params['type'] = 'select' ; | |||
$params['field'] = 'text' ; | |||
return $this->addSetting($params); | |||
} | |||
public function addSettingRadio(array $params): self | |||
{ | |||
$params['type'] = 'radio' ; | |||
$params['field'] = 'text' ; | |||
return $this->addSetting($params); | |||
} | |||
public function addSetting($params) | |||
{ | |||
$name = $params['name'] ; | |||
$category = $params['category'] ; | |||
if (!isset($this->settings[$category])) { | |||
$this->settings[$category] = []; | |||
} | |||
$this->settings[$category][$name] = $params; | |||
return $this ; | |||
} | |||
public function getSettings(): array | |||
{ | |||
return $this->settings; | |||
} | |||
public function getSettingsByCategory($category) | |||
{ | |||
$settings = $this->getSettings(); | |||
if (isset($settings[$category])) { | |||
return $settings[$category]; | |||
} | |||
return []; | |||
} | |||
public function getSettingByName($name): ?array | |||
{ | |||
$settings = $this->getSettings(); | |||
foreach ($settings as $category => $settingsCategory) { | |||
foreach ($settingsCategory as $nameSetting => $setting) { | |||
if ($nameSetting == $name) { | |||
return $setting; | |||
} | |||
} | |||
} | |||
return null; | |||
} | |||
public function getSettingType($name): ?string | |||
{ | |||
$setting = $this->getSettingByName($name); | |||
if ($setting) { | |||
return $setting['type']; | |||
} | |||
return null; | |||
} | |||
} |
@@ -0,0 +1,10 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Definition; | |||
interface MerchantSettingDefinitionInterface | |||
{ | |||
} |
@@ -0,0 +1,10 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Definition; | |||
interface SectionSettingDefinitionInterface | |||
{ | |||
} |
@@ -0,0 +1,112 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\EventSubscriber; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface; | |||
use Lc\CaracoleBundle\Factory\Setting\MerchantSettingFactory; | |||
use Lc\CaracoleBundle\Factory\Setting\SectionSettingFactory; | |||
use Lc\CaracoleBundle\Factory\User\UserMerchantFactory; | |||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | |||
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository; | |||
use Lc\CaracoleBundle\Definition\SectionSettingDefinitionInterface; | |||
use Lc\CaracoleBundle\Repository\Section\SectionRepository; | |||
use Lc\CaracoleBundle\Resolver\MerchantResolver; | |||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |||
use Symfony\Component\HttpKernel\KernelEvents; | |||
use Symfony\Component\Security\Core\Security; | |||
class SettingEventSubscriber implements EventSubscriberInterface | |||
{ | |||
protected $em; | |||
protected $merchantRepository; | |||
protected $sectionRepository; | |||
protected $merchantSettingDefinition; | |||
protected $sectionSettingDefinition; | |||
protected $merchantSettingFactory; | |||
protected $sectionSettingFactory; | |||
public function __construct( | |||
EntityManagerInterface $em, | |||
MerchantSettingDefinitionInterface $merchantSettingDefinition, | |||
SectionSettingDefinitionInterface $sectionSettingDefinition, | |||
MerchantRepository $merchantRepository, | |||
SectionRepository $sectionRepository, | |||
MerchantSettingFactory $merchantSettingFactory, | |||
SectionSettingFactory $sectionSettingFactory | |||
) { | |||
$this->em = $em; | |||
$this->merchantRepository = $merchantRepository; | |||
$this->sectionRepository = $sectionRepository; | |||
$this->merchantSettingDefinition = $merchantSettingDefinition; | |||
$this->sectionSettingDefinition = $sectionSettingDefinition; | |||
$this->merchantSettingFactory = $merchantSettingFactory; | |||
$this->sectionSettingFactory = $sectionSettingFactory; | |||
} | |||
public static function getSubscribedEvents() | |||
{ | |||
return [ | |||
KernelEvents::CONTROLLER => ['initSettings'] | |||
]; | |||
} | |||
public function initSettings() | |||
{ | |||
$this->initSettingsGeneric( | |||
'merchant', | |||
$this->merchantSettingDefinition->getSettings(), | |||
$this->merchantRepository->findAll(), | |||
$this->merchantSettingFactory | |||
); | |||
$this->initSettingsGeneric( | |||
'section', | |||
$this->sectionSettingDefinition->getSettings(), | |||
$this->sectionRepository->findAll(), | |||
$this->sectionSettingFactory | |||
); | |||
} | |||
public function initSettingsGeneric($type, $settings, $entities, $factory) | |||
{ | |||
foreach ($entities as $entity) { | |||
foreach ($settings as $category => $settingList) { | |||
foreach ($settingList as $settingName => $setting) { | |||
$entitySetting = $entity->getSetting($settingName); | |||
if (!$entitySetting) { | |||
// gestion du cas des SectionSetting spécifiques à une section | |||
$createEntitySetting = true; | |||
if ($entity instanceof SectionInterface && isset($setting['section']) && $setting['section'] != $entity) { | |||
$createEntitySetting = false; | |||
} | |||
if ($createEntitySetting) { | |||
$entitySetting = $factory->create( | |||
[ | |||
$type => $entity, | |||
'name' => $setting['name'], | |||
$setting['field'] => isset($setting['default']) ? $setting['default'] : null, | |||
] | |||
); | |||
$this->em->persist($entitySetting); | |||
} | |||
} else { | |||
if ($entitySetting->getValue() === null | |||
&& isset($setting['default']) | |||
&& $setting['default'] !== null) { | |||
$methodSetValue = 'set' . ucfirst($setting['field']); | |||
$entitySetting->$methodSetValue($setting['default']); | |||
$this->em->update($entitySetting); | |||
} | |||
} | |||
} | |||
} | |||
} | |||
$this->em->flush(); | |||
} | |||
} |
@@ -0,0 +1,14 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Factory\Setting; | |||
use Lc\CaracoleBundle\Model\Setting\MerchantSettingInterface; | |||
use Lc\SovBundle\Factory\AbstractFactory; | |||
class MerchantSettingFactory extends AbstractFactory | |||
{ | |||
public function getEntityClass() | |||
{ | |||
return MerchantSettingInterface::class; | |||
} | |||
} |
@@ -0,0 +1,14 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Factory\Setting; | |||
use Lc\CaracoleBundle\Model\Setting\SectionSettingInterface; | |||
use Lc\SovBundle\Factory\AbstractFactory; | |||
class SectionSettingFactory extends AbstractFactory | |||
{ | |||
public function getEntityClass() | |||
{ | |||
return SectionSettingInterface::class; | |||
} | |||
} |
@@ -0,0 +1,14 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Factory\User; | |||
use Lc\CaracoleBundle\Model\User\UserMerchantInterface; | |||
use Lc\SovBundle\Factory\AbstractFactory; | |||
class UserMerchantFactory extends AbstractFactory | |||
{ | |||
public function getEntityClass() | |||
{ | |||
return UserMerchantInterface::class; | |||
} | |||
} |
@@ -0,0 +1,164 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Form\Setting; | |||
use FOS\CKEditorBundle\Form\Type\CKEditorType; | |||
use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface; | |||
use Lc\CaracoleBundle\Model\Setting\MerchantSettingInterface; | |||
use Lc\CaracoleBundle\Model\Setting\SectionSettingInterface; | |||
use Lc\CaracoleBundle\Definition\SectionSettingDefinitionInterface; | |||
use Lc\SovBundle\Form\Common\FileManagerType; | |||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | |||
use Symfony\Component\Form\Extension\Core\Type\DateType; | |||
use Symfony\Component\Form\Extension\Core\Type\HiddenType; | |||
use Symfony\Component\Form\Extension\Core\Type\TextareaType; | |||
use Symfony\Component\Form\Extension\Core\Type\TextType; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Symfony\Component\Form\AbstractType; | |||
use Symfony\Component\Form\Extension\Core\Type\TimeType; | |||
use Symfony\Component\Form\FormBuilderInterface; | |||
use Symfony\Component\Form\FormEvent; | |||
use Symfony\Component\Form\FormEvents; | |||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||
abstract class BaseSettingType extends AbstractType | |||
{ | |||
protected $em; | |||
protected $merchantSetup; | |||
protected $sectionSetup; | |||
public function __construct( | |||
EntityManagerInterface $entityManager, | |||
MerchantSettingDefinitionInterface $merchantSetup, | |||
SectionSettingDefinitionInterface $sectionSetup | |||
) { | |||
$this->em = $entityManager; | |||
$this->merchantSetup = $merchantSetup; | |||
$this->sectionSetup = $sectionSetup; | |||
} | |||
public function buildForm(FormBuilderInterface $builder, array $options) | |||
{ | |||
$merchantSetup = $this->merchantSetup; | |||
$sectionSetup = $this->sectionSetup; | |||
$builder->addEventListener( | |||
FormEvents::PRE_SET_DATA, | |||
function (FormEvent $event) use ($merchantSetup, $sectionSetup) { | |||
$form = $event->getForm(); | |||
$settingEntity = $event->getData(); | |||
if ($settingEntity) { | |||
$form->add('name', HiddenType::class); | |||
$settingName = $settingEntity->getName(); | |||
$transCategory = 'undefined' ; | |||
$setup = null ; | |||
if($settingEntity instanceof MerchantSettingInterface) { | |||
$transCategory = 'merchant' ; | |||
$setup = $merchantSetup ; | |||
} | |||
elseif($settingEntity instanceof SectionSettingInterface) { | |||
$transCategory = 'section' ; | |||
$setup = $sectionSetup ; | |||
} | |||
$label = 'setting_definition.'.$transCategory.'.settings.'.$settingName ; | |||
if($setup) { | |||
$setting = $setup->getSettingByName($settingName); | |||
$settingType = $setup->getSettingType($settingName); | |||
if ($settingType == 'text') { | |||
$form->add( | |||
'text', | |||
TextType::class, | |||
[ | |||
'label' => $label | |||
] | |||
); | |||
} | |||
elseif ($settingType == 'textarea') { | |||
$form->add( | |||
'text', | |||
TextareaType::class, | |||
[ | |||
'label' => $label | |||
] | |||
); | |||
} | |||
elseif ($settingType == 'textarea_advanced') { | |||
$form->add( | |||
'text', | |||
CKEditorType::class, | |||
[ | |||
'label' => $label | |||
] | |||
); | |||
} elseif ($settingType == 'select') { | |||
$form->add( | |||
'text', | |||
ChoiceType::class, | |||
[ | |||
'label' => $label, | |||
'expanded' => false, | |||
'multiple' => false, | |||
'placeholder' => false, | |||
'choices' => $setting['choices'] | |||
] | |||
); | |||
} elseif ($settingType == 'radio') { | |||
$form->add( | |||
'text', | |||
ChoiceType::class, | |||
[ | |||
'label' => $label, | |||
'expanded' => true, | |||
'multiple' => false, | |||
'placeholder' => false, | |||
'choices' => $setting['choices'] | |||
] | |||
); | |||
} | |||
elseif ($settingType == 'date') { | |||
$form->add( | |||
'date', | |||
DateType::class, | |||
[ | |||
'label' => $label, | |||
'widget' => 'single_text', | |||
] | |||
); | |||
} | |||
elseif ($settingType == 'time') { | |||
$form->add( | |||
'date', | |||
TimeType::class, | |||
[ | |||
'label' => $label, | |||
'input' => 'datetime', | |||
'widget' => 'single_text', | |||
] | |||
); | |||
} | |||
elseif ($settingType == 'file' || $settingType == 'image') { | |||
$form->add( | |||
'file', | |||
FileManagerType::class, | |||
[ | |||
'label' => $label, | |||
'attr' => [ | |||
'type' => $settingType | |||
] | |||
] | |||
); | |||
} | |||
} | |||
} | |||
} | |||
); | |||
} | |||
} | |||
@@ -0,0 +1,21 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Form\Setting; | |||
use Lc\CaracoleBundle\Model\Setting\MerchantSettingInterface; | |||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||
class MerchantSettingType extends BaseSettingType | |||
{ | |||
public function configureOptions(OptionsResolver $resolver) | |||
{ | |||
$resolver->setDefaults( | |||
[ | |||
'label' => false, | |||
'data_class' => $this->em->getEntityName(MerchantSettingInterface::class), | |||
] | |||
); | |||
} | |||
} | |||
@@ -0,0 +1,52 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Form\Setting; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | |||
use Symfony\Component\Form\AbstractType; | |||
use Symfony\Component\Form\Extension\Core\Type\CollectionType; | |||
use Symfony\Component\Form\Extension\Core\Type\HiddenType; | |||
use Symfony\Component\Form\Extension\Core\Type\SubmitType; | |||
use Symfony\Component\Form\FormBuilderInterface; | |||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||
class MerchantSettingsFormType extends AbstractType | |||
{ | |||
protected $em; | |||
public function __construct(EntityManagerInterface $em) | |||
{ | |||
$this->em = $em; | |||
} | |||
public function buildForm(FormBuilderInterface $builder, array $options) | |||
{ | |||
$builder->add( | |||
'settings', | |||
CollectionType::class, | |||
[ | |||
'entry_type' => MerchantSettingType::class, | |||
'required' => false, | |||
'allow_add' => false, | |||
'allow_delete' => false, | |||
'by_reference' => false | |||
] | |||
); | |||
} | |||
/** | |||
* {@inheritdoc} | |||
*/ | |||
public function configureOptions(OptionsResolver $resolver) | |||
{ | |||
$resolver->setDefaults( | |||
[ | |||
'data_class' => $this->em->getEntityName(MerchantInterface::class), | |||
] | |||
); | |||
} | |||
} |
@@ -0,0 +1,21 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Form\Setting; | |||
use Lc\CaracoleBundle\Model\Setting\SectionSettingInterface; | |||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||
class SectionSettingType extends BaseSettingType | |||
{ | |||
public function configureOptions(OptionsResolver $resolver) | |||
{ | |||
$resolver->setDefaults( | |||
[ | |||
'label' => false, | |||
'data_class' => $this->em->getEntityName(SectionSettingInterface::class), | |||
] | |||
); | |||
} | |||
} | |||
@@ -0,0 +1,48 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Form\Setting; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | |||
use Symfony\Component\Form\AbstractType; | |||
use Symfony\Component\Form\Extension\Core\Type\CollectionType; | |||
use Symfony\Component\Form\FormBuilderInterface; | |||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||
class SectionSettingsFormType extends AbstractType | |||
{ | |||
protected $em; | |||
public function __construct(EntityManagerInterface $em) | |||
{ | |||
$this->em = $em; | |||
} | |||
public function buildForm(FormBuilderInterface $builder, array $options) | |||
{ | |||
$builder->add( | |||
'settings', | |||
CollectionType::class, | |||
[ | |||
'entry_type' => SectionSettingType::class, | |||
'required' => false, | |||
'allow_add' => false, | |||
'allow_delete' => false, | |||
'by_reference' => false | |||
] | |||
); | |||
} | |||
/** | |||
* {@inheritdoc} | |||
*/ | |||
public function configureOptions(OptionsResolver $resolver) | |||
{ | |||
$resolver->setDefaults( | |||
[ | |||
'data_class' => $this->em->getEntityName(SectionInterface::class), | |||
] | |||
); | |||
} | |||
} |
@@ -1,8 +0,0 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Model\Merchant; | |||
interface MerchantConfigInterface | |||
{ | |||
} |
@@ -1,126 +0,0 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Model\Merchant; | |||
use Doctrine\ORM\Mapping as ORM; | |||
use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity; | |||
use Lc\SovBundle\Model\File\FileInterface; | |||
/** | |||
* @ORM\MappedSuperclass() | |||
* @Vich\Uploadable | |||
*/ | |||
abstract class MerchantConfigModel extends AbstractLightEntity | |||
{ | |||
/** | |||
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface", inversedBy="merchantConfigs") | |||
* @ORM\JoinColumn(nullable=false) | |||
*/ | |||
protected $merchant; | |||
/** | |||
* @ORM\Column(type="string", length=63) | |||
*/ | |||
protected $name; | |||
/** | |||
* @ORM\Column(type="text", nullable=true) | |||
*/ | |||
protected $value; | |||
/** | |||
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\File\FileInterface", cascade={"persist", "remove"}) | |||
*/ | |||
protected $image; | |||
public static $availableOptions = []; | |||
public function getMerchant(): ?MerchantInterface | |||
{ | |||
return $this->merchant; | |||
} | |||
public function setMerchant(?MerchantInterface $merchant): self | |||
{ | |||
$this->merchant = $merchant; | |||
return $this; | |||
} | |||
public function getName(): ?string | |||
{ | |||
return $this->name; | |||
} | |||
public function setName(string $name): self | |||
{ | |||
$this->name = $name; | |||
return $this; | |||
} | |||
public function getValue(): ?string | |||
{ | |||
return $this->value; | |||
} | |||
public function setValue($value): self | |||
{ | |||
$this->value = $value; | |||
return $this; | |||
} | |||
public function getImage(): ?FileInterface | |||
{ | |||
return $this->image; | |||
} | |||
public function setImage(?FileInterface $image): self | |||
{ | |||
$this->image = $image; | |||
return $this; | |||
} | |||
public static function getAvailableOptions(): array | |||
{ | |||
return static::$availableOptions; | |||
} | |||
public function getOption() | |||
{ | |||
if (isset(static::$availableOptions[$this->getName()])) { | |||
return static::$availableOptions[$this->getName()]; | |||
} | |||
return false; | |||
} | |||
public function getOptionValue($key, $default = '') | |||
{ | |||
$option = $this->getOption(); | |||
if ($option) { | |||
if (isset($option[$key])) { | |||
return $option[$key]; | |||
} | |||
} | |||
return $default; | |||
} | |||
public function getLabel() | |||
{ | |||
return 'field.MerchantConfig.' . $this->getOptionValue('id'); | |||
} | |||
public function getFieldType() | |||
{ | |||
return $this->getOptionValue('type', 'text'); | |||
} | |||
public function getDefaultValue() | |||
{ | |||
return $this->getOptionValue('default'); | |||
} | |||
} |
@@ -12,6 +12,8 @@ use Lc\CaracoleBundle\Model\Newsletter\NewsletterInterface; | |||
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface; | |||
use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface; | |||
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | |||
use Lc\CaracoleBundle\Model\Setting\EntitySettingTrait; | |||
use Lc\CaracoleBundle\Model\Setting\MerchantSettingInterface; | |||
use Lc\CaracoleBundle\Model\Site\NewsInterface; | |||
use Lc\CaracoleBundle\Model\Site\PageInterface; | |||
use Lc\CaracoleBundle\Model\User\GroupUserInterface; | |||
@@ -22,6 +24,9 @@ use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity; | |||
*/ | |||
abstract class MerchantModel extends AbstractFullEntity | |||
{ | |||
use EntitySettingTrait; | |||
/** | |||
* @ORM\OneToOne(targetEntity="Lc\CaracoleBundle\Model\Credit\CreditConfigInterface", cascade={"persist", "remove"}) | |||
* @ORM\JoinColumn(nullable=true) | |||
@@ -44,11 +49,6 @@ abstract class MerchantModel extends AbstractFullEntity | |||
*/ | |||
protected $productFamilies; | |||
/** | |||
* @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantConfigInterface", mappedBy="merchant", orphanRemoval=true, cascade={"persist"}) | |||
*/ | |||
protected $merchantConfigs; | |||
/** | |||
* @ORM\OneToOne(targetEntity="Lc\CaracoleBundle\Model\Address\AddressInterface", inversedBy="merchant", cascade={"persist", "remove"}) | |||
* @ORM\JoinColumn(nullable=true) | |||
@@ -80,12 +80,16 @@ abstract class MerchantModel extends AbstractFullEntity | |||
*/ | |||
protected $groupUsers; | |||
/** | |||
* @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Setting\MerchantSettingInterface", mappedBy="merchant", orphanRemoval=true, cascade={"persist"}, fetch="EAGER") | |||
*/ | |||
protected $settings; | |||
public function __construct() | |||
{ | |||
$this->pointSales = new ArrayCollection(); | |||
$this->productFamilies = new ArrayCollection(); | |||
$this->merchantConfigs = new ArrayCollection(); | |||
$this->productCategories = new ArrayCollection(); | |||
$this->news = new ArrayCollection(); | |||
$this->groupUsers = new ArrayCollection(); | |||
@@ -181,49 +185,36 @@ abstract class MerchantModel extends AbstractFullEntity | |||
} | |||
/** | |||
* @return Collection|MerchantConfigInterface[] | |||
* @return Collection|MerchantSettingInterface[] | |||
*/ | |||
public function getMerchantConfigs(): Collection | |||
public function getSettings(): Collection | |||
{ | |||
return $this->merchantConfigs; | |||
return $this->settings; | |||
} | |||
public function addMerchantConfig(MerchantConfigInterface $merchantConfig): self | |||
public function addSetting(MerchantSettingInterface $merchantSetting): self | |||
{ | |||
if (!$this->merchantConfigs->contains($merchantConfig)) { | |||
$this->merchantConfigs[] = $merchantConfig; | |||
$merchantConfig->setMerchant($this); | |||
if (!$this->settings->contains($merchantSetting)) { | |||
$this->settings[] = $merchantSetting; | |||
$merchantSetting->setMerchant($this); | |||
} | |||
return $this; | |||
} | |||
public function removeMerchantConfig(MerchantConfigInterface $merchantConfig): self | |||
public function removeSetting(MerchantSettingInterface $merchantSetting): self | |||
{ | |||
if ($this->merchantConfigs->contains($merchantConfig)) { | |||
$this->merchantConfigs->removeElement($merchantConfig); | |||
if ($this->settings->contains($merchantSetting)) { | |||
$this->settings->removeElement($merchantSetting); | |||
// set the owning side to null (unless already changed) | |||
if ($merchantConfig->getMerchant() === $this) { | |||
$merchantConfig->setMerchant(null); | |||
if ($merchantSetting->getMerchant() === $this) { | |||
$merchantSetting->setMerchant(null); | |||
} | |||
} | |||
return $this; | |||
} | |||
public function getMerchantConfig($name) | |||
{ | |||
if ($this->getMerchantConfigs()) { | |||
foreach ($this->getMerchantConfigs() as $merchantConfig) { | |||
if ($merchantConfig->getName() == $name) { | |||
return $merchantConfig->getValue(); | |||
} | |||
} | |||
} | |||
return false; | |||
} | |||
public function getAddress(): ?AddressInterface | |||
{ | |||
return $this->address; |
@@ -10,6 +10,8 @@ use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | |||
use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface; | |||
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface; | |||
use Lc\CaracoleBundle\Model\Setting\EntitySettingTrait; | |||
use Lc\CaracoleBundle\Model\Setting\SectionSettingInterface; | |||
use Lc\CaracoleBundle\Model\Site\PageInterface; | |||
use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity; | |||
@@ -18,6 +20,8 @@ use Lc\SovBundle\Doctrine\Pattern\AbstractFullEntity; | |||
*/ | |||
abstract class SectionModel extends AbstractFullEntity implements FilterMerchantInterface | |||
{ | |||
use EntitySettingTrait; | |||
/** | |||
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface") | |||
* @ORM\JoinColumn(nullable=false) | |||
@@ -55,7 +59,6 @@ abstract class SectionModel extends AbstractFullEntity implements FilterMerchant | |||
*/ | |||
protected $orderShops; | |||
/** | |||
* @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Product\ProductCategoryInterface", mappedBy="section") | |||
*/ | |||
@@ -66,6 +69,11 @@ abstract class SectionModel extends AbstractFullEntity implements FilterMerchant | |||
*/ | |||
protected $pages; | |||
/** | |||
* @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Setting\SectionSettingInterface", mappedBy="section", orphanRemoval=true, cascade={"persist"}, fetch="EAGER") | |||
*/ | |||
protected $settings; | |||
public function __construct() | |||
{ | |||
$this->productFamilies = new ArrayCollection(); | |||
@@ -245,4 +253,35 @@ abstract class SectionModel extends AbstractFullEntity implements FilterMerchant | |||
return $this; | |||
} | |||
/** | |||
* @return Collection|SectionSettingInterface[] | |||
*/ | |||
public function getSettings(): Collection | |||
{ | |||
return $this->settings; | |||
} | |||
public function addSetting(SectionSettingInterface $sectionSetting): self | |||
{ | |||
if (!$this->settings->contains($sectionSetting)) { | |||
$this->settings[] = $sectionSetting; | |||
$sectionSetting->setMerchant($this); | |||
} | |||
return $this; | |||
} | |||
public function removeSetting(SectionSettingInterface $sectionSetting): self | |||
{ | |||
if ($this->settings->contains($sectionSetting)) { | |||
$this->settings->removeElement($sectionSetting); | |||
// set the owning side to null (unless already changed) | |||
if ($sectionSetting->getMerchant() === $this) { | |||
$sectionSetting->setMerchant(null); | |||
} | |||
} | |||
return $this; | |||
} | |||
} |
@@ -0,0 +1,33 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Model\Setting; | |||
trait EntitySettingTrait | |||
{ | |||
public function getSetting($name) | |||
{ | |||
if ($this->getSettings()) { | |||
foreach ($this->getSettings() as $setting) { | |||
if ($setting->getName() == $name) { | |||
return $setting; | |||
} | |||
} | |||
} | |||
return false; | |||
} | |||
public function getSettingValue($name) | |||
{ | |||
if ($this->getSettings()) { | |||
foreach ($this->getSettings() as $setting) { | |||
if ($setting->getName() == $name) { | |||
return $setting->getValue(); | |||
} | |||
} | |||
} | |||
return false; | |||
} | |||
} |
@@ -0,0 +1,8 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Model\Setting; | |||
interface MerchantSettingInterface | |||
{ | |||
} |
@@ -0,0 +1,30 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Model\Setting; | |||
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; | |||
use Doctrine\ORM\Mapping as ORM; | |||
use Lc\SovBundle\Doctrine\EntityInterface; | |||
class MerchantSettingModel implements SettingInterface, EntityInterface | |||
{ | |||
use SettingTrait; | |||
/** | |||
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface", inversedBy="merchantSettings") | |||
* @ORM\JoinColumn(nullable=false) | |||
*/ | |||
protected $merchant; | |||
public function getMerchant(): ?MerchantInterface | |||
{ | |||
return $this->merchant; | |||
} | |||
public function setMerchant(?MerchantInterface $merchant): self | |||
{ | |||
$this->merchant = $merchant; | |||
return $this; | |||
} | |||
} |
@@ -0,0 +1,8 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Model\Setting; | |||
interface SectionSettingInterface | |||
{ | |||
} |
@@ -0,0 +1,30 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Model\Setting; | |||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | |||
use Doctrine\ORM\Mapping as ORM; | |||
use Lc\SovBundle\Doctrine\EntityInterface; | |||
class SectionSettingModel implements SettingInterface, EntityInterface | |||
{ | |||
use SettingTrait; | |||
/** | |||
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface", inversedBy="sectionSettings") | |||
* @ORM\JoinColumn(nullable=false) | |||
*/ | |||
protected $section; | |||
public function getSection(): ?SectionInterface | |||
{ | |||
return $this->section; | |||
} | |||
public function setSection(?SectionInterface $section): self | |||
{ | |||
$this->section = $section; | |||
return $this; | |||
} | |||
} |
@@ -0,0 +1,8 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Model\Setting; | |||
interface SettingInterface | |||
{ | |||
} |
@@ -0,0 +1,87 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Model\Setting; | |||
use Lc\SovBundle\Model\File\FileInterface; | |||
trait SettingTrait | |||
{ | |||
/** | |||
* @ORM\Column(type="string", length=63) | |||
*/ | |||
protected $name; | |||
/** | |||
* @ORM\Column(type="text", nullable=true) | |||
*/ | |||
protected $text; | |||
/** | |||
* @ORM\Column(type="datetime", nullable=true) | |||
*/ | |||
protected $date; | |||
/** | |||
* @ORM\ManyToOne(targetEntity=FileInterface::class, cascade={"persist", "remove"}) | |||
*/ | |||
protected $file; | |||
public function getValue() | |||
{ | |||
if ($this->getText()) { | |||
return $this->getText(); | |||
} elseif ($this->getDate()) { | |||
return $this->getDate(); | |||
} elseif ($this->getFile()) { | |||
return $this->getFile(); | |||
} | |||
} | |||
public function getName(): ?string | |||
{ | |||
return $this->name; | |||
} | |||
public function setName(string $name): self | |||
{ | |||
$this->name = $name; | |||
return $this; | |||
} | |||
public function getText(): ?string | |||
{ | |||
return $this->text; | |||
} | |||
public function setText($text): self | |||
{ | |||
$this->text = $text; | |||
return $this; | |||
} | |||
public function getDate(): ?\DateTimeInterface | |||
{ | |||
return $this->date; | |||
} | |||
public function setDate(\DateTimeInterface $date): self | |||
{ | |||
$this->date = $date; | |||
return $this; | |||
} | |||
public function getFile(): ?FileInterface | |||
{ | |||
return $this->file; | |||
} | |||
public function setFile(?FileInterface $file): self | |||
{ | |||
$this->file = $file; | |||
return $this; | |||
} | |||
} |
@@ -0,0 +1,21 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Repository\Setting; | |||
use Lc\CaracoleBundle\Model\Setting\MerchantSettingInterface; | |||
use Lc\CaracoleBundle\Repository\AbstractRepository; | |||
/** | |||
* @method MerchantSettingInterface|null find($id, $lockMode = null, $lockVersion = null) | |||
* @method MerchantSettingInterface|null findOneBy(array $criteria, array $orderBy = null) | |||
* @method MerchantSettingInterface[] findAll() | |||
* @method MerchantSettingInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | |||
*/ | |||
class MerchantSettingRepository extends AbstractRepository | |||
{ | |||
public function getInterfaceClass() | |||
{ | |||
return MerchantSettingInterface::class; | |||
} | |||
} |
@@ -0,0 +1,21 @@ | |||
<?php | |||
namespace Lc\CaracoleBundle\Repository\Setting; | |||
use Lc\CaracoleBundle\Model\Setting\SectionSettingInterface; | |||
use Lc\CaracoleBundle\Repository\AbstractRepository; | |||
/** | |||
* @method SectionSettingInterface|null find($id, $lockMode = null, $lockVersion = null) | |||
* @method SectionSettingInterface|null findOneBy(array $criteria, array $orderBy = null) | |||
* @method SectionSettingInterface[] findAll() | |||
* @method SectionSettingInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | |||
*/ | |||
class SectionSettingRepository extends AbstractRepository | |||
{ | |||
public function getInterfaceClass() | |||
{ | |||
return SectionSettingInterface::class; | |||
} | |||
} |
@@ -6,3 +6,10 @@ carac_switch_section: | |||
path: /switch-section | |||
controller: Lc\CaracoleBundle\Controller\Section\SwitchSectionAdminController::switchSection | |||
carac_admin_setting_merchant: | |||
path: /admin/setting/merchant | |||
controller: Lc\CaracoleBundle\Controller\Setting\SettingAdminController::manageMerchant | |||
carac_admin_setting_section: | |||
path: /admin/setting/section | |||
controller: Lc\CaracoleBundle\Controller\Setting\SettingAdminController::manageSection |
@@ -1,5 +1,8 @@ | |||
menu: | |||
setting: Paramètres | |||
setting_merchant: Marchand | |||
setting_section: Section | |||
admin: Administration | |||
admin_merchant: Marchands | |||
admin_section: Sections |
@@ -0,0 +1,62 @@ | |||
<div class="card card-outline"> | |||
<div class="card-header p-0 border-bottom-0"> | |||
<ul id="nav-params" class="nav nav-pills" role="navigation"> | |||
{% for index, category in setting_definition.getCategories() %} | |||
<li class="nav-item"> | |||
<a href="#panel-{{ category }} " class="nav-link {{ index == 0 ? 'active' }}" | |||
data-toggle="tab" role="tab" | |||
aria-controls="panel-{{ category }}"> | |||
{{ ('setting_definition.'~trans_category~'.categories.'~category)|trans({}, 'admin') }} | |||
<i class="fa fa-exclamation-circle invalid-form"></i> | |||
</a> | |||
</li> | |||
{% endfor %} | |||
</ul> | |||
</div> | |||
</div> | |||
{% form_theme form '@LcSov/adminlte/crud/form_theme.html.twig' %} | |||
{{ form_start(form) }} | |||
<div class="tab-content"> | |||
{% set childSettings = form.settings %} | |||
{% for index, category in setting_definition.getCategories() %} | |||
<div class="tab-pane {{ index == 0 ? 'active' }}" id="panel-{{ category }}"> | |||
{% embed '@LcSov/adminlte/embed/card.html.twig' %} | |||
{% block header_wrapper %}{% endblock %} | |||
{% block body %} | |||
{% set count = 0 %} | |||
{% for name, setting in setting_definition.getSettingsByCategory(category) %} | |||
{% for child in childSettings %} | |||
{% if child.children.name.vars.value == name %} | |||
{{ form_widget(child) }} | |||
{% set count = count + 1 %} | |||
{% endif %} | |||
{% endfor %} | |||
{% endfor %} | |||
{% if count == 0 %} | |||
<div class="callout callout-warning"> | |||
Aucun paramètre disponible dans cet onglet. | |||
</div> | |||
{% endif %} | |||
{% endblock %} | |||
{% block footer_wrapper %}{% endblock %} | |||
{% endembed %} | |||
</div> | |||
{% endfor %} | |||
</div> | |||
<div class="form-footer"> | |||
<div class="row"> | |||
<div class="col-sm-12"> | |||
<div class="btn-list"> | |||
<button class="btn btn-info float-right" type="submit" name="submit" value="submit" | |||
data-action-name="submit"> | |||
<span class="btn-label">Sauvegarder</span> | |||
</button> | |||
</div> | |||
</div> | |||
</div> | |||
</div> | |||
{{ form_end(form) }} |
@@ -0,0 +1,10 @@ | |||
{% extends '@LcCaracole/adminlte/layout.html.twig' %} | |||
{% block content_title %} | |||
Paramètres globaux | |||
{% endblock %} | |||
{% block main %} | |||
{% set trans_category = 'merchant' %} | |||
{% include '@LcCaracole/admin/setting/form.html.twig' %} | |||
{% endblock %} |
@@ -0,0 +1,11 @@ | |||
{% extends '@LcCaracole/adminlte/layout.html.twig' %} | |||
{% block content_title %} | |||
{% set current_section = resolver.getCurrent() %} | |||
Paramètres de section > {{ current_section.title }} | |||
{% endblock %} | |||
{% block main %} | |||
{% set trans_category = 'section' %} | |||
{% include '@LcCaracole/admin/setting/form.html.twig' %} | |||
{% endblock %} |