Browse Source

Merge branch 'develop' of https://forge.laclic.fr/Laclic/CaracoleBundle into develop

packProduct
Fabien Normand 3 years ago
parent
commit
6c4a691ebd
4 changed files with 101 additions and 36 deletions
  1. +31
    -33
      Builder/Setting/SettingBuilder.php
  2. +34
    -0
      Command/MerchantSettingInitCommand.php
  3. +34
    -0
      Command/SectionSettingInitCommand.php
  4. +2
    -3
      Controller/Merchant/SwitchMerchantController.php

EventSubscriber/SettingEventSubscriber.php → Builder/Setting/SettingBuilder.php View File

<?php <?php


namespace Lc\CaracoleBundle\EventSubscriber;
namespace Lc\CaracoleBundle\Builder\Setting;


use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Definition\SectionSettingDefinition; use Lc\CaracoleBundle\Definition\SectionSettingDefinition;
use Lc\CaracoleBundle\Factory\Setting\MerchantSettingFactory; use Lc\CaracoleBundle\Factory\Setting\MerchantSettingFactory;
use Lc\CaracoleBundle\Factory\Setting\SectionSettingFactory; use Lc\CaracoleBundle\Factory\Setting\SectionSettingFactory;
use Lc\CaracoleBundle\Model\Section\SectionInterface; use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Repository\Merchant\MerchantStore; use Lc\CaracoleBundle\Repository\Merchant\MerchantStore;
use Lc\CaracoleBundle\Repository\Section\SectionStore;
use Lc\SovBundle\Definition\SiteSettingDefinition;
use Lc\SovBundle\Factory\Setting\SiteSettingFactory;
use Lc\SovBundle\Repository\Site\SiteStore;
use Lc\SovBundle\Solver\Setting\SettingSolver; use Lc\SovBundle\Solver\Setting\SettingSolver;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Lc\SovBundle\Builder\Setting\SettingBuilder as SovSettingBuilder;


