Parcourir la source

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

develop
Fabien Normand il y a 3 ans
Parent
révision
2bd4060497
6 fichiers modifiés avec 132 ajouts et 115 suppressions
  1. +88
    -0
      Builder/Setting/SettingBuilder.php
  2. +34
    -0
      Command/SiteSettingInitCommand.php
  3. +0
    -108
      EventSubscriber/SiteSettingEventSubscriber.php
  4. +4
    -1
      Form/Setting/BaseSettingType.php
  5. +0
    -5
      Resources/views/adminlte/crud/form.html.twig
  6. +6
    -1
      Resources/views/adminlte/layout.html.twig

+ 88
- 0
Builder/Setting/SettingBuilder.php Voir le fichier

@@ -0,0 +1,88 @@
<?php

namespace Lc\SovBundle\Builder\Setting;

use Doctrine\ORM\EntityManagerInterface;
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\HttpKernel\Exception\NotFoundHttpException;

class SettingBuilder
{
protected EntityManagerInterface $entityManager;
protected SettingSolver $settingSolver;
protected SiteStore $siteStore;
protected SiteSettingDefinition $siteSettingDefinition;
protected SiteSettingFactory $siteSettingFactory;

public function __construct(
EntityManagerInterface $entityManager,
SettingSolver $settingSolver,
SiteStore $siteStore,
SiteSettingDefinition $siteSettingDefinition,
SiteSettingFactory $siteSettingFactory
) {
$this->entityManager = $entityManager;
$this->settingSolver = $settingSolver;
$this->siteStore = $siteStore;
$this->siteSettingDefinition = $siteSettingDefinition;
$this->siteSettingFactory = $siteSettingFactory;
}

public function initSiteSettings()
{
$site = $this->siteStore->getOneByDevAlias('default');

if ($site) {
$settings = $this->siteSettingDefinition->getSettings();

foreach ($settings as $category => $settingList) {
foreach ($settingList as $settingName => $setting) {
$entitySetting = $this->settingSolver->getSetting($site, $settingName);

if (!$entitySetting) {
$text = null;
$date = null;
$file = null;

$fieldValue = isset($setting['default']) ? $setting['default'] : null;

if ($setting['field'] == 'text') {
$text = $fieldValue;
}
if ($setting['field'] == 'date') {
$date = $fieldValue;
}
if ($setting['field'] == 'file') {
$file = $fieldValue;
}

$entitySetting = $this->siteSettingFactory->create(
$site,
$setting['name'],
$text,
$date,
$file
);
$this->entityManager->create($entitySetting);
} else {
$methodGetValue = 'get' . ucfirst($setting['field']);
if ($entitySetting->$methodGetValue() === null
&& isset($setting['default'])
&& $setting['default'] !== null) {
$methodSetValue = 'set' . ucfirst($setting['field']);
$entitySetting->$methodSetValue($setting['default']);
$this->entityManager->update($entitySetting);
}
}
}
}

$this->entityManager->flush();
} else {
throw new NotFoundHttpException('Le site par défaut n\'existe pas.');
}
}
}

+ 34
- 0
Command/SiteSettingInitCommand.php Voir le fichier

@@ -0,0 +1,34 @@
<?php

namespace Lc\SovBundle\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 SiteSettingInitCommand extends Command
{
protected static $defaultName = 'setting:site:init';
protected static $defaultDescription = 'Initialise les SiteSetting.';

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->initSiteSettings();
$this->io->success('Les SiteSetting ont bien été initialisées.');
return Command::SUCCESS;
}
}

+ 0
- 108
EventSubscriber/SiteSettingEventSubscriber.php Voir le fichier

@@ -1,108 +0,0 @@
<?php

namespace Lc\SovBundle\EventSubscriber;

use Doctrine\ORM\EntityManagerInterface;
use Lc\SovBundle\Definition\SiteSettingDefinitionInterface;
use Lc\SovBundle\Factory\Setting\SiteSettingFactory;
use Lc\SovBundle\Factory\Site\SiteFactory;
use Lc\SovBundle\Repository\Setting\SiteSettingRepository;
use Lc\SovBundle\Repository\Site\SiteRepository;
use Lc\SovBundle\Repository\Site\SiteStore;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;

