|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
-
- namespace Lc\CaracoleBundle\Controller\Setting;
-
- use Lc\SovBundle\Controller\Setting\SettingAdminController as SovSettingController;
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface;
- use Lc\CaracoleBundle\Form\Setting\MerchantSettingsFormType;
- 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\Component\HttpFoundation\Request;
-
- class SettingAdminController extends SovSettingController
- {
- protected $em;
- protected $translatorAdmin;
- protected $merchantResolver;
- protected $merchantSettingDefinition;
- protected $sectionResolver;
- protected $sectionSettingDefinition;
- protected $siteSettingDefinition;
- protected $siteRepository;
-
- public function __construct(
- EntityManagerInterface $em,
- TranslatorAdmin $translatorAdmin,
- MerchantResolver $merchantResolver,
- SectionResolver $sectionResolver,
- MerchantSettingDefinitionInterface $merchantSettingDefinition,
- SectionSettingDefinitionInterface $sectionSettingDefinition,
- SiteSettingDefinition $siteSettingDefinition,
- SiteRepository $siteRepository
- ) {
- $this->em = $em;
- $this->translatorAdmin = $translatorAdmin;
- $this->merchantResolver = $merchantResolver;
- $this->sectionResolver = $sectionResolver;
- $this->merchantSettingDefinition = $merchantSettingDefinition;
- $this->sectionSettingDefinition = $sectionSettingDefinition;
- $this->siteSettingDefinition = $siteSettingDefinition;
- $this->siteRepository = $siteRepository;
- }
-
- public function manageMerchant(Request $request)
- {
- return $this->manage($request, 'merchant');
- }
-
- public function manageSection(Request $request)
- {
- return $this->manage($request, 'section');
- }
-
- public function manage(Request $request, $type)
- {
- $entity = null;
-
- if ($type == 'merchant') {
- $resolver = $this->merchantResolver;
- $formClass = MerchantSettingsFormType::class;
- $settingDefinition = $this->merchantSettingDefinition;
- } elseif ($type == 'section') {
- $resolver = $this->sectionResolver;
- $formClass = SectionSettingsFormType::class;
- $settingDefinition = $this->sectionSettingDefinition;
- }
-
- $entity = $resolver->getCurrent();
-
- if ($entity) {
- $form = $this->createForm($formClass, $entity);
-
- $form->handleRequest($request);
-
- if ($form->isSubmitted() && $form->isValid()) {
- $this->em->update($entity);
- $this->em->flush();
-
- $this->addFlash('success', $this->translatorAdmin->transFlashMessage('settings_saved'));
- }
-
- return $this->render(
- '@LcCaracole/admin/setting/' . $type . '.html.twig',
- [
- 'resolver' => $resolver,
- 'setting_definition' => $settingDefinition,
- 'form' => $form->createView()
- ]
- );
- }
- }
-
- 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()
- ]
- );
- }
- }
|