src/Controller/DefaultController.php line 29
<?php
namespace App\Controller;
use App\Repository\CharacterRepository;
use App\Repository\CourseRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class DefaultController extends AbstractController
{
private $projectDir;
private $publicDir;
private $dataCharRoute;
private $pictureCharRoute;
public function __construct(string $projectDir, string $publicDir, string $dataCharRoute, string $pictureCharRoute){
$this->projectDir=$projectDir;
$this->publicDir=$publicDir;
$this->dataCharRoute=$dataCharRoute;
$this->pictureCharRoute=$pictureCharRoute;
}
#[Route('/', name: 'homepage')]
public function index(): Response
{
return $this->render('default/index.html.twig', [
'controller_name' => 'DefaultController',
]);
} # END DEFAULT
#[Route('/menu', name: 'app_menu')]
public function menu(): Response
{
return $this->render('default/menu.html.twig', [
]);
}
#[Route('/game-policy', name: 'gamePolicy')]
public function policy(): Response
{
return $this->render('default/confidantialPolicy.html.twig', [
]);
} # END MENU
#[Route('/learn', name: 'app_learn')]
public function learn(CourseRepository $courseRepository): Response
{
$courses = $courseRepository->findAll();
return $this->render('learn/learn.html.twig', [
'courses' => $courses,
]);
} # END LEARN
#[Route('/open-source', name: 'app_open-source')]
public function openSource(): Response
{
return $this->render('default/open-source.html.twig', [
]);
}
#[Route('/multilinguisme', name: 'app_multilinguisme')]
public function multilinguisme(): Response
{
return $this->render('default/multilinguisme.html.twig', [
]);
}
#[Route('/game-policy', name: 'app_game-policy')]
public function game_policy(): Response
{
return $this->render('default/confidantialPolicy.html.twig', [
]);
}
#[Route('/learn/dictionary/page/{page}', name: 'app_dictionary', requirements: ['page'=>'\d+'], defaults:['page'=>1], priority: 3)]
public function dictionary(CharacterRepository $characterRepository, int $page): Response
{
$nbpages = ceil($characterRepository->count(criteria: []) / 10);
if ($nbpages<$page){
return $this->redirectToRoute('app_dictionary',['page'=>$nbpages]);
} elseif ($page == 0){
return $this->redirectToRoute('app_dictionary',['page'=>1]);
}
$characters = $characterRepository->findBy(criteria: [] ,limit: 10 , offset: ($page*10)-10);
return $this->render('learn/dictionary.html.twig', [
'characters' => $characters,
'page'=>$page,
'nbpages'=>$nbpages,
]);
} # END DICTIONARY VIEW
#[Route('/learn/dictionary/course/{course}/page/{page}', name: 'app_course', requirements: ['page'=>'\d+'], defaults:['page'=>1], priority: 2)]
public function course(CharacterRepository $characterRepository, int $page, string $course): Response
{
$nbpages = ceil($characterRepository->count(criteria: ["course"=> $course]) / 10);
if ($nbpages<$page){
return $this->redirectToRoute('app_course',['page'=>$nbpages,'course'=>$course]);
} elseif ($page == 0){
return $this->redirectToRoute('app_course',['page'=>1,'course'=>$course]);
}
$characters = $characterRepository->findBy(criteria: ["course"=> $course], orderBy: ["placeInCourse" => "ASC"], limit: 10, offset: ($page*10)-10);
return $this->render('learn/dictionary.html.twig', [
'characters' => $characters,
'page'=>$page,
'nbpages'=>$nbpages,
'course'=>$course,
]);
} # END COURSE
#[Route('/learn/course/{course}/page/{page}', name: 'app_course_view')]
public function courseView(CourseRepository $courseRepository, CharacterRepository $characterRepository, int $page, string $course): Response
{
if(!$course){
return $this->redirectToRoute('app_course_view',['page'=>1,'course'=>"01"]);
}
$courseObject = $courseRepository->find($course);
if (!$courseObject->getTitle()){
return $this->redirectToRoute('app_course_view',['page'=>1,'course'=>"01"]);
}
if (!$page){
return $this->redirectToRoute('app_course_view',['page'=>1,'course'=>"$course"]);
}
$nbpage = sizeof(array_values(array_diff(scandir($this->pictureCharRoute . $courseObject->getTitle() . "_png"),[".","..",".DS_Store"])));
if($page>$nbpage) {
return $this->redirectToRoute('app_course_view', ['page' => $nbpage, 'course' => $course]);
}
$character = $characterRepository->findBy(["course" => $course, "placeInCourse" => $page ]);
if ($character){
$character = $character[0];
} else {
$character = null;
}
//dd($character);
return $this->render('learn/courseView.html.twig', [
'numberOfPagesAvailable' => $nbpage,
'course'=>$courseObject,
'numberOfPage'=>$page,
'character'=>$character,
]);
} # END COURSE VIEW
#[Route('/keyboard-policy', name: 'keyboardPolicy')]
public function keyboard_policy(): Response
{
return $this->render('default/keyboardCGU.html.twig', [
]);
}
#[Route('/information', name: 'app_information')]
public function information(): Response
{
return $this->render('default/information.html.twig', [
]);
}
}