WIP: Implement availabilities
This commit is contained in:
@@ -2,17 +2,59 @@
|
||||
|
||||
namespace App\Controller\Teamer\Profile;
|
||||
|
||||
use App\Entity\Availability;
|
||||
use App\Entity\User;
|
||||
use App\Repository\AvailabilityRepository;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
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;
|
||||
|
||||
class AvailabilitiesController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly AvailabilityRepository $availabilityRepository,
|
||||
private readonly EntityManagerInterface $entityManager
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/teamer/profile/availabilities', name: 'app_teamer_profile_availabilities')]
|
||||
#[IsGranted('ROLE_TEAMER')]
|
||||
public function index(): Response
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
return $this->render('teamer/profile/availabilities.html.twig');
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$teamer = $user->getTeamer();
|
||||
|
||||
$selectableAvailabilities = $this->availabilityRepository->getSelectable($teamer);
|
||||
$form = $this->createFormBuilder($teamer)
|
||||
->add('availabilities', EntityType::class, [
|
||||
'label' => false,
|
||||
'class' => Availability::class,
|
||||
'choice_label' => function($choice) {
|
||||
return sprintf('%s - %s', $choice->getDateFrom()->format('d.m.Y'), $choice->getDateTo()->format('d.m.Y'));
|
||||
},
|
||||
'choices' => $selectableAvailabilities,
|
||||
'multiple' => true,
|
||||
'expanded' => true,
|
||||
])
|
||||
->getForm()
|
||||
;
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $this->redirectToRoute('app_teamer_profile_availabilities');
|
||||
}
|
||||
|
||||
return $this->render('teamer/profile/availabilities.html.twig', [
|
||||
'availabilities' => $teamer->getAvailabilities(),
|
||||
'selectableAvailabilities' => $selectableAvailabilities,
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user