src/Controller/HomeController.php line 75

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Creation;
  4. use App\Entity\Page;
  5. use App\Form\CreationType;
  6. use App\Repository\CreationRepository;
  7. use App\Repository\PageRepository;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use Symfony\Component\HttpFoundation\File\UploadedFile;
  13. /**
  14.  * @Route("/")
  15.  */
  16. class HomeController extends AbstractController{
  17.     /**
  18.      * @Route("/", name="home", methods={"GET"})
  19.      */
  20.     public function index(): Response{
  21.        return $this->redirectToRoute('homeByLang', ['lang' => 'en']);
  22.     }
  23.     /**
  24.      * @Route("home/legal_notice", name="legal_notice", methods={"GET"})
  25.      */
  26.     public function legal_notice(): Response{
  27.         return $this->render('home/legal_notice.html.twig', [
  28.             'controller_name' => 'HomeController',]);
  29.     }
  30.     /**
  31.      * @Route("home/{lang}/", name="homeByLang", methods={"GET"})
  32.      */
  33.     public function homeByLang(Request $requestCreationRepository $creationRepositoryPageRepository $pageRepository): Response{
  34.         $lang $request->get('lang');
  35.         $page $pageRepository->findByLang($lang);
  36.         $allPages $pageRepository->findAll();
  37.         $creations $creationRepository->findByLang($lang);
  38.         $creationsTamim $creationRepository->findByTamimByLang($lang);
  39.         $creationsSebastien $creationRepository->findBySebastienByLang($lang);
  40.         $creationsRes = [];
  41.         $nbCreations count($creations);
  42.         $nbCreationsSebastien count($creationsSebastien);
  43.         $nbCreationsTamim count($creationsTamim);
  44.         $usedRandsSebastien = [];
  45.         $usedRandsTamim = [];
  46.         $nbCreationsSebUsed 0;
  47.         $nbCreationsTamimUsed 0;
  48.         for($i 0$i $nbCreations$i++){
  49.             if(empty($creationsRes)){
  50.                 $rand rand(0$nbCreationsTamim-1);
  51.                 $creationsRes[] = $creationsTamim[$rand];
  52.                 $usedRandsTamim[] = $rand;
  53.                 $nbCreationsTamimUsed++;
  54.             }
  55.             if(end($creationsRes)->getOwner() == "tamim" && $nbCreationsSebUsed $nbCreationsSebastien){
  56.                 $rand rand(0$nbCreationsSebastien-1);
  57.                 while(in_array($rand$usedRandsSebastien)){
  58.                     $rand rand(0$nbCreationsSebastien-1);
  59.                 }
  60.                 $creationsRes[] = $creationsSebastien[$rand];
  61.                 $usedRandsSebastien[] = $rand;
  62.                 $nbCreationsSebUsed++;
  63.             }else if(end($creationsRes)->getOwner() == "sebastien" && $nbCreationsTamimUsed $nbCreationsTamim){
  64.                 $rand rand(0$nbCreationsTamim-1);
  65.                 while(in_array($rand$usedRandsTamim)){
  66.                     $rand rand(0$nbCreationsTamim-1);
  67.                 }
  68.                 $creationsRes[] = $creationsTamim[$rand];
  69.                 $usedRandsTamim[] = $rand;
  70.                 $nbCreationsTamimUsed++;
  71.             }else{
  72.                 if($nbCreationsTamimUsed $nbCreationsTamim){
  73.                     $rand rand(0$nbCreationsTamim-1);
  74.                     while(in_array($rand$usedRandsTamim)){
  75.                         $rand rand(0$nbCreationsTamim-1);
  76.                     }
  77.                     $creationsRes[] = $creationsTamim[$rand];
  78.                     $usedRandsTamim[] = $rand;
  79.                     $nbCreationsTamimUsed++;
  80.                 }
  81.                 if($nbCreationsSebUsed $nbCreationsSebastien){
  82.                     $rand rand(0$nbCreationsSebastien-1);
  83.                     while(in_array($rand$usedRandsSebastien)){
  84.                         $rand rand(0$nbCreationsSebastien-1);
  85.                     }
  86.                     $creationsRes[] = $creationsSebastien[$rand];
  87.                     $usedRandsSebastien[] = $rand;
  88.                     $nbCreationsSebUsed++;
  89.                 }
  90.             }
  91.         }
  92.         return $this->render('home/index.html.twig', [
  93.             'creations' => $creationsRes,
  94.             'allPages' => $allPages,
  95.             'mainPage' => $page,
  96.         ]);
  97.     }
  98. }