|
|
@@ -1,72 +1,66 @@ |
|
|
|
<?php |
|
|
|
|
|
|
|
namespace Lc\CaracoleBundle\EventSubscriber; |
|
|
|
namespace Lc\CaracoleBundle\Builder\Setting; |
|
|
|
|
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface; |
|
|
|
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition; |
|
|
|
use Lc\CaracoleBundle\Definition\SectionSettingDefinition; |
|
|
|
use Lc\CaracoleBundle\Factory\Setting\MerchantSettingFactory; |
|
|
|
use Lc\CaracoleBundle\Factory\Setting\SectionSettingFactory; |
|
|
|
use Lc\CaracoleBundle\Model\Section\SectionInterface; |
|
|
|
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 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 SectionStore $sectionStore; |
|
|
|
protected MerchantSettingDefinition $merchantSettingDefinition; |
|
|
|
protected MerchantSettingFactory $merchantSettingFactory; |
|
|
|
protected SectionSettingDefinition $sectionSettingDefinition; |
|
|
|
protected SectionSettingFactory $sectionSettingFactory; |
|
|
|
protected SettingSolver $settingSolver; |
|
|
|
|
|
|
|
public function __construct( |
|
|
|
EntityManagerInterface $entityManager, |
|
|
|
MerchantSettingDefinitionInterface $merchantSettingDefinition, |
|
|
|
SectionSettingDefinition $sectionSettingDefinition, |
|
|
|
SettingSolver $settingSolver, |
|
|
|
SiteStore $siteStore, |
|
|
|
SiteSettingDefinition $siteSettingDefinition, |
|
|
|
SiteSettingFactory $siteSettingFactory, |
|
|
|
MerchantStore $merchantStore, |
|
|
|
SectionStore $sectionStore, |
|
|
|
MerchantSettingDefinition $merchantSettingDefinition, |
|
|
|
MerchantSettingFactory $merchantSettingFactory, |
|
|
|
SectionSettingFactory $sectionSettingFactory, |
|
|
|
SettingSolver $settingSolver |
|
|
|
SectionSettingDefinition $sectionSettingDefinition, |
|
|
|
SectionSettingFactory $sectionSettingFactory |
|
|
|
) { |
|
|
|
$this->entityManager = $entityManager; |
|
|
|
parent::__construct($entityManager, $settingSolver, $siteStore, $siteSettingDefinition, $siteSettingFactory); |
|
|
|
|
|
|
|
$this->merchantStore = $merchantStore; |
|
|
|
$this->sectionStore = $sectionStore; |
|
|
|
$this->merchantSettingDefinition = $merchantSettingDefinition; |
|
|
|
$this->sectionSettingDefinition = $sectionSettingDefinition; |
|
|
|
$this->merchantSettingFactory = $merchantSettingFactory; |
|
|
|
$this->sectionSettingDefinition = $sectionSettingDefinition; |
|
|
|
$this->sectionSettingFactory = $sectionSettingFactory; |
|
|
|
$this->settingSolver = $settingSolver; |
|
|
|
} |
|
|
|
|
|
|
|
public static function getSubscribedEvents() |
|
|
|
{ |
|
|
|
return [ |
|
|
|
KernelEvents::CONTROLLER => ['initSettings'] |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
public function initSettings() |
|
|
|
public function initMerchantSettings() |
|
|
|
{ |
|
|
|
$merchants = $this->merchantStore->get(); |
|
|
|
|
|
|
|
$this->initSettingsGeneric( |
|
|
|
'merchant', |
|
|
|
$this->merchantSettingDefinition->getSettings(), |
|
|
|
//TODO vérifier que ce soit bien les online que l'on souhaite |
|
|
|
$merchants, |
|
|
|
$this->merchantSettingFactory |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
public function initSectionSettings() |
|
|
|
{ |
|
|
|
$merchants = $this->merchantStore->get(); |
|
|
|
|
|
|
|
foreach($merchants as $merchant) { |
|
|
|
$this->initSettingsGeneric( |
|
|
|
'section', |
|
|
|
$this->sectionSettingDefinition->getSettings(), |
|
|
|
$merchant->getSections(), |
|
|
|
$this->sectionSettingFactory |
|
|
@@ -74,16 +68,20 @@ class SettingEventSubscriber implements EventSubscriberInterface |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function initSettingsGeneric($type, $settings, $entities, $factory) |
|
|
|
protected function initSettingsGeneric($settings, $entities, $factory) |
|
|
|
{ |
|
|
|
if($entities) { |
|
|
|
foreach ($entities as $entity) { |
|
|
|
|
|
|
|
$this->entityManager->refresh($entity); |
|
|
|
|
|
|
|
foreach ($settings as $category => $settingList) { |
|
|
|
foreach ($settingList as $settingName => $setting) { |
|
|
|
|
|
|
|
$entitySetting = $this->settingSolver->getSetting($entity, $settingName); |
|
|
|
|
|
|
|
if (!$entitySetting) { |
|
|
|
|
|
|
|
// gestion du cas des SectionSetting spécifiques à une section |
|
|
|
$createEntitySetting = true; |
|
|
|
if ($entity instanceof SectionInterface && isset($setting['section']) && $setting['section'] != $entity) { |
|
|
@@ -107,7 +105,7 @@ class SettingEventSubscriber implements EventSubscriberInterface |
|
|
|
|
|
|
|
$entitySetting = $factory->create($entity, $setting['name'], $text, $date, $file); |
|
|
|
|
|
|
|
$this->entityManager->persist($entitySetting); |
|
|
|
$this->entityManager->create($entitySetting); |
|
|
|
} |
|
|
|
} else { |
|
|
|
if ($this->settingSolver->getValue($entitySetting) === null |