File: /var/www/dvpis2026/dvpis.kaunokolegija.lt/src/Controller/FinalEgzamController.php
<?php
namespace App\Controller;
use App\Entity\Lecturer;
use Doctrine\DBAL\Exception;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use App\Entity\StudentCountProgramPlan;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use App\Entity\FinalEgzam;
use App\Entity\StudiesProgramPlan;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Form;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use App\Service\ProcessDatesValidation;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Doctrine\ORM\EntityManagerInterface;
/**
* Finalegzam controller.
* @Security("is_granted('ROLE_DEPARTMENT_HEAD') or is_granted('ROLE_ACADEMIC_UNIT_PROHEAD')")
*/
#[Route(path: 'finalegzam')]
class FinalEgzamController extends AbstractController
{
private $onlyView = false;
public function __construct(
private readonly ProcessDatesValidation $dateValidator,
private readonly EntityManagerInterface $em,
) {
if (!$this->dateValidator->isActivePlan() && !$this->dateValidator->isActiveProcessPlan()) {
throw new AccessDeniedHttpException("Jūs negalite pasiekti šio turinio");
}
if ($this->dateValidator->isOnlyView()) {
$this->onlyView = true;
}
if ($this->em->getFilters()->isEnabled('department_filter')) {
$this->em->getFilters()->disable('department_filter');
}
if ($this->em->getFilters()->isEnabled('lecturer_filter')) {
$this->em->getFilters()->disable('lecturer_filter');
}
}
/**
* Lists all finalEgzam entities.
*
* @Method("GET")
*/
#[Route(path: '/', name: 'finalegzam_index')]
public function indexAction()
{
throw new AccessDeniedHttpException("Jūs negalite pasiekti šio turinio");
// $finalEgzams = $this->em->getRepository(FinalEgzam::class)->findAll();
//
// return $this->render('finalegzam/index.html.twig', array(
// 'finalEgzams' => $finalEgzams,
// 'studentCount' => $this->em
// ->getRepository(StudentCountProgramPlan::class)
// ->getAllByProgramCourseType(),
// ));
}
/**
* Creates a new finalEgzam entity.
*
* @Method({"GET", "POST"})
*/
#[Route(path: '/new/{id}', name: 'finalegzam_new')]
public function newAction(Request $request, StudiesProgramPlan $studiesProgramPlan)
{
if ($this->onlyView) {
throw new AccessDeniedHttpException("Jūs negalite pasiekti šio turinio");
}
$finalEgzam = new Finalegzam();
$form = $this->createForm('App\Form\FinalEgzamType', $finalEgzam);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$finalEgzam->setStudiesProgramPlan($studiesProgramPlan);
$this->em->persist($finalEgzam);
$this->em->flush();
return $this->redirectToRoute('finalegzam_show', array('id' => $studiesProgramPlan->getId()));
}
return $this->render('finalegzam/new.html.twig', array(
'finalEgzam' => $finalEgzam,
'form' => $form->createView(),
'studiesProgramPlan' => $studiesProgramPlan,
'lecturerData' => json_encode($this->getLecturerData()),
'studentCount' => $this->em
->getRepository(StudentCountProgramPlan::class)
->getAllByProgramCourseType(),
));
}
/**
* Finds and displays a finalEgzam entity.
*
* @Method("GET")
* @param StudiesProgramPlan $studiesProgramPlan
* @return Response|null
*/
#[Route(path: '/{id}', requirements: ['id' => '\d+'], name: 'finalegzam_show')]
public function showAction(StudiesProgramPlan $studiesProgramPlan)
{
return $this->render('finalegzam/show.html.twig', array(
'studiesProgramPlan' => $studiesProgramPlan,
'isOnlyView' => $this->onlyView,
'studentCount' => $this->em
->getRepository(StudentCountProgramPlan::class)
->getAllByProgramCourseType(),
));
}
/**
* Displays a form to edit an existing finalEgzam entity.
*
* @Method({"GET", "POST"})
*/
#[Route(path: '/{id}/edit', name: 'finalegzam_edit')]
public function editAction(Request $request, FinalEgzam $finalEgzam)
{
if ($this->onlyView) {
throw new AccessDeniedHttpException("Jūs negalite pasiekti šio turinio");
}
$studiesProgramPlan = $finalEgzam->getStudiesProgramPlan();
$deleteForm = $this->createDeleteForm($finalEgzam);
$editForm = $this->createForm('App\Form\FinalEgzamType', $finalEgzam);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$finalEgzam->setStudiesProgramPlan($studiesProgramPlan);
$this->em->flush();
return $this->redirectToRoute('finalegzam_edit', array('id' => $finalEgzam->getId()));
}
return $this->render('finalegzam/edit.html.twig', array(
'studiesProgramPlan' => $studiesProgramPlan,
'finalEgzam' => $finalEgzam,
'form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
'lecturerData' => json_encode($this->getLecturerData()),
'studentCount' => $this->em
->getRepository(StudentCountProgramPlan::class)
->getAllByProgramCourseType(),
));
}
/**
* Deletes a finalEgzam entity.
*
* @Method("DELETE")
*/
#[Route(path: '/{id}', requirements: ['id' => '\d+'], name: 'finalegzam_delete')]
public function deleteAction(Request $request, FinalEgzam $finalEgzam)
{
if ($this->onlyView) {
throw new AccessDeniedHttpException("Jūs negalite pasiekti šio turinio");
}
$form = $this->createDeleteForm($finalEgzam);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->em->remove($finalEgzam);
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('egzamcommissionspp_index');
}
/**
* Creates a form to delete a finalEgzam entity.
*
* @param FinalEgzam $finalEgzam The finalEgzam entity
*
* @return Form The form
*/
private function createDeleteForm(FinalEgzam $finalEgzam)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('finalegzam_delete', array('id' => $finalEgzam->getId())))
->setMethod('DELETE')
->getForm()
;
}
private function getLecturerData()
{
$lecturerRepo = $this->em->getRepository(Lecturer::class);
$lecturersData = $lecturerRepo->findAll();
$lecturerDepPos = [];
foreach ($lecturersData as $lecturerData) {
$lecturerDepPos[$lecturerData->getId()]['position'] = $lecturerData->getLecturerPosition()?->getId();
$lecturerDepPos[$lecturerData->getId()]['department'] = $lecturerData->getDepartment()->getId();
$lecturerDepPos[$lecturerData->getId()]['isNotFullTime'] = $lecturerData->getIsNotFullTime();
}
return $lecturerDepPos;
}
}