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/Poll/PollGroupController.php
<?php

namespace App\Controller\Poll;

use Doctrine\ORM\EntityManagerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use App\Entity\Poll\PollGroup;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\Form;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Request;

/**
 * Pollgroup controller.
 */
#[Route(path: 'poll_pollgroup')]
class PollGroupController extends AbstractController
{
    public function __construct(
        private readonly EntityManagerInterface $em,
    ) {
    }

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


        $pollGroups = $this->em->getRepository(PollGroup::class)->findAll();

        return $this->render('poll/pollgroup/index.html.twig', array(
                    'pollGroups' => $pollGroups,
        ));
    }

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

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

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

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

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

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

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

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

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

        if ($form->isSubmitted() && $form->isValid()) {
            $this->em->remove($pollGroup);
            $this->em->flush();
        }

        return $this->redirectToRoute('poll_pollgroup_index');
    }

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