<commit_before><?php

namespace Woe\EventBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

class DefaultController extends Controller
{
    public function indexAction(Request $request)
    {
        $events = $this->getDoctrine()->getManager()
            ->getRepository('WoeEventBundle:Event')
            ->findAll();

        return $this->renderPaginatedEvents($request, $events);
    }

    public function eventAction($id)
    {
        $event = $this->getDoctrine()->getManager()
            ->getRepository('WoeEventBundle:Event')
            ->find($id);

        if (!$event) {
            throw $this->createNotFoundException('Renginys nerastas');
        }

        return $this->render('WoeWebBundle:Body:event.html.twig', array('event' => $event));<commit_msg>Added notification form handling to eventAction<commit_after><?php

namespace Woe\EventBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Woe\EventBundle\Entity\Notification;

class DefaultController extends Controller
{
    public function indexAction(Request $request)
    {
        $events = $this->getDoctrine()->getManager()
            ->getRepository('WoeEventBundle:Event')
            ->findAll();

        return $this->renderPaginatedEvents($request, $events);
    }

    public function eventAction($id, Request $request)
    {
        $em = $this->getDoctrine()->getManager();
        $event = $em->getRepository('WoeEventBundle:Event')->find($id);

        if (!$event) {
            throw $this->createNotFoundException('Renginys nerastas');
        }

        $notification = new Notification();
        $form = $this->createForm('notification', $notification);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $interval = new \DateInterval('P' . $form->get('days')->getData() . 'D');
            $notification_date = $event->getDate()->sub($interval);

            $notification->setDate($notification_date);
            $notification->setEvent($event);
            $em->persist($notification);
            $em->flush();

            $request->getSession()->getFlashBag()->add(
                'success',
                'Priminimas sėkmingai išsaugotas. Jį gausite nurodytu adresu ' . $notification_date->format("Y-m-d H:i")
            );

            return $this->redirect($this->generateUrl('woe_web_event', array('id' => $id)));
        }

        return $this->render('WoeWebBundle:Body:event.html.twig', array(
            'event' => $event,
            'form'  => $form->createView(),
        ));
{'fraction_non_alphanumeric': 0.15003723008190617, 'fraction_numerical': 0.0, 'mean_word_length': 2.844062947067239, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4664844', 'n_tokens_mistral': 745, 'n_tokens_neox': 736, 'n_words': 122}