Browse Source

Refactoring frontend

develop
Guillaume 3 years ago
parent
commit
e5c52a8e8a
4 changed files with 32 additions and 22 deletions
  1. +8
    -1
      Controller/AbstractController.php
  2. +5
    -18
      Controller/Setting/SettingAdminController.php
  3. +2
    -2
      Solver/Setting/SettingSolver.php
  4. +17
    -1
      Twig/TwigExtension.php

+ 8
- 1
Controller/AbstractController.php View File

use Lc\SovBundle\Container\User\GroupUserContainer; use Lc\SovBundle\Container\User\GroupUserContainer;
use Lc\SovBundle\Container\User\UserContainer; use Lc\SovBundle\Container\User\UserContainer;
use Lc\SovBundle\Solver\Setting\SettingSolver; use Lc\SovBundle\Solver\Setting\SettingSolver;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as SfAbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as SfAbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface;
PaginatorInterface::class => PaginatorInterface::class, PaginatorInterface::class => PaginatorInterface::class,
RequestStack::class => RequestStack::class, RequestStack::class => RequestStack::class,
EventDispatcherInterface::class => EventDispatcherInterface::class, EventDispatcherInterface::class => EventDispatcherInterface::class,
TranslatorInterface::class => TranslatorInterface::class,
LoggerInterface::class => LoggerInterface::class, LoggerInterface::class => LoggerInterface::class,
TranslatorInterface::class => TranslatorInterface::class,
TranslatorAdmin::class => TranslatorAdmin::class,
SettingSolver::class => SettingSolver::class, SettingSolver::class => SettingSolver::class,
ComponentContainer::class => ComponentContainer::class, ComponentContainer::class => ComponentContainer::class,
FileContainer::class => FileContainer::class, FileContainer::class => FileContainer::class,
return $this->get(TranslatorInterface::class); return $this->get(TranslatorInterface::class);
} }


public function getTranslatorAdmin(): TranslatorAdmin
{
return $this->get(TranslatorAdmin::class);
}

