Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

112 lines
3.9KB

  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\Controller\ControllerTrait;
  6. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  7. use Lc\CaracoleBundle\Resolver\SectionResolver;
  8. use Lc\SovBundle\Container\Setting\SiteSettingContainer;
  9. use Lc\SovBundle\Container\Site\SiteContainer;
  10. use Lc\SovBundle\Controller\Setting\SettingAdminController as SovSettingController;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use Lc\CaracoleBundle\Form\Setting\MerchantSettingsFormType;
  13. use Lc\CaracoleBundle\Form\Setting\SectionSettingsFormType;
  14. use Lc\SovBundle\Form\Setting\SiteSettingsFormType;
  15. use Lc\SovBundle\Translation\TranslatorAdmin;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. class SettingAdminController extends SovSettingController
  19. {
  20. use ControllerTrait;
  21. /**
  22. * @Route("/admin/setting/merchant", name="carac_admin_setting_merchant")
  23. */
  24. public function manageMerchant(
  25. Request $request
  26. ) {
  27. return $this->manage($request, 'merchant');
  28. }
  29. /**
  30. * @Route("/admin/setting/section", name="carac_admin_setting_section")
  31. */
  32. public function manageSection(
  33. Request $request
  34. ) {
  35. return $this->manage($request, 'section');
  36. }
  37. public function manage(
  38. Request $request,
  39. $type
  40. ) {
  41. $entity = null;
  42. $entityManager = $this->getEntityManager();
  43. if ($type == 'merchant') {
  44. $resolver = $this->getMerchantContainer()->getResolver();
  45. $formClass = MerchantSettingsFormType::class;
  46. $settingDefinition = $this->getMerchantSettingContainer()->getDefinition();
  47. } elseif ($type == 'section') {
  48. $resolver = $this->getSectionContainer()->getResolver();
  49. $formClass = SectionSettingsFormType::class;
  50. $settingDefinition = $this->getSectionSettingContainer()->getDefinition();
  51. }
  52. $entity = $resolver->getCurrent();
  53. if ($entity) {
  54. $form = $this->createForm($formClass, $entity);
  55. dump($request);
  56. $form->handleRequest($request);
  57. if ($form->isSubmitted() && $form->isValid()) {
  58. $entityManager->update($entity);
  59. $entityManager->flush();
  60. $this->addFlash('success', $this->getTranslatorAdmin()->transFlashMessage('settings_saved'));
  61. }
  62. return $this->render(
  63. '@LcCaracole/admin/setting/edit_' . $type . '.html.twig',
  64. [
  65. 'display_switch_section' => ($type == 'section') ? true : false,
  66. 'resolver' => $resolver,
  67. 'setting_definition' => $settingDefinition,
  68. 'form' => $form->createView()
  69. ]
  70. );
  71. }
  72. }
  73. /**
  74. * @Route("/admin/setting/site2", name="carac_admin_setting_site")
  75. */
  76. public function manageGlobal(Request $request)
  77. {
  78. $entityManager = $this->getEntityManager();
  79. $site = $this->getSiteContainer()->getStore()->getOneByDevAlias('default');
  80. $form = $this->createForm(SiteSettingsFormType::class, $site);
  81. $form->handleRequest($request);
  82. if ($form->isSubmitted() && $form->isValid()) {
  83. $entityManager->update($site);
  84. $entityManager->flush();
  85. $this->addFlash('success', $this->getTranslatorAdmin()->transFlashMessage('settings_saved'));
  86. }
  87. return $this->render(
  88. '@LcCaracole/admin/setting/edit_site.html.twig',
  89. [
  90. 'setting_definition' => $this->getSiteSettingContainer()->getDefinition(),
  91. 'form' => $form->createView()
  92. ]
  93. );
  94. }
  95. }