|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <?php
-
- namespace Lc\CaracoleBundle\Controller\Setting;
-
- use Lc\CaracoleBundle\Container\Setting\MerchantSettingContainer;
- use Lc\CaracoleBundle\Container\Setting\SectionSettingContainer;
- use Lc\CaracoleBundle\Resolver\MerchantResolver;
- use Lc\CaracoleBundle\Resolver\SectionResolver;
- use Lc\SovBundle\Container\Setting\SiteSettingContainer;
- use Lc\SovBundle\Container\Site\SiteContainer;
- use Lc\SovBundle\Controller\Setting\SettingAdminController as SovSettingController;
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\CaracoleBundle\Form\Setting\MerchantSettingsFormType;
- use Lc\CaracoleBundle\Form\Setting\SectionSettingsFormType;
- use Lc\SovBundle\Form\Setting\SiteSettingsFormType;
- use Lc\SovBundle\Translation\TranslatorAdmin;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\Routing\Annotation\Route;
-
- class SettingAdminController extends SovSettingController
- {
- protected MerchantResolver $merchantResolver;
- protected SectionResolver $sectionResolver;
- protected MerchantSettingContainer $merchantSettingContainer;
- protected SectionSettingContainer $sectionSettingContainer;
- protected SiteContainer $siteContainer;
- protected SiteSettingContainer $siteSettingContainer;
- protected TranslatorAdmin $translatorAdmin;
-
- public function __construct(
- EntityManagerInterface $entityManager,
- MerchantResolver $merchantResolver,
- SectionResolver $sectionResolver,
- MerchantSettingContainer $merchantSettingContainer,
- SectionSettingContainer $sectionSettingContainer,
- SiteContainer $siteContainer,
- SiteSettingContainer $siteSettingContainer,
- TranslatorAdmin $translatorAdmin
- ) {
- parent::__construct($entityManager);
- $this->merchantResolver = $merchantResolver;
- $this->sectionResolver = $sectionResolver;
- $this->merchantSettingContainer = $merchantSettingContainer;
- $this->sectionSettingContainer = $sectionSettingContainer;
- $this->siteContainer = $siteContainer;
- $this->siteSettingContainer = $siteSettingContainer;
- $this->translatorAdmin = $translatorAdmin;
- }
-
- /**
- * @Route("/admin/setting/merchant", name="carac_admin_setting_merchant")
- */
- public function manageMerchant(
- Request $request
- ) {
- return $this->manage($request, 'merchant');
- }
-
- /**
- * @Route("/admin/setting/section", name="carac_admin_setting_section")
- */
- public function manageSection(
- Request $request
- ) {
- return $this->manage($request, 'section');
- }
-
- public function manage(
- Request $request,
- $type
- ) {
- $entity = null;
- $entityManager = $this->entityManager;
-
- if ($type == 'merchant') {
- $resolver = $this->merchantResolver;
- $formClass = MerchantSettingsFormType::class;
- $settingDefinition = $this->merchantSettingContainer->getDefinition();
- } elseif ($type == 'section') {
- $resolver = $this->sectionResolver;
- $formClass = SectionSettingsFormType::class;
- $settingDefinition = $this->sectionSettingContainer->getDefinition();
- }
-
- $entity = $resolver->getCurrent();
-
- if ($entity) {
- $form = $this->createForm($formClass, $entity);
-
- $form->handleRequest($request);
-
- if ($form->isSubmitted() && $form->isValid()) {
- $entityManager->update($entity);
- $entityManager->flush();
-
- $this->addFlash('success', $this->get(TranslatorAdmin::class)->transFlashMessage('settings_saved'));
- }
-
- return $this->render(
- '@LcCaracole/admin/setting/edit_' . $type . '.html.twig',
- [
- 'display_switch_section' => ($type == 'section') ? true : false,
- 'resolver' => $resolver,
- 'setting_definition' => $settingDefinition,
- 'form' => $form->createView()
- ]
- );
- }
- }
-
- /**
- * @Route("/admin/setting/site2", name="carac_admin_setting_site")
- */
- public function manageGlobal(Request $request, EntityManagerInterface $entityManager)
- {
- $site = $this->siteContainer->getStore()->getOneByDevAlias('default');
- $form = $this->createForm(SiteSettingsFormType::class, $site);
-
- $form->handleRequest($request);
-
- if ($form->isSubmitted() && $form->isValid()) {
- $entityManager->update($site);
- $entityManager->flush();
-
- $this->addFlash('success', $this->translatorAdmin->transFlashMessage('settings_saved'));
- }
-
- return $this->render(
- '@LcCaracole/admin/setting/edit_site.html.twig',
- [
- 'setting_definition' => $this->siteSettingContainer->getDefinition(),
- 'form' => $form->createView()
- ]
- );
- }
- }
|