Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

43 lines
1.4KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Controller\Section;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\CaracoleBundle\Form\Section\SwitchSectionFormType;
  5. use Lc\CaracoleBundle\Repository\Section\SectionRepository;
  6. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. class SwitchSectionAdminController extends AbstractController
  11. {
  12. /**
  13. * @Route("/section/switch", name="carac_section_switch")
  14. */
  15. public function switchSection(
  16. Request $request,
  17. EntityManagerInterface $em,
  18. MerchantResolver $merchantResolver,
  19. SectionRepository $sectionRepository
  20. ) {
  21. $form = $this->createForm(SwitchSectionFormType::class);
  22. $form->handleRequest($request);
  23. if ($form->isSubmitted() && $form->isValid()) {
  24. $idSection = $form->get('id_section')->getData();
  25. $section = $sectionRepository->find($idSection);
  26. $userMerchant = $merchantResolver->getUserMerchant();
  27. if ($section && $userMerchant) {
  28. $userMerchant->setCurrentAdminSection($section);
  29. $em->update($section);
  30. $em->flush();
  31. }
  32. }
  33. $referer = $request->headers->get('referer');
  34. return $this->redirect($referer);
  35. }
  36. }