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.

SwitchSectionAdminController.php 1.5KB

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