HEX
Server: Apache
System: Linux WWW 6.1.0-40-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.153-1 (2025-09-20) x86_64
User: web11 (1011)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /var/www/dvpis2025/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);
    }
}