選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

44 行
1.5KB

  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. }