|
- <?php
-
- namespace Lc\CaracoleBundle\Controller\Setting;
-
- use Lc\CaracoleBundle\Controller\ControllerTrait;
- use Lc\SovBundle\Controller\Setting\SettingAdminController as SovSettingController;
- use Lc\CaracoleBundle\Form\Setting\MerchantSettingsFormType;
- use Lc\CaracoleBundle\Form\Setting\SectionSettingsFormType;
- use Lc\SovBundle\Form\Setting\SiteSettingsFormType;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\Routing\Annotation\Route;
-
- class SettingAdminController extends SovSettingController
- {
- use ControllerTrait;
-
- /**
- * @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->getEntityManager();
-
- if ($type == 'merchant') {
- $resolver = $this->getMerchantContainer()->getResolver();
- $formClass = MerchantSettingsFormType::class;
- $settingDefinition = $this->getMerchantSettingContainer()->getDefinition();
- } elseif ($type == 'section') {
- $resolver = $this->getSectionContainer()->getResolver();
- $formClass = SectionSettingsFormType::class;
- $settingDefinition = $this->getSectionSettingContainer()->getDefinition();
- }
-
- $entity = $resolver->getCurrent();
- $displaySwitchSection = ($type == 'section') ? true : false;
- $view = '@LcCaracole/admin/setting/edit_' . $type . '.html.twig';
-
- if ($entity) {
- $form = $this->createForm($formClass, $entity);
-
- $form->handleRequest($request);
-
- if ($form->isSubmitted() && $form->isValid()) {
- $entityManager->update($entity);
- $entityManager->flush();
-
- $this->addFlashTranslator('success', 'updated');
- }
-
- return $this->render(
- $view,
- [
- 'display_switch_section' => $displaySwitchSection,
- 'resolver' => $resolver,
- 'setting_definition' => $settingDefinition,
- 'form' => $form->createView()
- ]
- );
- }
- else {
- return $this->render(
- $view,
- [
- 'display_switch_section' => $displaySwitchSection,
- 'replace_content_with_message' => "Vous devez sélectionner une section pour afficher ces données."
- ]
- );
- }
- }
-
- /**
- * @Route("/admin/setting/site2", name="carac_admin_setting_site")
- */
- public function manageGlobal(Request $request)
- {
- $entityManager = $this->getEntityManager();
- $site = $this->getSiteContainer()->getStore()->getOneByDevAlias('default');
- $form = $this->createForm(SiteSettingsFormType::class, $site);
-
- $form->handleRequest($request);
-
- if ($form->isSubmitted() && $form->isValid()) {
- $entityManager->update($site);
- $entityManager->flush();
-
- $this->addFlashTranslator('success', 'updated');
- }
-
- return $this->render(
- '@LcCaracole/admin/setting/edit_site.html.twig',
- [
- 'setting_definition' => $this->getSiteSettingContainer()->getDefinition(),
- 'form' => $form->createView()
- ]
- );
- }
- }
|