56 lines
1.7 KiB
PHP
56 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Controller\Teamer;
|
|
|
|
use App\Entity\User;
|
|
use App\Repository\AssignmentRepository;
|
|
use Knp\Component\Pager\PaginatorInterface;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
|
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
|
|
|
class IndexController extends AbstractController
|
|
{
|
|
public function __construct(
|
|
private readonly ValidatorInterface $validator,
|
|
private readonly PaginatorInterface $paginator,
|
|
private readonly AssignmentRepository $assignmentRepository
|
|
) {
|
|
}
|
|
|
|
#[Route('/teamer', name: 'app_teamer_index')]
|
|
#[IsGranted('ROLE_TEAMER')]
|
|
public function index(Request $request): Response
|
|
{
|
|
/** @var User $user */
|
|
$user = $this->getUser();
|
|
$teamer = $user->getTeamer();
|
|
|
|
// Validate teamer data to show missing data right away
|
|
$errors = $this->validator->validate($teamer, null, ['profile_preflight']);
|
|
|
|
$query = $this
|
|
->assignmentRepository
|
|
->getListQueryForTeamer($teamer)
|
|
;
|
|
|
|
$pagination = $this->paginator->paginate(
|
|
$query,
|
|
$request->query->getInt('page', 1),
|
|
10,
|
|
[
|
|
'defaultSortFieldName' => 'destination.dateFrom',
|
|
'defaultSortDirection' => 'asc',
|
|
]
|
|
);
|
|
|
|
return $this->render('teamer/index.html.twig', [
|
|
'teamer' => $teamer,
|
|
'pagination' => $pagination,
|
|
'errors' => $errors,
|
|
]);
|
|
}
|
|
} |