Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

SettingAdminController.php 5.0KB

3 anos atrás
3 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. }