|
12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
-
- namespace Lc\CaracoleBundle\Controller\Section;
-
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\CaracoleBundle\Form\Section\SwitchSectionFormType;
- use Lc\CaracoleBundle\Repository\Section\SectionRepository;
- use Lc\CaracoleBundle\Resolver\MerchantResolver;
- use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\Routing\Annotation\Route;
-
- class SwitchSectionAdminController extends AbstractController
- {
-
- /**
- * @Route("/section/switch", name="carac_section_switch")
- */
- public function switchSection(
- Request $request,
- EntityManagerInterface $em,
- MerchantResolver $merchantResolver,
- SectionRepository $sectionRepository
- ) {
- $form = $this->createForm(SwitchSectionFormType::class);
- $form->handleRequest($request);
-
- if ($form->isSubmitted() && $form->isValid()) {
- $idSection = $form->get('id_section')->getData();
- $section = $sectionRepository->find($idSection);
- $userMerchant = $merchantResolver->getUserMerchant();
-
- if ($section && $userMerchant) {
- $userMerchant->setCurrentAdminSection($section);
- $em->update($section);
- $em->flush();
- }
- }
-
- $referer = $request->headers->get('referer');
- return $this->redirect($referer);
- }
- }
|