您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

86 行
2.8KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Controller\Setting;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\CaracoleBundle\Definition\MerchantSettingDefinitionInterface;
  5. use Lc\CaracoleBundle\Form\Setting\MerchantSettingsFormType;
  6. use Lc\CaracoleBundle\Form\Setting\SectionSettingsFormType;
  7. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  8. use Lc\CaracoleBundle\Resolver\SectionResolver;
  9. use Lc\CaracoleBundle\Definition\SectionSettingDefinitionInterface;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Component\HttpFoundation\Request;
  12. class SettingAdminController extends AbstractController
  13. {
  14. protected $em;
  15. protected $merchantResolver;
  16. protected $merchantSettingDefinition;
  17. protected $sectionResolver;
  18. protected $sectionSettingDefinition;
  19. public function __construct(
  20. EntityManagerInterface $em,
  21. MerchantResolver $merchantResolver,
  22. SectionResolver $sectionResolver,
  23. MerchantSettingDefinitionInterface $merchantSettingDefinition,
  24. SectionSettingDefinitionInterface $sectionSettingDefinition
  25. ) {
  26. $this->em = $em;
  27. $this->merchantResolver = $merchantResolver;
  28. $this->sectionResolver = $sectionResolver;
  29. $this->merchantSettingDefinition = $merchantSettingDefinition;
  30. $this->sectionSettingDefinition = $sectionSettingDefinition;
  31. }
  32. public function manageMerchant(Request $request)
  33. {
  34. return $this->manage($request, 'merchant');
  35. }
  36. public function manageSection(Request $request)
  37. {
  38. return $this->manage($request, 'section');
  39. }
  40. public function manage(Request $request, $type)
  41. {
  42. $entity = null ;
  43. if ($type == 'merchant') {
  44. $resolver = $this->merchantResolver ;
  45. $formClass = MerchantSettingsFormType::class;
  46. $settingDefinition = $this->merchantSettingDefinition ;
  47. } elseif ($type == 'section') {
  48. $resolver = $this->sectionResolver ;
  49. $formClass = SectionSettingsFormType::class;
  50. $settingDefinition = $this->sectionSettingDefinition ;
  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. $this->em->update($entity);
  58. $this->em->flush();
  59. $this->addFlash('success', 'Paramètres mis à jour');
  60. }
  61. return $this->render(
  62. '@LcCaracole/admin/setting/' . $type . '.html.twig',
  63. [
  64. 'resolver' => $resolver,
  65. 'setting_definition' => $settingDefinition,
  66. 'form' => $form->createView()
  67. ]
  68. );
  69. }
  70. }
  71. }