Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

50 rindas
1.7KB

  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. // valeur par défaut de $section : Tout afficher
  27. $section = null;
  28. $idSection = $form->get('id_section')->getData();
  29. $userMerchant = $merchantResolver->getUserMerchant();
  30. if($userMerchant) {
  31. if($idSection) {
  32. $section = $sectionContainer->getStore()->getOneById($idSection);
  33. }
  34. $userMerchant->setCurrentAdminSection($section);
  35. $entityManager->update($userMerchant);
  36. $entityManager->flush();
  37. }
  38. }
  39. $referer = $request->headers->get('referer');
  40. return $this->redirect($referer);
  41. }
  42. }