public function getLogger(): LoggerInterface public function getLogger(): LoggerInterface
{ {
return $this->get(LoggerInterface::class); return $this->get(LoggerInterface::class);

+ 5
- 18
Controller/Setting/SettingAdminController.php View File



namespace Lc\SovBundle\Controller\Setting; namespace Lc\SovBundle\Controller\Setting;


use Doctrine\ORM\EntityManagerInterface;
use Lc\SovBundle\Container\Setting\SiteSettingContainer; use Lc\SovBundle\Container\Setting\SiteSettingContainer;
use Lc\SovBundle\Container\Site\SiteContainer;
use Lc\SovBundle\Definition\SiteSettingDefinitionInterface;
use Lc\SovBundle\Controller\AbstractController;
use Lc\SovBundle\Form\Setting\SiteSettingsFormType; use Lc\SovBundle\Form\Setting\SiteSettingsFormType;
use Lc\SovBundle\Repository\Setting\SiteSettingRepository;
use Lc\SovBundle\Repository\Site\SiteRepository;
use Lc\SovBundle\Translation\TranslatorAdmin;
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;


class SettingAdminController extends AbstractController class SettingAdminController extends AbstractController
{ {
protected EntityManagerInterface $entityManager;

public function __construct(EntityManagerInterface $entityManager)
{
$this->entityManager = $entityManager;
}

/** /**
* @Route("/admin/setting/site", name="sov_admin_setting_site") * @Route("/admin/setting/site", name="sov_admin_setting_site")
*/ */
public function manageGlobal(Request $request, EntityManagerInterface $entityManager)
public function manageGlobal(Request $request)
{ {
$site = $this->get(SiteContainer::class)->getStore()->getOneByDevAlias('default') ;
$entityManager = $this->getEntityManager();
$site = $this->getSiteContainer()->getStore()->getOneByDevAlias('default') ;
$form = $this->createForm(SiteSettingsFormType::class, $site); $form = $this->createForm(SiteSettingsFormType::class, $site);


$form->handleRequest($request); $form->handleRequest($request);
$entityManager->update($site); $entityManager->update($site);
$entityManager->flush(); $entityManager->flush();


$this->addFlash('success', $this->get(TranslatorAdmin::class)->transFlashMessage('settings_saved'));
$this->addFlash('success', $this->getTranslatorAdmin()->transFlashMessage('settings_saved'));
} }


return $this->render( return $this->render(

+ 2
- 2
Solver/Setting/SettingSolver.php View File

return null; return null;
} }


public function getSettingValue(EntityInterface $entity, string $name): ?string
public function getSettingValue(EntityInterface $entity, string $name)
{ {
$setting = $this->getSetting($entity, $name); $setting = $this->getSetting($entity, $name);


return null; return null;
} }


public function getValue(SettingInterface $setting): ?string
public function getValue(SettingInterface $setting)
{ {
if ($setting->getText()) { if ($setting->getText()) {
return $setting->getText(); return $setting->getText();

+ 17
- 1
Twig/TwigExtension.php View File



use App\Repository\ReminderRepository; use App\Repository\ReminderRepository;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Lc\SovBundle\Component\DateComponent;
use Lc\SovBundle\Component\MetaComponent; use Lc\SovBundle\Component\MetaComponent;
use Lc\SovBundle\Component\StringComponent; use Lc\SovBundle\Component\StringComponent;
use Lc\SovBundle\Form\Newsletter\NewsletterType; use Lc\SovBundle\Form\Newsletter\NewsletterType;
protected FormFactoryInterface $formFactory; protected FormFactoryInterface $formFactory;
protected StringComponent $stringComponent; protected StringComponent $stringComponent;
protected MetaComponent $metaComponent; protected MetaComponent $metaComponent;
protected DateComponent $dateComponent;


public function __construct( public function __construct(
KernelInterface $kernel, KernelInterface $kernel,
Security $security, Security $security,
FormFactoryInterface $formFactory, FormFactoryInterface $formFactory,
StringComponent $stringComponent, StringComponent $stringComponent,
MetaComponent $metaComponent
MetaComponent $metaComponent,
DateComponent $dateComponent
) { ) {
$this->kernel = $kernel; $this->kernel = $kernel;
$this->parameterBag = $parameterBag; $this->parameterBag = $parameterBag;
$this->formFactory = $formFactory; $this->formFactory = $formFactory;
$this->stringComponent = $stringComponent; $this->stringComponent = $stringComponent;
$this->metaComponent = $metaComponent; $this->metaComponent = $metaComponent;
$this->dateComponent = $dateComponent;
} }


public function getFunctions() public function getFunctions()
new TwigFunction('die', [$this, 'die']), new TwigFunction('die', [$this, 'die']),
new TwigFunction('get_form_newsletter', [$this, 'getFormNewsletter']), new TwigFunction('get_form_newsletter', [$this, 'getFormNewsletter']),
new TwigFunction('sov_limit_text', [$this, 'limitText']), new TwigFunction('sov_limit_text', [$this, 'limitText']),
new TwigFunction('day_by_number', [$this, 'getDayByNumber']),
]; ];
} }


new TwigFilter('uc_first', [$this, 'ucFirst']), new TwigFilter('uc_first', [$this, 'ucFirst']),
new TwigFilter('format_price', [$this, 'formatPrice']), new TwigFilter('format_price', [$this, 'formatPrice']),
new TwigFilter('sov_cache', [$this, 'sovCache']), new TwigFilter('sov_cache', [$this, 'sovCache']),
new TwigFilter('slugify', [$this, 'slugify']),
]; ];
} }


return $this->stringComponent->limitText($text, $limit); return $this->stringComponent->limitText($text, $limit);
} }


public function getDayByNumber($day): string
{
return $this->dateComponent->getDayByNumber($day);
}

public function slugify($string)
{
return $this->stringComponent->slugify($string) ;
}

} }

Loading…
Cancel
Save