62 lines
2.0 KiB
PHP
62 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Controller\Teamer\Assignment;
|
|
|
|
use App\Entity\User;
|
|
use App\Repository\AssignmentRepository;
|
|
use App\Service\Common\AssignmentFilterHandler;
|
|
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\Attribute\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 AssignmentFilterHandler $filterHandler,
|
|
private readonly PaginatorInterface $paginator,
|
|
private readonly AssignmentRepository $assignmentRepository,
|
|
) {
|
|
}
|
|
|
|
#[Route('/teamer/assignment', name: 'app_teamer_assignment_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']);
|
|
|
|
$filterDto = $this->filterHandler->getFilterSettings();
|
|
|
|
$query = $this
|
|
->assignmentRepository
|
|
->getListQueryForTeamer($teamer, $filterDto)
|
|
;
|
|
|
|
$pagination = $this->paginator->paginate(
|
|
$query,
|
|
$request->query->getInt('page', 1),
|
|
9,
|
|
[
|
|
'defaultSortFieldName' => 'destination.dateFrom',
|
|
'defaultSortDirection' => 'asc',
|
|
]
|
|
);
|
|
|
|
return $this->render('teamer/assignment/index.html.twig', [
|
|
'teamer' => $teamer,
|
|
'errors' => $errors,
|
|
'pagination' => $pagination,
|
|
'filterDto' => $filterDto,
|
|
]);
|
|
}
|
|
}
|