Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

132 lines
4.6KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Controller\Setting;
  3. use Lc\SovBundle\Controller\Setting\SettingAdminController as SovSettingController;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface;
  6. use Lc\CaracoleBundle\Form\Setting\MerchantSettingsFormType;
  7. use Lc\CaracoleBundle\Form\Setting\SectionSettingsFormType;
  8. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  9. use Lc\CaracoleBundle\Resolver\SectionResolver;
  10. use Lc\CaracoleBundle\Definition\SectionSettingDefinitionInterface;
  11. use Lc\SovBundle\Definition\SiteSettingDefinition;
  12. use Lc\SovBundle\Form\Setting\SiteSettingsFormType;
  13. use Lc\SovBundle\Repository\Site\SiteRepository;
  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 $em;
  20. protected $translatorAdmin;
  21. protected $merchantResolver;
  22. protected $merchantSettingDefinition;
  23. protected $sectionResolver;
  24. protected $sectionSettingDefinition;
  25. protected $siteSettingDefinition;
  26. protected $siteRepository;
  27. public function __construct(
  28. EntityManagerInterface $em,
  29. TranslatorAdmin $translatorAdmin,
  30. MerchantResolver $merchantResolver,
  31. SectionResolver $sectionResolver,
  32. MerchantSettingDefinitionInterface $merchantSettingDefinition,
  33. SectionSettingDefinitionInterface $sectionSettingDefinition,
  34. SiteSettingDefinition $siteSettingDefinition,
  35. SiteRepository $siteRepository
  36. ) {
  37. $this->em = $em;
  38. $this->translatorAdmin = $translatorAdmin;
  39. $this->merchantResolver = $merchantResolver;
  40. $this->sectionResolver = $sectionResolver;
  41. $this->merchantSettingDefinition = $merchantSettingDefinition;
  42. $this->sectionSettingDefinition = $sectionSettingDefinition;
  43. $this->siteSettingDefinition = $siteSettingDefinition;
  44. $this->siteRepository = $siteRepository;
  45. }
  46. /**
  47. * @Route("/admin/setting/merchant", name="carac_admin_setting_merchant")
  48. */
  49. public function manageMerchant(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(Request $request)
  57. {
  58. return $this->manage($request, 'section');
  59. }
  60. public function manage(Request $request, $type)
  61. {
  62. $entity = null;
  63. if ($type == 'merchant') {
  64. $resolver = $this->merchantResolver;
  65. $formClass = MerchantSettingsFormType::class;
  66. $settingDefinition = $this->merchantSettingDefinition;
  67. } elseif ($type == 'section') {
  68. $resolver = $this->sectionResolver;
  69. $formClass = SectionSettingsFormType::class;
  70. $settingDefinition = $this->sectionSettingDefinition;
  71. }
  72. $entity = $resolver->getCurrent();
  73. if ($entity) {
  74. $form = $this->createForm($formClass, $entity);
  75. $form->handleRequest($request);
  76. if ($form->isSubmitted() && $form->isValid()) {
  77. $this->em->update($entity);
  78. $this->em->flush();
  79. $this->addFlash('success', $this->translatorAdmin->transFlashMessage('settings_saved'));
  80. }
  81. return $this->render(
  82. '@LcCaracole/admin/setting/edit_' . $type . '.html.twig',
  83. [
  84. 'display_switch_section' => ($type == 'section') ? true : false,
  85. 'resolver' => $resolver,
  86. 'setting_definition' => $settingDefinition,
  87. 'form' => $form->createView()
  88. ]
  89. );
  90. }
  91. }
  92. /**
  93. * @Route("/admin/setting/site2", name="carac_admin_setting_site")
  94. */
  95. public function manageGlobal(Request $request)
  96. {
  97. $site = $this->siteRepository->findOneByDevAlias('default');
  98. $form = $this->createForm(SiteSettingsFormType::class, $site);
  99. $form->handleRequest($request);
  100. if ($form->isSubmitted() && $form->isValid()) {
  101. $this->em->update($site);
  102. $this->em->flush();
  103. $this->addFlash('success', $this->translatorAdmin->transFlashMessage('settings_saved'));
  104. }
  105. return $this->render(
  106. '@LcCaracole/admin/setting/edit_site.html.twig',
  107. [
  108. 'setting_definition' => $this->siteSettingDefinition,
  109. 'form' => $form->createView()
  110. ]
  111. );
  112. }
  113. }