<?php
namespace App\Controller;
use App\Service\LogsService;
use App\Service\ProjectService;
use App\Service\YouKnowService;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class HomeController extends AbstractController
{
/**
* Retourne la page d'accueil de l'application
*
* @param LogsService $logsService instance du service lié aux Logs
* @param ProjectService $projectService instance du service lié aux projets
* @return Response
*/
#[Route('/', name: 'app_home')]
public function index(LogsService $logsService, ProjectService $projectService, YouKnowService $youKnowService): Response
{
$user = $this->getUser();
$logs = $logsService->getUserLog($user);
$inProgressProjectsCount = $projectService->getInProgressProject($this->getUser());
$inProgressDeliverable = $projectService->getInProgressDeliverable($this->getUser());
$waitingForValidDeliverable = $projectService->getWaitingForValidDeliverables($this->getUser());
if($this->isGranted('ROLE_ADMIN', $user)) {
$inProgressProjectsCount = $projectService->getInProgressProject($this->getUser(), true);
$inProgressDeliverable = $projectService->getInProgressDeliverable($this->getUser(), true);
$waitingForValidDeliverable = $projectService->getWaitingForValidDeliverables($this->getUser(), true);
$logs = $logsService->getUserLog($user, true);
}
if(!empty($youKnowService->getRandomYouKnow())) {
$youKnow = $youKnowService->getRandomYouKnow()->getContent();
} else {
$youKnow = null;
}
return $this->render('home/index.html.twig', [
'user'=>$user,
'logs'=>$logs,
'youKnow'=>$youKnow,
'projectsCount'=>$inProgressProjectsCount,
'deliverablesCount' => $inProgressDeliverable,
'waitingForValidDeliverable' => $waitingForValidDeliverable
]);
}
}