You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SwitchSectionAdminController.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. class SwitchSectionAdminController extends AbstractController
  10. {
  11. public function switchSection(
  12. Request $request,
  13. EntityManagerInterface $em,
  14. MerchantResolver $merchantResolver,
  15. SectionRepository $sectionRepository
  16. ) {
  17. $form = $this->createForm(SwitchSectionFormType::class);
  18. $form->handleRequest($request);
  19. if ($form->isSubmitted() && $form->isValid()) {
  20. $idSection = $form->get('id_section')->getData();
  21. $section = $sectionRepository->find($idSection);
  22. $userMerchant = $merchantResolver->getUserMerchant();
  23. if ($section && $userMerchant) {
  24. $userMerchant->setCurrentAdminSection($section);
  25. $em->update($section);
  26. $em->flush();
  27. }
  28. }
  29. $referer = $request->headers->get('referer');
  30. return $this->redirect($referer);
  31. }
  32. }