class SettingEventSubscriber implements EventSubscriberInterface
class SettingBuilder extends SovSettingBuilder
{ {
protected EntityManagerInterface $entityManager;
protected MerchantSettingDefinitionInterface $merchantSettingDefinition;
protected SectionSettingDefinition $sectionSettingDefinition;
protected MerchantStore $merchantStore; protected MerchantStore $merchantStore;
protected SectionStore $sectionStore;
protected MerchantSettingDefinition $merchantSettingDefinition;
protected MerchantSettingFactory $merchantSettingFactory; protected MerchantSettingFactory $merchantSettingFactory;
protected SectionSettingDefinition $sectionSettingDefinition;
protected SectionSettingFactory $sectionSettingFactory; protected SectionSettingFactory $sectionSettingFactory;
protected SettingSolver $settingSolver;


public function __construct( public function __construct(
EntityManagerInterface $entityManager, EntityManagerInterface $entityManager,
MerchantSettingDefinitionInterface $merchantSettingDefinition,
SectionSettingDefinition $sectionSettingDefinition,
SettingSolver $settingSolver,
SiteStore $siteStore,
SiteSettingDefinition $siteSettingDefinition,
SiteSettingFactory $siteSettingFactory,
MerchantStore $merchantStore, MerchantStore $merchantStore,
SectionStore $sectionStore,
MerchantSettingDefinition $merchantSettingDefinition,
MerchantSettingFactory $merchantSettingFactory, MerchantSettingFactory $merchantSettingFactory,
SectionSettingFactory $sectionSettingFactory,
SettingSolver $settingSolver
SectionSettingDefinition $sectionSettingDefinition,
SectionSettingFactory $sectionSettingFactory
) { ) {
$this->entityManager = $entityManager;
parent::__construct($entityManager, $settingSolver, $siteStore, $siteSettingDefinition, $siteSettingFactory);

$this->merchantStore = $merchantStore; $this->merchantStore = $merchantStore;
$this->sectionStore = $sectionStore;
$this->merchantSettingDefinition = $merchantSettingDefinition; $this->merchantSettingDefinition = $merchantSettingDefinition;
$this->sectionSettingDefinition = $sectionSettingDefinition;
$this->merchantSettingFactory = $merchantSettingFactory; $this->merchantSettingFactory = $merchantSettingFactory;
$this->sectionSettingDefinition = $sectionSettingDefinition;
$this->sectionSettingFactory = $sectionSettingFactory; $this->sectionSettingFactory = $sectionSettingFactory;
$this->settingSolver = $settingSolver;
} }


public static function getSubscribedEvents()
{
return [
KernelEvents::CONTROLLER => ['initSettings']
];
}

public function initSettings()
public function initMerchantSettings()
{ {
$merchants = $this->merchantStore->get(); $merchants = $this->merchantStore->get();


$this->initSettingsGeneric( $this->initSettingsGeneric(
'merchant',
$this->merchantSettingDefinition->getSettings(), $this->merchantSettingDefinition->getSettings(),
//TODO vérifier que ce soit bien les online que l'on souhaite
$merchants, $merchants,
$this->merchantSettingFactory $this->merchantSettingFactory
); );
}

public function initSectionSettings()
{
$merchants = $this->merchantStore->get();


foreach($merchants as $merchant) { foreach($merchants as $merchant) {
$this->initSettingsGeneric( $this->initSettingsGeneric(
'section',
$this->sectionSettingDefinition->getSettings(), $this->sectionSettingDefinition->getSettings(),
$merchant->getSections(), $merchant->getSections(),
$this->sectionSettingFactory $this->sectionSettingFactory
} }
} }


public function initSettingsGeneric($type, $settings, $entities, $factory)
protected function initSettingsGeneric($settings, $entities, $factory)
{ {
if($entities) { if($entities) {
foreach ($entities as $entity) { foreach ($entities as $entity) {


$this->entityManager->refresh($entity);

foreach ($settings as $category => $settingList) { foreach ($settings as $category => $settingList) {
foreach ($settingList as $settingName => $setting) { foreach ($settingList as $settingName => $setting) {

$entitySetting = $this->settingSolver->getSetting($entity, $settingName); $entitySetting = $this->settingSolver->getSetting($entity, $settingName);


if (!$entitySetting) { if (!$entitySetting) {

// gestion du cas des SectionSetting spécifiques à une section // gestion du cas des SectionSetting spécifiques à une section
$createEntitySetting = true; $createEntitySetting = true;
if ($entity instanceof SectionInterface && isset($setting['section']) && $setting['section'] != $entity) { if ($entity instanceof SectionInterface && isset($setting['section']) && $setting['section'] != $entity) {


$entitySetting = $factory->create($entity, $setting['name'], $text, $date, $file); $entitySetting = $factory->create($entity, $setting['name'], $text, $date, $file);


$this->entityManager->persist($entitySetting);
$this->entityManager->create($entitySetting);
} }
} else { } else {
if ($this->settingSolver->getValue($entitySetting) === null if ($this->settingSolver->getValue($entitySetting) === null

+ 34
- 0
Command/MerchantSettingInitCommand.php View File

<?php

namespace Lc\CaracoleBundle\Command;

use Lc\SovBundle\Builder\Setting\SettingBuilder;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class MerchantSettingInitCommand extends Command
{
protected static $defaultName = 'setting:merchant:init';
protected static $defaultDescription = 'Initialise les MerchantSetting.';

protected SettingBuilder $settingBuilder;

public function __construct(string $name = null, SettingBuilder $settingBuilder)
{
parent::__construct($name);
$this->settingBuilder = $settingBuilder;
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->io = new SymfonyStyle($input, $output);
$this->settingBuilder->initMerchantSettings();
$this->io->success('Les MerchantSetting ont bien été initialisées.');
return Command::SUCCESS;
}
}

+ 34
- 0
Command/SectionSettingInitCommand.php View File

<?php

namespace Lc\CaracoleBundle\Command;

use Lc\SovBundle\Builder\Setting\SettingBuilder;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class SectionSettingInitCommand extends Command
{
protected static $defaultName = 'setting:section:init';
protected static $defaultDescription = 'Initialise les SectionSetting.';

protected SettingBuilder $settingBuilder;

public function __construct(string $name = null, SettingBuilder $settingBuilder)
{
parent::__construct($name);
$this->settingBuilder = $settingBuilder;
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$this->io = new SymfonyStyle($input, $output);
$this->settingBuilder->initSectionSettings();
$this->io->success('Les SectionSetting ont bien été initialisées.');
return Command::SUCCESS;
}
}

+ 2
- 3
Controller/Merchant/SwitchMerchantController.php View File

namespace Lc\CaracoleBundle\Controller\Merchant; namespace Lc\CaracoleBundle\Controller\Merchant;


use Lc\CaracoleBundle\Container\Merchant\MerchantContainer; use Lc\CaracoleBundle\Container\Merchant\MerchantContainer;
use Lc\CaracoleBundle\Controller\AbstractController;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition; use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType; use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Annotation\Route;


$context = $form->get('context')->getData(); $context = $form->get('context')->getData();


if ($merchant) { if ($merchant) {
$url = $this->get(MerchantContainer::class)->getSettingSolver()->getSettingValue(
$url = $this->getSettingValue(
$merchant, $merchant,
MerchantSettingDefinition::SETTING_URL MerchantSettingDefinition::SETTING_URL
); );

Loading…
Cancel
Save