src/Controller/Client/v2/DashController.php line 78

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Client\v2;
  3. use App\Entity\Client;
  4. use App\Entity\Company;
  5. use App\Entity\Segmentation;
  6. use App\Entity\User;
  7. use App\Form\Client\SegmentationType;
  8. use App\Repository\ArticleRepository;
  9. use App\Repository\ChannelRepository;
  10. use App\Repository\ProgramRepository;
  11. use App\Repository\RegistrationRepository;
  12. use App\Repository\SlideRepository;
  13. use App\Repository\TeamplayRepository;
  14. use App\Repository\TeamRepository;
  15. use App\Repository\VideoRepository;
  16. use App\Service\LogService;
  17. use App\Service\SegmentationService;
  18. use Doctrine\ORM\EntityManagerInterface;
  19. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  20. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\HttpFoundation\Response;
  23. use Symfony\Component\Routing\Annotation\Route;
  24. /**
  25.  * @isGranted("ROLE_CLIENT")
  26.  */
  27. class DashController extends AbstractController
  28. {
  29.     private $em;
  30.     private $teamRepository;
  31.     private $teamplayRepository;
  32.     private $registrationRepository;
  33.     private $slideRepository;
  34.     private $programRepository;
  35.     private $channelRepository;
  36.     private $videoRepository;
  37.     private $articleRepository;
  38.     private $segmentationService;
  39.     /**
  40.      * @var LogService
  41.      */
  42.     private $logService;
  43.     
  44.     public function __construct(
  45.         EntityManagerInterface $em,
  46.         TeamRepository $teamRepository,
  47.         TeamplayRepository $teamplayRepository,
  48.         RegistrationRepository $registrationRepository,
  49.         SlideRepository $slideRepository,
  50.         ProgramRepository $programRepository,
  51.         ChannelRepository $channelRepository,
  52.         VideoRepository $videoRepository,
  53.         ArticleRepository $articleRepository,
  54.         SegmentationService $segmentationService,
  55.         LogService $logService
  56.     )
  57.     {
  58.         $this->em $em;
  59.         $this->teamRepository $teamRepository;
  60.         $this->teamplayRepository $teamplayRepository;
  61.         $this->registrationRepository $registrationRepository;
  62.         $this->slideRepository $slideRepository;
  63.         $this->programRepository $programRepository;
  64.         $this->channelRepository $channelRepository;
  65.         $this->videoRepository $videoRepository;
  66.         $this->articleRepository $articleRepository;
  67.         $this->segmentationService $segmentationService;
  68.         $this->logService $logService;
  69.     }
  70.     /**
  71.      * @Route("/", name="dashboard")
  72.      */
  73.     public function index(Request $request): Response
  74.     {   
  75.         $client $allowedSegmentations null;
  76.         $formView  null;
  77.         $showSegmentationForm false;
  78.         /**
  79.          *  @var Client 
  80.          */
  81.         $client $this->em->getRepository(Client::class)->find($this->getUser()->getClient()->getId());
  82.         // Ajout log d'utilisation de la plateforme
  83.         $this->logService->postLogForUser($this->getUser()->getId(), $client->getCompany()->getId(), "NULL");
  84.         if($client instanceof Client) {
  85.             // Redirection vers "Informations" si pas de "Nom" et "PrĂ©nom ou si pas de cgu"
  86.             if(empty($client->getFirstName()) || empty($client->getLastName())) {
  87.                 return $this->redirectToRoute('client_myaccount', ["error" => "no_name"]);
  88.             }
  89.             if(empty($client->getIsCgu())) {
  90.                 return $this->redirectToRoute('client_myaccount', ["error" => "no_cgu"]);
  91.             }
  92.             if($client->getSegmentation() instanceof Segmentation) {
  93.                 if($client->getSegmentation()->getParent() instanceof Segmentation && !$client->getSegmentation()->isAlone()) {
  94.                     $allowedSegmentations $client->getSegmentation()->getParent()->getChildren()->toArray();
  95.                 } else {
  96.                     $allowedSegmentations = [$client->getSegmentation()];
  97.                 }
  98.             }else{
  99.                 if ($client->getCompany()->getForceSegmentation() == true) {
  100.                     $showSegmentationForm true;
  101.                     /**
  102.                      *  @var User 
  103.                      */
  104.                     $user $this->em->getRepository(User::class)->find($this->getUser());
  105.     
  106.                     $company $this->em->getRepository(Company::class)->find($client->getCompany()->getId());
  107.                     $segmentationChoices = [];
  108.                     if (!empty($company->getSegmentations()->toArray())) {
  109.                         foreach ($company->getSegmentations()->toArray() as $key => $segmentation) {
  110.                             if (empty($segmentation->getChildren()->toArray())) {
  111.     
  112.                                 $segmentationKey = ($segmentation->getParent() != null) ? ($segmentation->getParent()->getName()) : "Autre" ;
  113.     
  114.                                 $segmentationChoices[$segmentationKey][$this->segmentationService->getSegmentationName($segmentation->getName())] = $segmentation;
  115.                             }
  116.                         }
  117.                         $form $this->createForm(SegmentationType::class, $client, ['segmentationChoices' => $segmentationChoices]);
  118.                         $form->handleRequest($request);
  119.                         if ($form->isSubmitted() && $form->isValid()) {
  120.                             $user->setSegmentation($client->getSegmentation());
  121.                             $this->em->persist($client);
  122.                             $this->em->persist($user);
  123.                             $this->em->flush();
  124.                             return $this->redirectToRoute('client_dashboard');
  125.                         }
  126.                     }
  127.                     $formView $form->createView();
  128.                 }
  129.             }
  130.         } 
  131.         $teamplay $this->teamplayRepository->findTeamplayInProgressForDesktop($client->getCompany());
  132.         $team null;
  133.         if ($teamplay) {
  134.             $team $this->teamRepository->getTeamByUserAndTeamplay($this->getUser(), $teamplay);
  135.         }
  136.         $registrations $this->registrationRepository->getRegistrationsForClient($client'start'true);
  137.         $hpSlides $this->slideRepository->getHpSlide($client->getCompany(), 'homepage_slide');
  138.         $programs $this->programRepository->getRandomProgramsDql(3);
  139.         $expressPrograms $this->channelRepository->findRandomExpressProgramsBy([], );
  140.         $dailyVideo $this->videoRepository->getDailyVideo();
  141.         $randomVideos $this->videoRepository->customGetVideosRandom(['is_recipe' => 0'forthcoming' => 0], 10);
  142.         $dailySlideArray  array_merge($programs$expressPrograms);
  143.         $articles $this->articleRepository->findBy([
  144.             'homepage' => 1,
  145.             'active' => 1
  146.         ]);
  147.         return $this->render('client/v2/dashboard.html.twig', [
  148.             'registrations'         => $registrations,
  149.             'showSegmentationForm'  => $showSegmentationForm,
  150.             'hpSlides'              => $hpSlides,
  151.             'dailySlideContent'     => $dailySlideArray,
  152.             "dailyVideo"            => $dailyVideo,
  153.             'randomVideos'          => $randomVideos,
  154.             'articles'              => $articles,
  155.             'teamplay'              => $teamplay,
  156.             'team'                  => $team,
  157.             'allowedSegmentations'  => $allowedSegmentations,
  158.             'formView'              => $formView,
  159.         ]);
  160.     }
  161.     
  162. }