<?php
namespace App\Controller\Front;
use App\Entity\User\User;
use App\Controller\Admin\CoreController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Repository\Configuration\SurveyRepository;
use App\Service\LanguagesManager;
use App\Service\Manager\RequestForm\RequestFormManager;
#[Route('/request')]
class RequestController extends CoreController
{
#[Route('/index/{refSuffix}', name: 'front_request_index')]
public function index($refSuffix,
SurveyRepository $surveyRepository,
Request $request,
LanguagesManager $languagesManager,
RequestFormManager $requestFormManager
): Response
{
$language = $languagesManager->getLanguageUser($request);
$survey = "";
$user = $this->getUser();
$parametres = [
'refSuffix' => $refSuffix,
'deletedAt' => null,
'isEnable' => 1,
'isDisplay' => 1
];
if ($user && (!in_array($user->getRoles(), [User::ROLE_ADMIN]))) {
unset($parametres['isEnable']);
unset($parametres['isDisplay']);
}
$survey = $surveyRepository->getAllQb([
'refSuffix' => $refSuffix,
'fk' => ['survey.label'],
'id_language' => $language->getId()
])->getOneOrNullResult();
$response = $requestFormManager->getForm($survey);
if($response instanceof Response) return $response;
return $this->render('front/request/index.html.twig', (!empty($response['paramsTemplate'])) ? $response['paramsTemplate'] : [] );
}
}