Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

114 lines
4.2KB

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