File: /var/www/dvpis2025/dvpis.kaunokolegija.lt/src/Controller/YearInformationController.php
<?php
namespace App\Controller;
use Doctrine\DBAL\Exception;
use Doctrine\ORM\EntityManagerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use App\Entity\YearInformation;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Form;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
/**
* Yearinformation controller.
*
* @Security("is_granted('ROLE_STUDY_DEPARTMENT')")
*/
#[Route(path: 'yearinformation')]
class YearInformationController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $em,
) {
}
/**
* Lists all yearInformation entities.
*
* @Method("GET")
*/
#[Route(path: '/', name: 'yearinformation_index')]
public function indexAction()
{
$yearInformations = $this->em->getRepository(YearInformation::class)->findAll();
return $this->render('yearinformation/index.html.twig', array(
'yearInformations' => $yearInformations,
));
}
/**
* Creates a new yearInformation entity.
*
* @Method({"GET", "POST"})
*/
#[Route(path: '/new', name: 'yearinformation_new')]
public function newAction(Request $request)
{
$yearInformation = new Yearinformation();
$form = $this->createForm('App\Form\YearInformationType', $yearInformation);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->em->persist($yearInformation);
$this->em->flush();
return $this->redirectToRoute('yearinformation_index', array('id' => $yearInformation->getId()));
}
return $this->render('yearinformation/new.html.twig', array(
'yearInformation' => $yearInformation,
'form' => $form->createView(),
));
}
/**
* Displays a form to edit an existing yearInformation entity.
*
* @Method({"GET", "POST"})
*/
#[Route(path: '/{id}/edit', name: 'yearinformation_edit')]
public function editAction(Request $request, YearInformation $yearInformation)
{
$deleteForm = $this->createDeleteForm($yearInformation);
$editForm = $this->createForm('App\Form\YearInformationType', $yearInformation);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$this->em->flush();
return $this->redirectToRoute('yearinformation_edit', array('id' => $yearInformation->getId()));
}
return $this->render('yearinformation/edit.html.twig', array(
'yearInformation' => $yearInformation,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
/**
* Deletes a yearInformation entity.
*
* @Method("DELETE")
*/
#[Route(path: '/{id}', requirements: ['id' => '\d+'], name: 'yearinformation_delete')]
public function deleteAction(Request $request, YearInformation $yearInformation)
{
$form = $this->createDeleteForm($yearInformation);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->em->remove($yearInformation);
try {
$this->em->flush();
} catch (Exception $ex) {
$this->addFlash('warning', "Ištrinti įrašo nepavyko! Jis gali turėti susijusių įrašų." . $ex->getMessage());
}
}
return $this->redirectToRoute('yearinformation_index');
}
/**
* Creates a form to delete a yearInformation entity.
*
* @param YearInformation $yearInformation The yearInformation entity
*
* @return Form The form
*/
private function createDeleteForm(YearInformation $yearInformation)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('yearinformation_delete', array('id' => $yearInformation->getId())))
->setMethod('DELETE')
->getForm();
}
}