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

@@ -17,6 +17,7 @@ use Lc\SovBundle\Container\Ticket\TicketMessageContainer;
use Lc\SovBundle\Container\User\GroupUserContainer;
use Lc\SovBundle\Container\User\UserContainer;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController as SfAbstractController;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
@@ -44,8 +45,9 @@ class AbstractController extends SfAbstractController
PaginatorInterface::class => PaginatorInterface::class,
RequestStack::class => RequestStack::class,
EventDispatcherInterface::class => EventDispatcherInterface::class,
TranslatorInterface::class => TranslatorInterface::class,
LoggerInterface::class => LoggerInterface::class,
TranslatorInterface::class => TranslatorInterface::class,
TranslatorAdmin::class => TranslatorAdmin::class,
SettingSolver::class => SettingSolver::class,
ComponentContainer::class => ComponentContainer::class,
FileContainer::class => FileContainer::class,
@@ -113,6 +115,11 @@ class AbstractController extends SfAbstractController
return $this->get(TranslatorInterface::class);
}

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

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

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

@@ -2,34 +2,21 @@

namespace Lc\SovBundle\Controller\Setting;

use Doctrine\ORM\EntityManagerInterface;
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\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\Routing\Annotation\Route;

class SettingAdminController extends AbstractController
{
protected EntityManagerInterface $entityManager;

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

/**
* @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->handleRequest($request);
@@ -39,7 +26,7 @@ class SettingAdminController extends AbstractController
$entityManager->update($site);
$entityManager->flush();

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

return $this->render(

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

@@ -21,7 +21,7 @@ class SettingSolver
return null;
}

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

@@ -32,7 +32,7 @@ class SettingSolver
return null;
}

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

+ 17
- 1
Twig/TwigExtension.php View File

@@ -4,6 +4,7 @@ namespace Lc\SovBundle\Twig;

use App\Repository\ReminderRepository;
use Doctrine\ORM\EntityManagerInterface;
use Lc\SovBundle\Component\DateComponent;
use Lc\SovBundle\Component\MetaComponent;
use Lc\SovBundle\Component\StringComponent;
use Lc\SovBundle\Form\Newsletter\NewsletterType;
@@ -37,6 +38,7 @@ class TwigExtension extends AbstractExtension
protected FormFactoryInterface $formFactory;
protected StringComponent $stringComponent;
protected MetaComponent $metaComponent;
protected DateComponent $dateComponent;

public function __construct(
KernelInterface $kernel,
@@ -51,7 +53,8 @@ class TwigExtension extends AbstractExtension
Security $security,
FormFactoryInterface $formFactory,
StringComponent $stringComponent,
MetaComponent $metaComponent
MetaComponent $metaComponent,
DateComponent $dateComponent
) {
$this->kernel = $kernel;
$this->parameterBag = $parameterBag;
@@ -66,6 +69,7 @@ class TwigExtension extends AbstractExtension
$this->formFactory = $formFactory;
$this->stringComponent = $stringComponent;
$this->metaComponent = $metaComponent;
$this->dateComponent = $dateComponent;
}

public function getFunctions()
@@ -80,6 +84,7 @@ class TwigExtension extends AbstractExtension
new TwigFunction('die', [$this, 'die']),
new TwigFunction('get_form_newsletter', [$this, 'getFormNewsletter']),
new TwigFunction('sov_limit_text', [$this, 'limitText']),
new TwigFunction('day_by_number', [$this, 'getDayByNumber']),
];
}

@@ -94,6 +99,7 @@ class TwigExtension extends AbstractExtension
new TwigFilter('uc_first', [$this, 'ucFirst']),
new TwigFilter('format_price', [$this, 'formatPrice']),
new TwigFilter('sov_cache', [$this, 'sovCache']),
new TwigFilter('slugify', [$this, 'slugify']),
];
}

@@ -169,4 +175,14 @@ class TwigExtension extends AbstractExtension
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