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/dvpis2026/dvpis.kaunokolegija.lt/src/Controller/LecturerWorkTimePlanController.php
<?php

namespace App\Controller;

use Doctrine\DBAL\Exception;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use App\Entity\LecturerWorkTimePlan;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Form;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use App\Service\ProcessDatesValidation;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
use Doctrine\ORM\EntityManagerInterface;
use App\Service\DbDataFilter;

/**
* Lecturerworktimeplan controller.
*
* @Security("is_granted('ROLE_LECTURER')
  or is_granted('ROLE_DEPARTMENT_ADMINISTRATOR')
  or is_granted('ROLE_DEPARTMENT_HEAD')
  or is_granted('ROLE_ACADEMIC_UNIT_PROHEAD')
  or is_granted('ROLE_PERSONAL_DEPARTMENT')
 ")
*/
#[Route(path: 'lecturerworktimeplan')]
class LecturerWorkTimePlanController extends AbstractController
{
    public function __construct(
        private readonly ProcessDatesValidation $dateValidator,
        private readonly EntityManagerInterface $em,
        private readonly DbDataFilter $dbDataFilter,
        private readonly AuthorizationCheckerInterface $authorizationChecker,
    ) {

        if (!$this->dateValidator->isActiveLecturerWorkTime()) {
            throw new AccessDeniedHttpException("Jūs negalite pasiekti šio turinio");
        }


        if ($this->authorizationChecker->isGranted('ROLE_PERSONAL_DEPARTMENT')) {
            return;
        }
        if ($this->authorizationChecker->isGranted('ROLE_ACADEMIC_UNIT_PROHEAD')) {
            $this->dbDataFilter->enableOnlyAcademicUnitFilter();
            return;
        }

        if ($this->authorizationChecker->isGranted('ROLE_DEPARTMENT_ADMINISTRATOR') || $this->authorizationChecker->isGranted('ROLE_DEPARTMENT_HEAD')) {
            $this->dbDataFilter->enableOnlyDepartmentFilter();
            return;
        }

        if ($this->authorizationChecker->isGranted('ROLE_LECTURER')) {
            $this->dbDataFilter->enableOnlyLecturerFilter();
            return;
        }

        throw new AccessDeniedHttpException("Jūsų naudotojas negali pasiekti šio turinio");
    }

    /**
     * Lists all lecturerWorkTimePlan entities.
     *
     * @Method("GET")
     */
    #[Route(path: '/', name: 'lecturerworktimeplan_index')]
    public function indexAction()
    {


        $lecturerWorkTimePlans = $this->em->getRepository(LecturerWorkTimePlan::class)->findAll();

        return $this->render('lecturerworktimeplan/index.html.twig', array(
            'lecturerWorkTimePlans' => $lecturerWorkTimePlans,
        ));
    }

    /**
     * Creates a new lecturerWorkTimePlan entity.
     *
     * @Method({"GET", "POST"})
     */
    #[Route(path: '/new', name: 'lecturerworktimeplan_new')]
    public function newAction(Request $request)
    {
        $lecturerWorkTimePlan = new Lecturerworktimeplan();
        $form = $this->createForm('App\Form\LecturerWorkTimePlanType', $lecturerWorkTimePlan);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $this->em->persist($lecturerWorkTimePlan);
            $this->em->flush();

            return $this->redirectToRoute('lecturerworktimeplan_index', array('id' => $lecturerWorkTimePlan->getId()));
        }

        return $this->render('lecturerworktimeplan/new.html.twig', array(
            'lecturerWorkTimePlan' => $lecturerWorkTimePlan,
            'form' => $form->createView(),
        ));
    }

    /**
     * Displays a form to edit an existing lecturerWorkTimePlan entity.
     *
     * @Method({"GET", "POST"})
     */
    #[Route(path: '/{id}/edit', name: 'lecturerworktimeplan_edit')]
    public function editAction(Request $request, LecturerWorkTimePlan $lecturerWorkTimePlan)
    {
        $deleteForm = $this->createDeleteForm($lecturerWorkTimePlan);
        $editForm = $this->createForm('App\Form\LecturerWorkTimePlanType', $lecturerWorkTimePlan);
        $editForm->handleRequest($request);

        if ($editForm->isSubmitted() && $editForm->isValid()) {
            $this->em->flush();

            return $this->redirectToRoute('lecturerworktimeplan_edit', array('id' => $lecturerWorkTimePlan->getId()));
        }

        return $this->render('lecturerworktimeplan/edit.html.twig', array(
            'lecturerWorkTimePlan' => $lecturerWorkTimePlan,
            'edit_form' => $editForm->createView(),
            'delete_form' => $deleteForm->createView(),
        ));
    }

    /**
     * Deletes a lecturerWorkTimePlan entity.
     *
     * @Method("DELETE")
     */
    #[Route(path: '/{id}', requirements: ['id' => '\d+'], name: 'lecturerworktimeplan_delete')]
    public function deleteAction(Request $request, LecturerWorkTimePlan $lecturerWorkTimePlan)
    {
        $form = $this->createDeleteForm($lecturerWorkTimePlan);
        $form->handleRequest($request);

        if ($form->isSubmitted() && $form->isValid()) {
            $this->em->remove($lecturerWorkTimePlan);
            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('lecturerworktimeplan_index');
    }

    /**
     * Creates a form to delete a lecturerWorkTimePlan entity.
     *
     * @param LecturerWorkTimePlan $lecturerWorkTimePlan The lecturerWorkTimePlan entity
     *
     * @return Form The form
     */
    private function createDeleteForm(LecturerWorkTimePlan $lecturerWorkTimePlan)
    {
        return $this->createFormBuilder()
            ->setAction($this->generateUrl('lecturerworktimeplan_delete', array('id' => $lecturerWorkTimePlan->getId())))
            ->setMethod('DELETE')
            ->getForm();
    }
}