|
- <?php
-
- namespace Lc\CaracoleBundle\Controller\Section;
-
- use Doctrine\ORM\EntityManagerInterface;
- use Lc\CaracoleBundle\Builder\User\UserMerchantBuilder;
- use Lc\CaracoleBundle\Container\Section\SectionContainer;
- use Lc\CaracoleBundle\Form\Section\SwitchSectionFormType;
- 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("/admin/section/switch", name="admin_section_switch")
- */
- public function switchSection(
- Request $request,
- EntityManagerInterface $entityManager,
- MerchantResolver $merchantResolver,
- SectionContainer $sectionContainer,
- UserMerchantBuilder $userMerchantBuilder
- ) {
- $form = $this->createForm(SwitchSectionFormType::class);
- $form->handleRequest($request);
-
- if ($form->isSubmitted() && $form->isValid()) {
-
- // valeur par défaut de $section : Tout afficher
- $section = null;
- $idSection = $form->get('id_section')->getData();
- $userMerchant = $merchantResolver->getUserMerchant();
-
- if($userMerchant) {
- if($idSection) {
- $section = $sectionContainer->getStore()->getOneById($idSection);
- }
-
- $userMerchant->setCurrentAdminSection($section);
- $entityManager->update($userMerchant);
- $entityManager->flush();
- }
- }
-
- $referer = $request->headers->get('referer');
- return $this->redirect($referer);
- }
- }
|