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.

44 satır
1.6KB

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