<?php
// src/Controller/AideController.php
namespace App\Controller;
use App\Entity\CategorieArticleAide;
use App\Entity\ArticleAide;
use App\Form\ArticleAideType;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
/**
* @Route("/{_locale}/help")
*/
class AideController extends AbstractController
{
/**
* @Route("/", name="index_aide")
*/
public function indexAction($_locale = '')
{
$em = $this->getDoctrine()->getManager();
$categorieAides = $em->getRepository(CategorieArticleAide::class)
->findByLangue(
array(
'langue' => $_locale
)
);
return $this->render('entreprise/help.html.twig', [
'locale' => $_locale,
'categorieAides' => $categorieAides
]);
}
/**
* @Route("/category/{slug}", name="article_par_categrorie")
*/
public function articleParCategorieAction(CategorieArticleAide $categorieAide)
{
$em = $this->getDoctrine()->getManager();
$articleAides = $em->getRepository(ArticleAide::class)
->findByCategorie(
$categorieAide
);
return $this->render('entreprise/article_help.html.twig', [
'articleAides' => $articleAides,
'categorieAide' => $categorieAide
]);
}
/**
* @Route("/write-article", name="ecrire_un_article")
*/
public function ajouterArticleAction()
{
/*
if(!$this->get('security.context')->isGranted('ROLE_AUTEUR'))
{
throw $this->createNotFoundException('NAU');
}
*/
$em = $this->getDoctrine()->getManager();
$articleAide = new ArticleAide;
$form = $this->createForm(ArticleAideType::class, $articleAide);
$requestStack = $this->get('request_stack');
$requete = $requestStack->getCurrentRequest();
$ok_soumission = '';
$error = '';
if('POST' == $requete->getMethod() )
{
$form->handleRequest($requete);
if($form->isValid()){
$em->persist($articleAide);
$em->flush();
$articleAide = new ArticleAide;
$form = $this->createForm(ArticleAideType::class, $articleAide);
$ok_soumission = 'Enregistrement effectué';
} else{
$error = 'error s\'est produite, veuillez recommencer';
}
}
return $this->render('entreprise/ecrire_article_aide.html.twig', [
'form' => $form->createView(),
'ok_soumission' => $ok_soumission,
'error' => $error
]);
}
/**
* @Route("/read-article/{slug}", name="lire_un_article")
*/
public function lireArticleAction(ArticleAide $article)
{
return $this->render('entreprise/lire_article_aide.html.twig', [
'article' => $article
]);
}
}