<?php
namespace App\Controller;
use App\Entity\Post;
use App\Entity\Role;
use App\Entity\User;
use App\Entity\Media;
use App\Entity\Cabinet;
use App\Entity\Service;
use App\Entity\Category;
use App\Entity\Direction;
use App\Entity\OldMinistre;
use App\Form\RegistrationType;
use App\Form\RegistrationFrontType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\Common\Persistence\ObjectManager;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
class FrontController extends AbstractController
{
/**
* @Route("/old", name="front")
*/
public function index()
{
$repository = $this->getDoctrine()->getRepository(Post::class);
$posts = $repository->findPostByCategorieLimit('Informations',5);
$slides = $repository->findPostByCategorieLimit('Slides',3);
$latest= $repository->findBylast();
//dd($slides);
return $this->render('front/index.html.twig', [
'controller_name' => 'FrontController',
'posts' => $posts,
'slides' => $slides,
'latest' => $latest,
]);
}
/**
* @Route("/", name="newfront")
*/
public function indexnew()
{
$repository = $this->getDoctrine()->getRepository(Post::class);
$posts = $repository->findPostByCategorieLimit('Informations',5);
$slides = $repository->findPostByCategorieLimit('Slides',3);
$latest= $repository->findBylast();
//dd($slides);
return $this->render('newwebfront/index.html.twig', [
'controller_name' => 'FrontController',
'posts' => $posts,
'slides' => $slides,
'latest' => $latest,
]);
}
/**
* @Route("/accueil/blog", name="blog")
*/
public function blog()
{
return $this->render('front/blog.html.twig', [
'controller_name' => 'FrontController',
]);
}
/**
* @Route("/accueil/article", name="article")
*/
public function showarticle()
{
return $this->render('front/article.html.twig', [
'controller_name' => 'FrontController',
]);
}
/**
* @Route("/accueil/service", name="service")
*/
public function showservice()
{
$repository = $this->getDoctrine()->getRepository(Post::class);
$services = $this->getDoctrine()
->getRepository(Service::class)
->findAll();
$latest= $repository->findBylast();
return $this->render('front/service.html.twig', [
'controller_name' => 'FrontController',
'services' => $services,
'latest' => $latest,
]);
}
/**
* @Route("/accueil/prestation", name="prestation")
*/
public function showprestation(Request $request)
{
$page =$request->query->getInt('page',1);
$repository = $this->getDoctrine()->getRepository(Post::class);
$services = $this->getDoctrine()
->getRepository(Service::class)
->findPaginateAllService($page, 10);
$latest= $repository->findBylast();
return $this->render('newwebfront/prestation.html.twig', [
'controller_name' => 'FrontController',
'services' => $services,
'latest' => $latest,
]);
}
/**
* @Route("accueil/direction/{sigle}", name="show_direction", methods={"GET"})
*/
public function directionshow(String $sigle)
{
$repository = $this->getDoctrine()->getRepository(Direction::class);
$repository2 = $this->getDoctrine()->getRepository(Post::class);
$repository3 = $this->getDoctrine()->getRepository(Cabinet::class);
$direction = $repository->findDirectionBySigle($sigle);
$latest= $repository2->findBylast();
$membs=$repository3->findAll();
return $this->render('front/direction.html.twig', [
'direction' => $direction,
'latest' => $latest,
'membs' => $membs,
]);
}
/**
* @Route("accueil/newdirection/{sigle}", name="new_show_direction", methods={"GET"})
*/
public function newdirectionshow(String $sigle)
{
$repository = $this->getDoctrine()->getRepository(Direction::class);
$repository2 = $this->getDoctrine()->getRepository(Post::class);
$repository3 = $this->getDoctrine()->getRepository(Cabinet::class);
$direction = $repository->findDirectionBySigle($sigle);
$latest= $repository2->findBylast();
$membs=$repository3->findAll();
return $this->render('newwebfront/direction.html.twig', [
'direction' => $direction,
'latest' => $latest,
'membs' => $membs,
]);
}
/**
* @Route("accueil/ministere/MINISTERE", name="show_ministere")
*/
public function ministereshow()
{
$repository = $this->getDoctrine()->getRepository(Direction::class);
$repository2 = $this->getDoctrine()->getRepository(Post::class);
$repository3 = $this->getDoctrine()->getRepository(Cabinet::class);
$direction = $repository->findDirectionBySigle("MINISTERE");
$latest= $repository2->findBylast();
$membs=$repository3->findAll();
return $this->render('front/minitere.html.twig', [
'direction' => $direction,
'latest' => $latest,
'membs' => $membs,
]);
}
/**
* @Route("/accueil/ministreold", name="ministre")
*/
public function ministre()
{
$repository = $this->getDoctrine()->getRepository(Cabinet::class);
$repository2 = $this->getDoctrine()->getRepository(Post::class);
$membs=$repository->findAll();
$latest= $repository2->findBylast();
return $this->render('front/ministre.html.twig', [
'controller_name' => 'FrontController',
'membs' => $membs,
'latest' => $latest
]);
}
/**
* @Route("/accueil/ministre", name="new_ministre")
*/
public function ministrenew()
{
$repository = $this->getDoctrine()->getRepository(Cabinet::class);
$repository2 = $this->getDoctrine()->getRepository(Post::class);
$membs=$repository->findAll();
$latest= $repository2->findBylast();
return $this->render('newwebfront/ministre.html.twig', [
'controller_name' => 'FrontController',
'membs' => $membs,
'latest' => $latest
]);
}
/**
* @Route("/accueil/documentheque", name="documentheque")
*/
public function documentheque()
{
$repository2 = $this->getDoctrine()->getRepository(Post::class);
$repository = $this->getDoctrine()->getRepository(Media::class);
$latest= $repository2->findBylast();
$docs=$repository->findByOnline();
return $this->render('front/documentheque.html.twig', [
'controller_name' => 'FrontController',
'latest' => $latest,
'docs' => $docs
]);
}
/**
* Permet d'afficher le formulaire d'inscription
*
* @Route("/front/register", name="front_register")
* @return Response
*/
public function register(Request $request, EntityManagerInterface $manager, UserPasswordEncoderInterface $encoder) {
$user = new User();
$user->setIsActived(false);
// $userRole = new Role();
$userRole=$manager->getRepository('App\Entity\Role')->find(3);
// $userRole1=$userRole->('ROLE_USERFRONT');
// $id=$userRole->getId();
// $id=$manager->getRepository('App\Entity\Role')->findOneBy([
// 'title'=>"ROLE_USERFRONT"
// ]);
// dump($userRole);
// dump($id);die();
// $manager->persist($userRole);
$form = $this->createForm(RegistrationFrontType::class, $user);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid()) {
$hash = $encoder->encodePassword($user, $user->getHash());
$user->setHash($hash);
$user->addUserRole($userRole);
$manager->persist($user);
$manager->flush();
$this->addFlash(
'success',
"Votre compte a bien été créé ! Vous pouvez maintenant vous connecter !"
);
return $this->redirectToRoute('front');
}
return $this->render('account/registration.html.twig', [
'form' => $form->createView()
]);
}
/**
* @Route("/adresse", name="contact")
*/
public function contact()
{
return $this->render('contact/contact.html.twig'
);
}
/**
* @Route("/accueil/anciens-ministres", name="old_ministre")
*/
public function showoldministre(Request $request)
{
$page =$request->query->getInt('page',1);
$repository = $this->getDoctrine()->getRepository(OldMinistre::class);
$old_ministres = $this->getDoctrine()
->getRepository(OldMinistre::class)
->findPaginateAllMinistre($page, 12);
//dd($old_ministres);
return $this->render('newwebfront/ancienministre.html.twig', [
'controller_name' => 'FrontController',
'old_ministres' => $old_ministres,
]);
}
/**
* @Route("/ancien/ministre/{id}", name="show_old_ministre", methods={"GET"})
*/
public function newpostshow(String $id): Response
{
$repository = $this->getDoctrine()->getRepository(OldMinistre::class);
$ministre = $repository->findOneBy([
'id'=>$id
]);
//dd($post);
return $this->render('newwebfront/presentancienministre.html.twig', [
'ministre' => $ministre,
]);
}
}