You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

136 lines
5.0KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Controller\Setting;
  3. use Lc\CaracoleBundle\Container\Setting\MerchantSettingContainer;
  4. use Lc\CaracoleBundle\Container\Setting\SectionSettingContainer;
  5. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  6. use Lc\CaracoleBundle\Resolver\SectionResolver;
  7. use Lc\SovBundle\Container\Setting\SiteSettingContainer;
  8. use Lc\SovBundle\Container\Site\SiteContainer;
  9. use Lc\SovBundle\Controller\Setting\SettingAdminController as SovSettingController;
  10. use Doctrine\ORM\EntityManagerInterface;
  11. use Lc\CaracoleBundle\Form\Setting\MerchantSettingsFormType;
  12. use Lc\CaracoleBundle\Form\Setting\SectionSettingsFormType;
  13. use Lc\SovBundle\Form\Setting\SiteSettingsFormType;
  14. use Lc\SovBundle\Translation\TranslatorAdmin;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. class SettingAdminController extends SovSettingController
  18. {
  19. protected MerchantResolver $merchantResolver;
  20. protected SectionResolver $sectionResolver;
  21. protected MerchantSettingContainer $merchantSettingContainer;
  22. protected SectionSettingContainer $sectionSettingContainer;
  23. protected SiteContainer $siteContainer;
  24. protected SiteSettingContainer $siteSettingContainer;
  25. protected TranslatorAdmin $translatorAdmin;
  26. public function __construct(
  27. EntityManagerInterface $entityManager,
  28. MerchantResolver $merchantResolver,
  29. SectionResolver $sectionResolver,
  30. MerchantSettingContainer $merchantSettingContainer,
  31. SectionSettingContainer $sectionSettingContainer,
  32. SiteContainer $siteContainer,
  33. SiteSettingContainer $siteSettingContainer,
  34. TranslatorAdmin $translatorAdmin
  35. ) {
  36. parent::__construct($entityManager);
  37. $this->merchantResolver = $merchantResolver;
  38. $this->sectionResolver = $sectionResolver;
  39. $this->merchantSettingContainer = $merchantSettingContainer;
  40. $this->sectionSettingContainer = $sectionSettingContainer;
  41. $this->siteContainer = $siteContainer;
  42. $this->siteSettingContainer = $siteSettingContainer;
  43. $this->translatorAdmin = $translatorAdmin;
  44. }
  45. /**
  46. * @Route("/admin/setting/merchant", name="carac_admin_setting_merchant")
  47. */
  48. public function manageMerchant(
  49. Request $request
  50. ) {
  51. return $this->manage($request, 'merchant');
  52. }
  53. /**
  54. * @Route("/admin/setting/section", name="carac_admin_setting_section")
  55. */
  56. public function manageSection(
  57. Request $request
  58. ) {
  59. return $this->manage($request, 'section');
  60. }
  61. public function manage(
  62. Request $request,
  63. $type
  64. ) {
  65. $entity = null;
  66. $entityManager = $this->entityManager;
  67. if ($type == 'merchant') {
  68. $resolver = $this->merchantResolver;
  69. $formClass = MerchantSettingsFormType::class;
  70. $settingDefinition = $this->merchantSettingContainer->getDefinition();
  71. } elseif ($type == 'section') {
  72. $resolver = $this->sectionResolver;
  73. $formClass = SectionSettingsFormType::class;
  74. $settingDefinition = $this->sectionSettingContainer->getDefinition();
  75. }
  76. $entity = $resolver->getCurrent();
  77. if ($entity) {
  78. $form = $this->createForm($formClass, $entity);
  79. $form->handleRequest($request);
  80. if ($form->isSubmitted() && $form->isValid()) {
  81. $entityManager->update($entity);
  82. $entityManager->flush();
  83. $this->addFlash('success', $this->get(TranslatorAdmin::class)->transFlashMessage('settings_saved'));
  84. }
  85. return $this->render(
  86. '@LcCaracole/admin/setting/edit_' . $type . '.html.twig',
  87. [
  88. 'display_switch_section' => ($type == 'section') ? true : false,
  89. 'resolver' => $resolver,
  90. 'setting_definition' => $settingDefinition,
  91. 'form' => $form->createView()
  92. ]
  93. );
  94. }
  95. }
  96. /**
  97. * @Route("/admin/setting/site2", name="carac_admin_setting_site")
  98. */
  99. public function manageGlobal(Request $request, EntityManagerInterface $entityManager)
  100. {
  101. $site = $this->siteContainer->getStore()->getOneByDevAlias('default');
  102. $form = $this->createForm(SiteSettingsFormType::class, $site);
  103. $form->handleRequest($request);
  104. if ($form->isSubmitted() && $form->isValid()) {
  105. $entityManager->update($site);
  106. $entityManager->flush();
  107. $this->addFlash('success', $this->translatorAdmin->transFlashMessage('settings_saved'));
  108. }
  109. return $this->render(
  110. '@LcCaracole/admin/setting/edit_site.html.twig',
  111. [
  112. 'setting_definition' => $this->siteSettingContainer->getDefinition(),
  113. 'form' => $form->createView()
  114. ]
  115. );
  116. }
  117. }