|
123456789101112131415161718192021222324252627282930313233343536373839 |
- <?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;
-
- class SwitchSectionAdminController extends AbstractController
- {
-
- 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);
- }
- }
|