Files
myep-team/src/Controller/Teamer/IndexController.php
T

94 lines
2.8 KiB
PHP

<?php
namespace App\Controller\Teamer;
use App\Entity\Application;
use App\Entity\Assignment;
use App\Entity\Disposition;
use App\Entity\Feedback;
use App\Entity\News;
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
class IndexController extends AbstractController
{
public function __construct(private readonly EntityManagerInterface $entityManager)
{
}
#[Route('/teamer', name: 'app_teamer_index')]
#[IsGranted('ROLE_TEAMER')]
public function index(): Response
{
/** @var User $user */
$user = $this->getUser();
$teamer = $user->getTeamer();
$news = $this
->entityManager
->getRepository(News::class)
->getLatestForDashboard()
;
$matchingAssignments = $this
->entityManager
->getRepository(Assignment::class)
->getNewMatchingTeamerProfile($teamer)
;
$recentFeedback = $this
->entityManager
->getRepository(Feedback::class)
->getRecentForTeamer($teamer)
;
$pendingApplications = $this
->entityManager
->getRepository(Application::class)
->getPendingForTeamer($teamer)
;
$currentDispositions = $this
->entityManager
->getRepository(Disposition::class)
->findCurrentDispositionsByTeamer($teamer)
;
$upcomingDispositions = $this
->entityManager
->getRepository(Disposition::class)
->getUpcomingDispositionsByTeamer($teamer)
;
$dispositionDocuments = $this->processDocuments($upcomingDispositions);
return $this->render('teamer/index.html.twig', [
'news' => $news,
'teamer' => $teamer,
'matchingAssignments' => $matchingAssignments,
'recentFeedback' => $recentFeedback,
'pendingApplications' => $pendingApplications,
'currentDispositions' => $currentDispositions,
'upcomingDispositions' => $upcomingDispositions,
'dispositionDocuments' => $dispositionDocuments,
]);
}
private function processDocuments(array $upcomingDispositions): array
{
$dispositions = [];
foreach ($upcomingDispositions as $disposition) {
/** @var Disposition $disposition */
if ($disposition->isContractDue() || $disposition->isContractRejected() || $disposition->isInvoiceDue()) {
$dispositions[] = $disposition;
}
}
return $dispositions;
}
}