No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

113 líneas
3.8KB

  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. $form->handleRequest($request);
  56. if ($form->isSubmitted() && $form->isValid()) {
  57. $entityManager->update($entity);
  58. $entityManager->flush();
  59. $this->addFlashTranslator('success','updated');
  60. }
  61. return $this->render(
  62. '@LcCaracole/admin/setting/edit_' . $type . '.html.twig',
  63. [
  64. 'display_switch_section' => ($type == 'section') ? true : false,
  65. 'resolver' => $resolver,
  66. 'setting_definition' => $settingDefinition,
  67. 'form' => $form->createView()
  68. ]
  69. );
  70. }
  71. }
  72. /**
  73. * @Route("/admin/setting/site2", name="carac_admin_setting_site")
  74. */
  75. public function manageGlobal(Request $request)
  76. {
  77. $entityManager = $this->getEntityManager();
  78. $site = $this->getSiteContainer()->getStore()->getOneByDevAlias('default');
  79. $form = $this->createForm(SiteSettingsFormType::class, $site);
  80. $form->handleRequest($request);
  81. if ($form->isSubmitted() && $form->isValid()) {
  82. $entityManager->update($site);
  83. $entityManager->flush();
  84. $this->addFlashTranslator('success','updated');
  85. }
  86. return $this->render(
  87. '@LcCaracole/admin/setting/edit_site.html.twig',
  88. [
  89. 'setting_definition' => $this->getSiteSettingContainer()->getDefinition(),
  90. 'form' => $form->createView()
  91. ]
  92. );
  93. }
  94. }