WIP: Implement teamer dashboard

This commit is contained in:
Björn Fromme
2023-11-12 16:41:28 +01:00
parent f8207b6731
commit 286064c739
12 changed files with 335 additions and 196 deletions
@@ -1,6 +1,6 @@
<?php
namespace App\Controller\Teamer;
namespace App\Controller\Teamer\Assignment;
use App\Controller\Traits\ReturnUrlTrait;
use App\Entity\Assignment;
@@ -13,7 +13,7 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
class AssignmentController extends AbstractController
class DetailController extends AbstractController
{
use ReturnUrlTrait;
@@ -23,7 +23,7 @@ class AssignmentController extends AbstractController
) {
}
#[Route('/teamer/assignment/{uuid}', name: 'app_teamer_assignment')]
#[Route('/teamer/assignment/{uuid}', name: 'app_teamer_assignment_detail')]
#[IsGranted('ROLE_TEAMER')]
public function index(Assignment $assignment, Request $request): Response
{
@@ -49,7 +49,7 @@ class AssignmentController extends AbstractController
$isBookmarked = $teamer->getBookmarks()->contains($assignment);
return $this->render('teamer/assignment/index.html.twig', [
return $this->render('teamer/assignment/detail.html.twig', [
'teamer' => $teamer,
'assignment' => $assignment,
'disposition' => $disposition,
@@ -0,0 +1,61 @@
<?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\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 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),
10,
[
'defaultSortFieldName' => 'destination.dateFrom',
'defaultSortDirection' => 'asc',
]
);
return $this->render('teamer/assignment/index.html.twig', [
'teamer' => $teamer,
'errors' => $errors,
'pagination' => $pagination,
'filterDto' => $filterDto,
]);
}
}
+11 -34
View File
@@ -2,60 +2,37 @@
namespace App\Controller\Teamer;
use App\Entity\Assignment;
use App\Entity\User;
use App\Repository\AssignmentRepository;
use App\Service\Common\AssignmentFilterHandler;
use Knp\Component\Pager\PaginatorInterface;
use Doctrine\ORM\EntityManagerInterface;
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 AssignmentFilterHandler $filterHandler,
private readonly PaginatorInterface $paginator,
private readonly AssignmentRepository $assignmentRepository
) {
public function __construct(private readonly EntityManagerInterface $entityManager)
{
}
#[Route('/teamer', name: 'app_teamer_index')]
#[IsGranted('ROLE_TEAMER')]
public function index(Request $request): Response
public function index(): Response
{
/** @var User $user */
$user = $this->getUser();
$teamer = $user->getTeamer();
$availabilities = $teamer->getAllAvailabilities()->toArray();
// 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)
$matchingAssignments = $this
->entityManager
->getRepository(Assignment::class)
->getNewMatchingTeamerProfile($teamer, $availabilities)
;
$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,
'errors' => $errors,
'pagination' => $pagination,
'filterDto' => $filterDto,
'matchingAssignments' => $matchingAssignments,
]);
}
}
+16 -1
View File
@@ -103,7 +103,7 @@ class Teamer implements TimestampableEntityInterface
#[ORM\OneToMany(mappedBy: 'teamer', targetEntity: License::class, cascade: ['remove'])]
private Collection $licenses;
#[ORM\ManyToMany(targetEntity: JobProfile::class, orphanRemoval: true)]
#[ORM\ManyToMany(targetEntity: JobProfile::class)]
private Collection $jobProfiles;
#[ORM\ManyToMany(targetEntity: Assignment::class, inversedBy: 'teamers')]
@@ -439,6 +439,21 @@ class Teamer implements TimestampableEntityInterface
return $this;
}
public function getAllAvailabilities(): Collection
{
$allAvailabilities = new ArrayCollection();
foreach ($this->getAvailabilities() as $availability) {
$allAvailabilities->add($availability);
}
foreach ($this->getCustomAvailabilities() as $availability) {
$allAvailabilities->add($availability);
}
return $allAvailabilities;
}
public function getPhoto(): ?Upload
{
return $this->photo;
+7 -2
View File
@@ -11,12 +11,17 @@ class TeamerMenuBuilder extends AbstractMenuBuilder
$menuItems = [
[
'route' => 'app_teamer_index',
'title' => 'Dashboard',
'icon' => 'chart',
],
[
'route' => 'app_teamer_assignment_index',
'title' => 'Einsatzübersicht',
'icon' => 'calendar',
'hideChildren' => true,
'children' => [
[
'route' => 'app_teamer_assignment',
'route' => 'app_teamer_assignment_detail',
'title' => 'Einsatzdetails',
'routeParameters' => $this->getDefaultRouteParameters('uuid'),
]
@@ -51,7 +56,7 @@ class TeamerMenuBuilder extends AbstractMenuBuilder
'title' => 'Merkliste',
'children' => [
[
'route' => 'app_teamer_assignment',
'route' => 'app_teamer_assignment_detail',
'title' => 'Einsatzdetails',
'routeParameters' => $this->getDefaultRouteParameters('uuid'),
]
+32
View File
@@ -202,4 +202,36 @@ class AssignmentRepository extends ServiceEntityRepository
->getResult()
;
}
public function getNewMatchingTeamerProfile(Teamer $teamer, array $availabilities, int $limit = 5): array
{
$qb = $this->createQueryBuilder('assignment');
$qb
->select('assignment', 'destination', 'job_profile')
->innerJoin('assignment.destination', 'destination')
->innerJoin('assignment.jobProfile', 'job_profile')
->leftJoin('assignment.applications', 'application', Join::WITH, $qb->expr()->neq('application.teamer', ':teamer'))
->where($qb->expr()->andX(
$qb->expr()->in('assignment.jobProfile', ':jobProfiles'),
$qb->expr()->isNull('application')
))
->setParameter('jobProfiles', $teamer->getJobProfiles())
->setParameter('teamer', $teamer)
;
foreach ($availabilities as $availability) {
$qb->orWhere($qb->expr()->andX(
$qb->expr()->eq('assignment.dateFrom', ':dateFrom'),
$qb->expr()->eq('assignment.dateTo', ':dateTo')
));
}
return $qb
->orderBy('assignment.createdAt', 'DESC')
->setMaxResults($limit)
->getQuery()
->getResult()
;
}
}