src/Controller/DefaultController.php line 51

  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\CharacterRepository;
  4. use App\Repository\CourseRepository;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. class DefaultController extends AbstractController
  9. {
  10.     private $projectDir;
  11.     private $publicDir;
  12.     private $dataCharRoute;
  13.     private $pictureCharRoute;
  14.     public function  __construct(string $projectDirstring $publicDirstring $dataCharRoutestring $pictureCharRoute){
  15.         $this->projectDir=$projectDir;
  16.         $this->publicDir=$publicDir;
  17.         $this->dataCharRoute=$dataCharRoute;
  18.         $this->pictureCharRoute=$pictureCharRoute;
  19.     }
  20.     #[Route('/'name'homepage')]
  21.     public function index(): Response
  22.     {
  23.         return $this->render('default/index.html.twig', [
  24.             'controller_name' => 'DefaultController',
  25.         ]);
  26.     } # END DEFAULT
  27.     #[Route('/menu'name'app_menu')]
  28.     public function menu(): Response
  29.     {
  30.         return $this->render('default/menu.html.twig', [
  31.         ]);
  32.     }
  33.     #[Route('/game-policy'name'gamePolicy')]
  34.     public function policy(): Response
  35.     {
  36.         return $this->render('default/confidantialPolicy.html.twig', [
  37.         ]);
  38.     } # END MENU
  39.     #[Route('/learn'name'app_learn')]
  40.     public function learn(CourseRepository $courseRepository): Response
  41.     {
  42.         $courses $courseRepository->findAll();
  43.         return $this->render('learn/learn.html.twig', [
  44.             'courses' => $courses,
  45.         ]);
  46.     } # END LEARN
  47.     #[Route('/open-source'name'app_open-source')]
  48.     public function openSource(): Response
  49.     {
  50.         return $this->render('default/open-source.html.twig', [
  51.         ]);
  52.     }
  53.     #[Route('/multilinguisme'name'app_multilinguisme')]
  54.     public function multilinguisme(): Response
  55.     {
  56.         return $this->render('default/multilinguisme.html.twig', [
  57.         ]);
  58.     }
  59.     #[Route('/game-policy'name'app_game-policy')]
  60.     public function game_policy(): Response
  61.     {
  62.         return $this->render('default/confidantialPolicy.html.twig', [
  63.         ]);
  64.     }
  65.     
  66.     #[Route('/learn/dictionary/page/{page}'name'app_dictionary'requirements: ['page'=>'\d+'], defaults:['page'=>1], priority3)]
  67.     public function dictionary(CharacterRepository $characterRepositoryint $page): Response
  68.     {
  69.         $nbpages ceil($characterRepository->count(criteria: []) / 10);
  70.         if ($nbpages<$page){
  71.             return $this->redirectToRoute('app_dictionary',['page'=>$nbpages]);
  72.         } elseif ($page == 0){
  73.             return $this->redirectToRoute('app_dictionary',['page'=>1]);
  74.         }
  75.         $characters $characterRepository->findBy(criteria: [] ,limit10 offset: ($page*10)-10);
  76.         return $this->render('learn/dictionary.html.twig', [
  77.             'characters' => $characters,
  78.             'page'=>$page,
  79.             'nbpages'=>$nbpages,
  80.         ]);
  81.     } # END DICTIONARY VIEW
  82.     #[Route('/learn/dictionary/course/{course}/page/{page}'name'app_course'requirements: ['page'=>'\d+'], defaults:['page'=>1], priority2)]
  83.     public function course(CharacterRepository $characterRepositoryint $pagestring $course): Response
  84.     {
  85.         $nbpages ceil($characterRepository->count(criteria: ["course"=> $course]) / 10);
  86.         if ($nbpages<$page){
  87.             return $this->redirectToRoute('app_course',['page'=>$nbpages,'course'=>$course]);
  88.         } elseif ($page == 0){
  89.             return $this->redirectToRoute('app_course',['page'=>1,'course'=>$course]);
  90.         }
  91.         $characters $characterRepository->findBy(criteria: ["course"=> $course], orderBy: ["placeInCourse" => "ASC"], limit10offset: ($page*10)-10);
  92.         return $this->render('learn/dictionary.html.twig', [
  93.             'characters' => $characters,
  94.             'page'=>$page,
  95.             'nbpages'=>$nbpages,
  96.             'course'=>$course,
  97.         ]);
  98.     } # END COURSE
  99.     #[Route('/learn/course/{course}/page/{page}'name'app_course_view')]
  100.     public function courseView(CourseRepository $courseRepositoryCharacterRepository $characterRepositoryint $pagestring $course): Response
  101.     {
  102.         if(!$course){
  103.             return $this->redirectToRoute('app_course_view',['page'=>1,'course'=>"01"]);
  104.         }
  105.         $courseObject $courseRepository->find($course);
  106.         if (!$courseObject->getTitle()){
  107.             return $this->redirectToRoute('app_course_view',['page'=>1,'course'=>"01"]);
  108.         }
  109.         if (!$page){
  110.             return $this->redirectToRoute('app_course_view',['page'=>1,'course'=>"$course"]);
  111.         }
  112.         $nbpage sizeof(array_values(array_diff(scandir($this->pictureCharRoute $courseObject->getTitle() . "_png"),[".","..",".DS_Store"])));
  113.         if($page>$nbpage) {
  114.             return $this->redirectToRoute('app_course_view', ['page' => $nbpage'course' => $course]);
  115.         }
  116.         $character $characterRepository->findBy(["course" => $course"placeInCourse" => $page ]);
  117.         if ($character){
  118.             $character $character[0];
  119.         } else {
  120.             $character null;
  121.         }
  122.         //dd($character);
  123.         return $this->render('learn/courseView.html.twig', [
  124.             'numberOfPagesAvailable' => $nbpage,
  125.             'course'=>$courseObject,
  126.             'numberOfPage'=>$page,
  127.             'character'=>$character,
  128.         ]);
  129.     } # END COURSE VIEW
  130.     #[Route('/keyboard-policy'name'keyboardPolicy')]
  131.     public function keyboard_policy(): Response
  132.     {
  133.         return $this->render('default/keyboardCGU.html.twig', [
  134.         ]);
  135.     }
  136.     #[Route('/information'name'app_information')]
  137.     public function information(): Response
  138.     {
  139.         return $this->render('default/information.html.twig', [
  140.         ]);
  141.     }
  142. }