Преглед на файлове

SiteSettings : paramètres globaux

feature/ticket^2
Guillaume преди 3 години
родител
ревизия
a21fb3a628
променени са 11 файла, в които са добавени 67 реда и са изтрити 281 реда
  1. +41
    -9
      Controller/Setting/SettingAdminController.php
  2. +0
    -129
      Definition/AbstractSettingDefinition.php
  3. +1
    -0
      Definition/MerchantSettingDefinition.php
  4. +1
    -0
      EventSubscriber/SettingEventSubscriber.php
  5. +1
    -1
      EventSubscriber/User/UserRolesEventSubscriber.php
  6. +5
    -89
      Form/Setting/BaseSettingType.php
  7. +4
    -0
      Resources/config/routes.yaml
  8. +0
    -49
      Resources/views/admin/setting/form.html.twig
  9. +10
    -0
      Resources/views/admin/setting/global.html.twig
  10. +2
    -2
      Resources/views/admin/setting/merchant.html.twig
  11. +2
    -2
      Resources/views/admin/setting/section.html.twig

+ 41
- 9
Controller/Setting/SettingAdminController.php Целия файл

@@ -9,6 +9,9 @@ use Lc\CaracoleBundle\Form\Setting\SectionSettingsFormType;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\CaracoleBundle\Definition\SectionSettingDefinitionInterface;
use Lc\SovBundle\Definition\SiteSettingDefinition;
use Lc\SovBundle\Form\Setting\SiteSettingsFormType;
use Lc\SovBundle\Repository\Site\SiteRepository;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
@@ -16,26 +19,32 @@ use Symfony\Component\HttpFoundation\Request;
class SettingAdminController extends AbstractController
{
protected $em;
protected $translatorAdmin;
protected $merchantResolver;
protected $merchantSettingDefinition;
protected $sectionResolver;
protected $sectionSettingDefinition;
protected $translatorAdmin;
protected $siteSettingDefinition;
protected $siteRepository;

public function __construct(
EntityManagerInterface $em,
TranslatorAdmin $translatorAdmin,
MerchantResolver $merchantResolver,
SectionResolver $sectionResolver,
MerchantSettingDefinitionInterface $merchantSettingDefinition,
SectionSettingDefinitionInterface $sectionSettingDefinition,
TranslatorAdmin $translatorAdmin
SiteSettingDefinition $siteSettingDefinition,
SiteRepository $siteRepository
) {
$this->em = $em;
$this->translatorAdmin = $translatorAdmin;
$this->merchantResolver = $merchantResolver;
$this->sectionResolver = $sectionResolver;
$this->merchantSettingDefinition = $merchantSettingDefinition;
$this->sectionSettingDefinition = $sectionSettingDefinition;
$this->translatorAdmin = $translatorAdmin ;
$this->siteSettingDefinition = $siteSettingDefinition;
$this->siteRepository = $siteRepository;
}

public function manageMerchant(Request $request)
@@ -50,22 +59,21 @@ class SettingAdminController extends AbstractController

public function manage(Request $request, $type)
{
$entity = null ;
$entity = null;

if ($type == 'merchant') {
$resolver = $this->merchantResolver ;
$resolver = $this->merchantResolver;
$formClass = MerchantSettingsFormType::class;
$settingDefinition = $this->merchantSettingDefinition ;
$settingDefinition = $this->merchantSettingDefinition;
} elseif ($type == 'section') {
$resolver = $this->sectionResolver ;
$resolver = $this->sectionResolver;
$formClass = SectionSettingsFormType::class;
$settingDefinition = $this->sectionSettingDefinition ;
$settingDefinition = $this->sectionSettingDefinition;
}

$entity = $resolver->getCurrent();

if ($entity) {

$form = $this->createForm($formClass, $entity);

$form->handleRequest($request);
@@ -88,4 +96,28 @@ class SettingAdminController extends AbstractController
}
}

public function manageGlobal(Request $request)
{
$site = $this->siteRepository->findOneByDevAlias('default') ;
$form = $this->createForm(SiteSettingsFormType::class, $site);

$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {

$this->em->update($site);
$this->em->flush();

$this->addFlash('success', $this->translatorAdmin->transFlashMessage('settings_saved'));
}

return $this->render(
'@LcCaracole/admin/setting/global.html.twig' ,
[
'setting_definition' => $this->siteSettingDefinition,
'form' => $form->createView()
]
);
}

}

+ 0
- 129
Definition/AbstractSettingDefinition.php Целия файл

@@ -1,129 +0,0 @@
<?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;
}
}

+ 1
- 0
Definition/MerchantSettingDefinition.php Целия файл

@@ -2,6 +2,7 @@

namespace Lc\CaracoleBundle\Definition;

use Lc\SovBundle\Definition\AbstractSettingDefinition;

class MerchantSettingDefinition extends AbstractSettingDefinition implements MerchantSettingDefinitionInterface
{

+ 1
- 0
EventSubscriber/SettingEventSubscriber.php Целия файл

@@ -66,6 +66,7 @@ class SettingEventSubscriber implements EventSubscriberInterface
$this->sectionRepository->findAll(),
$this->sectionSettingFactory
);

}

public function initSettingsGeneric($type, $settings, $entities, $factory)

