File: /var/www/dvpis2026/dvpis.kaunokolegija.lt/src/Controller/LecturerAgreementTypeController.php
<?php
namespace App\Controller;
use App\Entity\LecturerAgreementType;
use App\Form\LecturerAgreementTypeType;
use App\Repository\LecturerAgreementTypeRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
#[Route('/lecturer/agreement/type')]
final class LecturerAgreementTypeController extends AbstractController
{
#[Route(name: 'app_lecturer_agreement_type_index', methods: ['GET'])]
public function index(LecturerAgreementTypeRepository $lecturerAgreementTypeRepository): Response
{
return $this->render('lecturer_agreement_type/index.html.twig', [
'lecturer_agreement_types' => $lecturerAgreementTypeRepository->findAll(),
]);
}
#[Route('/new', name: 'app_lecturer_agreement_type_new', methods: ['GET', 'POST'])]
public function new(Request $request, EntityManagerInterface $entityManager): Response
{
$lecturerAgreementType = new LecturerAgreementType();
$form = $this->createForm(LecturerAgreementTypeType::class, $lecturerAgreementType);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($lecturerAgreementType);
$entityManager->flush();
return $this->redirectToRoute('app_lecturer_agreement_type_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('lecturer_agreement_type/new.html.twig', [
'lecturer_agreement_type' => $lecturerAgreementType,
'form' => $form,
]);
}
#[Route('/{id}/edit', name: 'app_lecturer_agreement_type_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, LecturerAgreementType $lecturerAgreementType, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(LecturerAgreementTypeType::class, $lecturerAgreementType);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();
return $this->redirectToRoute('app_lecturer_agreement_type_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('lecturer_agreement_type/edit.html.twig', [
'lecturer_agreement_type' => $lecturerAgreementType,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_lecturer_agreement_type_delete', methods: ['POST'])]
public function delete(Request $request, LecturerAgreementType $lecturerAgreementType, EntityManagerInterface $entityManager): Response
{
if ($this->isCsrfTokenValid('delete'.$lecturerAgreementType->getId(), $request->getPayload()->getString('_token'))) {
$entityManager->remove($lecturerAgreementType);
$entityManager->flush();
}
return $this->redirectToRoute('app_lecturer_agreement_type_index', [], Response::HTTP_SEE_OTHER);
}
}