<?php
namespace App\Controller;
use App\Entity\Project;
use App\Entity\Task;
use App\Entity\User;
use App\Entity\UserPro;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class HomeController extends AbstractController
{
#[Route('/', name: 'home')]
public function index(): Response
{
/** @var User $user */
$user = $this->getUser();
$myTasks = $user->getTasksAssigne()->filter(function (Task $task){
return $task->getStatus()!= Task::STATUS_DONE;
});
$projets = null;
$tma= null;
if($user->hasRole(User::ROLE_CLIENT)){
$projets = $user->getUserPros();
/** @var Project $firstProject */
$firstProject = $user->getUserPros()->first()->getProject();
$tma = $firstProject->getTMAs()->last();
}
return $this->render('home/index.html.twig', [
'myTasks' =>$myTasks,
'myProject'=> $projets && $projets->first() ? $projets->first()->getProject() : null,
'tma' => $tma
]);
}
}