class SiteSettingEventSubscriber implements EventSubscriberInterface
{
protected EntityManagerInterface $entityManager;
protected SiteSettingDefinitionInterface $siteSettingDefinition;
protected SiteSettingFactory $siteSettingFactory;
protected SiteSettingRepository $siteSettingRepository;
protected SiteStore $siteStore;
protected SiteFactory $siteFactory;
protected SettingSolver $settingSolver;

public function __construct(
EntityManagerInterface $entityManager,
SiteSettingRepository $siteSettingRepository,
SiteStore $siteStore,
SiteSettingDefinitionInterface $siteSettingDefinition,
SiteSettingFactory $siteSettingFactory,
SiteFactory $siteFactory,
SettingSolver $settingSolver
) {
$this->entityManager = $entityManager;
$this->siteSettingDefinition = $siteSettingDefinition;
$this->siteSettingFactory = $siteSettingFactory;
$this->siteSettingRepository = $siteSettingRepository;
$this->siteStore = $siteStore;
$this->siteFactory = $siteFactory;
$this->settingSolver = $settingSolver;
}

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

public function initSettings()
{
$site = $this->getSiteDefault();
if (!$site) {
$site = $this->siteFactory->create('default');
$this->entityManager->persist($site);
$this->entityManager->flush($site);
}

$settings = $this->siteSettingDefinition->getSettings();
$factory = $this->siteSettingFactory;

foreach ($settings as $category => $settingList) {
foreach ($settingList as $settingName => $setting) {
$entitySetting = $this->settingSolver->getSetting($site, $settingName);

if (!$entitySetting) {

$text = null;
$date = null;
$file = null;

$fieldValue = isset($setting['default']) ? $setting['default'] : null;

if($setting['field'] == 'text') {
$text = $fieldValue;
}
if($setting['field'] == 'date') {
$date = $fieldValue;
}
if($setting['field'] == 'file') {
$file = $fieldValue;
}

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

$this->entityManager->persist($entitySetting);
} else {
$methodGetValue = 'get' . ucfirst($setting['field']);
if ($entitySetting->$methodGetValue() === null
&& isset($setting['default'])
&& $setting['default'] !== null) {
$methodSetValue = 'set' . ucfirst($setting['field']);
$entitySetting->$methodSetValue($setting['default']);
$this->entityManager->update($entitySetting);
}
}
}
}

$this->entityManager->flush();
}

public function getSiteDefault()
{
return $this->siteStore->getOneByDevAlias('default');
}
}

+ 4
- 1
Form/Setting/BaseSettingType.php Voir le fichier

@@ -53,7 +53,10 @@ abstract class BaseSettingType extends AbstractType
'text',
CKEditorType::class,
[
'label' => $label
'label' => $label,
'attr' => [
'class' => 'field-text_editor'
]
]
);
} elseif ($settingType == 'select') {

+ 0
- 5
Resources/views/adminlte/crud/form.html.twig Voir le fichier

@@ -60,11 +60,6 @@
<script src="{{ asset(js_asset) }}"></script>
{% endfor %}

<script type="text/javascript">
var CKEDITOR_BASEPATH = "{{ ckeditor_base_path("/bundles/fosckeditor/") }}";
</script>
<script type="text/javascript" src="{{ asset('bundles/fosckeditor/ckeditor.js') }}"></script>

{% for webpack_encore_entry in form.vars.ea_crud_form.assets.webpackEncoreAssets %}
{{ ea_call_function_if_exists('encore_entry_script_tags', webpack_encore_entry) }}
{% endfor %}

+ 6
- 1
Resources/views/adminlte/layout.html.twig Voir le fichier

@@ -27,7 +27,6 @@
<link rel="stylesheet" href="{{ asset(css_asset) }}">
{% endfor %}


{% for webpack_encore_entry in ea.assets.webpackEncoreAssets ?? [] %}
{{ ea_call_function_if_exists('encore_entry_link_tags', webpack_encore_entry) }}
{% endfor %}
@@ -47,6 +46,12 @@
<link rel="stylesheet" href="{{ asset('bundles/easyadmin/app-custom-rtl.css') }}">
{% endif %} #}

{# CKEditor #}
<script type="text/javascript">
var CKEDITOR_BASEPATH = "{{ ckeditor_base_path("/bundles/fosckeditor/") }}";
</script>
<script type="text/javascript" src="{{ asset('bundles/fosckeditor/ckeditor.js') }}"></script>

{% block configured_head_contents %}
{% for htmlContent in ea.assets.headContents ?? [] %}
{{ htmlContent|raw }}

Chargement…
Annuler
Enregistrer