+ 1
- 1
EventSubscriber/User/UserRolesEventSubscriber.php Целия файл

@@ -46,7 +46,7 @@ class UserRolesEventSubscriber implements EventSubscriberInterface

public function setUserRolesFromKernelRequest(RequestEvent $event)
{
if (!$event->isMainRequest()) {
if (!$event->isMasterRequest()) {
return;
}
if ($this->setUserRoles($event->getRequest())) {

+ 5
- 89
Form/Setting/BaseSettingType.php Целия файл

@@ -20,8 +20,9 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Lc\SovBundle\Form\Setting\BaseSettingType as SovBaseSettingType;

abstract class BaseSettingType extends AbstractType
abstract class BaseSettingType extends SovBaseSettingType
{
protected $em;
protected $merchantSettingDefinition;
@@ -63,96 +64,11 @@ abstract class BaseSettingType extends AbstractType
$transCategory = 'section' ;
$settingDefinition = $sectionSettingDefinition ;
}
$label = 'setting_definition.'.$transCategory.'.settings.'.$settingName ;

if($settingDefinition) {
$setting = $settingDefinition->getSettingByName($settingName);
$settingType = $settingDefinition->getSettingType($settingName);
$label = 'setting_definition.'.$transCategory.'.settings.'.$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
]
]
);
}
if(isset($settingDefinition) && $settingDefinition) {
$this->buildFormSetting($label, $form, $settingDefinition, $settingEntity);
}
}
}

+ 4
- 0
Resources/config/routes.yaml Целия файл

@@ -17,3 +17,7 @@ carac_admin_setting_merchant:
carac_admin_setting_section:
path: /admin/setting/section
controller: Lc\CaracoleBundle\Controller\Setting\SettingAdminController::manageSection

carac_admin_setting_global:
path: /admin/setting/global2
controller: Lc\CaracoleBundle\Controller\Setting\SettingAdminController::manageGlobal

+ 0
- 49
Resources/views/admin/setting/form.html.twig Целия файл

@@ -1,49 +0,0 @@

{% embed '@LcSov/adminlte/embed/tabs/tabs.html.twig' %}
{# items menu #}
{% import '@LcSov/adminlte/macro/tabs.html.twig' as mtabs %}
{% block menu_items %}
{% for index, category in setting_definition.getCategories() %}
{{ mtabs.menu_item(category, loop.first, ('setting_definition.'~trans_category~'.categories.'~category)|trans({}, 'admin')) }}
{% endfor %}
{% endblock %}

{# content #}
{% block content %}
{% form_theme form '@LcSov/adminlte/crud/form_theme.html.twig' %}
{{ form_start(form) }}

{# panes #}
{% for index, category in setting_definition.getCategories() %}
{% embed '@LcSov/adminlte/embed/tabs/pane.html.twig' %}
{% block class %}{{ index == 0 ? 'active' }}{% endblock %}
{% block id %}{{ category }}{% endblock %}
{% block content %}
{% set count = 0 %}
{% for name, setting in setting_definition.getSettingsByCategory(category) %}
{% for child in form.settings %}
{% if child.children.name.vars.value == name %}
{{ form_widget(child) }}
{% set count = count + 1 %}
{% endif %}
{% endfor %}
{% endfor %}
{% if count == 0 %}
{% import '@LcSov/adminlte/macro/callout.html.twig' as mcallout %}
{{ mcallout.callout_warning('Aucun paramètre disponible dans cet onglet.') }}
{% endif %}
{% endblock %}
{% endembed %}
{% endfor %}

{# form footer #}
{% embed '@LcSov/adminlte/embed/form_footer.html.twig' %}
{% block width %}12{% endblock %}
{% block content %}
{{ form_widget(form.submit) }}
{% endblock %}
{% endembed %}

{{ form_end(form) }}
{% endblock %}
{% endembed %}

+ 10
- 0
Resources/views/admin/setting/global.html.twig Целия файл

@@ -0,0 +1,10 @@
{% extends '@LcCaracole/adminlte/layout.html.twig' %}

{% block content_title %}
Paramètres globaux
{% endblock %}

{% block main %}
{% set trans_category = 'global' %}
{% include '@LcSov/admin/setting/form.html.twig' %}
{% endblock %}

+ 2
- 2
Resources/views/admin/setting/merchant.html.twig Целия файл

@@ -1,10 +1,10 @@
{% extends '@LcCaracole/adminlte/layout.html.twig' %}

{% block content_title %}
Paramètres globaux
Paramètres marchand
{% endblock %}

{% block main %}
{% set trans_category = 'merchant' %}
{% include '@LcCaracole/admin/setting/form.html.twig' %}
{% include '@LcSov/admin/setting/form.html.twig' %}
{% endblock %}

+ 2
- 2
Resources/views/admin/setting/section.html.twig Целия файл

@@ -2,10 +2,10 @@

{% block content_title %}
{% set current_section = resolver.getCurrent() %}
Paramètres de section &gt; {{ current_section.title }}
Paramètres section &gt; {{ current_section.title }}
{% endblock %}

{% block main %}
{% set trans_category = 'section' %}
{% include '@LcCaracole/admin/setting/form.html.twig' %}
{% include '@LcSov/admin/setting/form.html.twig' %}
{% endblock %}

Loading…
Отказ
Запис