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.

SwitchSectionAdminController.php 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Lc\CaracoleBundle\Controller\Section;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Lc\CaracoleBundle\Builder\User\UserMerchantBuilder;
  5. use Lc\CaracoleBundle\Container\Section\SectionContainer;
  6. use Lc\CaracoleBundle\Form\Section\SwitchSectionFormType;
  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("/admin/section/switch", name="carac_section_switch")
  15. */
  16. public function switchSection(
  17. Request $request,
  18. EntityManagerInterface $entityManager,
  19. MerchantResolver $merchantResolver,
  20. SectionContainer $sectionContainer,
  21. UserMerchantBuilder $userMerchantBuilder
  22. ) {
  23. $form = $this->createForm(SwitchSectionFormType::class);
  24. $form->handleRequest($request);
  25. if ($form->isSubmitted() && $form->isValid()) {
  26. $idSection = $form->get('id_section')->getData();
  27. $section = $sectionContainer->getStore()->getOneById($idSection);
  28. $userMerchant = $merchantResolver->getUserMerchant();
  29. if ($section && $userMerchant) {
  30. $userMerchant->setCurrentAdminSection($section);
  31. $entityManager->update($section);
  32. $entityManager->flush();
  33. }
  34. }
  35. $referer = $request->headers->get('referer');
  36. return $this->redirect($referer);
  37. }
  38. }