<commit_before><?php

namespace Pixelbonus\SiteBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use JMS\SecurityExtraBundle\Annotation\Secure;
use Symfony\Component\HttpFoundation\RedirectResponse;

use Pixelbonus\SiteBundle\Entity\Course;
use Pixelbonus\SiteBundle\Form\Type\CourseType;

class CourseController extends Controller {
    /**
     * @Route("/courses", name="courses")
     * @Secure(roles="ROLE_USER")
     */
    public function coursesAction() {
        $user = $this->container->get('security.context')->getToken()->getUser();
        if($user->getCourses()->count() > 0) {
            return $this->render('PixelbonusSiteBundle:Courses:courses.html.twig', array(
                'courses' => $user->getCourses(),
            ));
        } else {
            $course = new Course();
            $course->setUser($user);
            $form = $this->createForm(new CourseType(), $course,  array());
            return $this->render('PixelbonusSiteBundle:Courses:no_courses.html.twig', array(
                'form' => $form->createView(),
            ));
        }
    }

    /**
     * @Route("/courses_new", name="new_course")
     * @Secure(roles="ROLE_USER")
     */
    public function newCourseAction() {
        $user = $this->container->get('security.context')->getToken()->getUser();
        $course = new Course();
        $course->setUser($user);
        $form = $this->createForm(new CourseType(), $course,  array());
        if ('POST' == $this->getRequest()->getMethod()) {
            // parameter handling
            $form->bind($this->getRequest());

            if(!$this->getRequest()->request->has($form->getName())) {
                echo 'No form fields specified'; die();
            } else if($form->isValid()) {
                $this->container->get('doctrine')->getManager()->persist($course);
                $this->container->get('doctrine')->getManager()->flush($course);

                if($this->getRequest()->request->has('_submit_another')) {
                    return new RedirectResponse($this->container->get('router')->generate('new_course'));
                } else {
                    return new RedirectResponse($this->container->get('router')->generate('courses'));
                }
            }
        }
        return $this->render('PixelbonusSiteBundle:Courses:new.html.twig', array(
            'form' => $form->createView(),
        ));
    }

    /**
     * @Route("/qrset/{course}/delete", name="delete_course")
     * @Secure(roles="ROLE_USER")
     */
    public function deleteCourse(Course $course) {
        $course = $course->getCourse()->getId();
        $this->container->get('doctrine')->getManager()->remove($course);
        $this->container->get('doctrine')->getManager()->flush($course);
        return new RedirectResponse($this->container->get('router')->generate('courses'));
    }
}<commit_msg>Deletion bug fix<commit_after><?php

namespace Pixelbonus\SiteBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use JMS\SecurityExtraBundle\Annotation\Secure;
use Symfony\Component\HttpFoundation\RedirectResponse;

use Pixelbonus\SiteBundle\Entity\Course;
use Pixelbonus\SiteBundle\Form\Type\CourseType;

class CourseController extends Controller {
    /**
     * @Route("/courses", name="courses")
     * @Secure(roles="ROLE_USER")
     */
    public function coursesAction() {
        $user = $this->container->get('security.context')->getToken()->getUser();
        if($user->getCourses()->count() > 0) {
            return $this->render('PixelbonusSiteBundle:Courses:courses.html.twig', array(
                'courses' => $user->getCourses(),
            ));
        } else {
            $course = new Course();
            $course->setUser($user);
            $form = $this->createForm(new CourseType(), $course,  array());
            return $this->render('PixelbonusSiteBundle:Courses:no_courses.html.twig', array(
                'form' => $form->createView(),
            ));
        }
    }

    /**
     * @Route("/courses_new", name="new_course")
     * @Secure(roles="ROLE_USER")
     */
    public function newCourseAction() {
        $user = $this->container->get('security.context')->getToken()->getUser();
        $course = new Course();
        $course->setUser($user);
        $form = $this->createForm(new CourseType(), $course,  array());
        if ('POST' == $this->getRequest()->getMethod()) {
            // parameter handling
            $form->bind($this->getRequest());

            if(!$this->getRequest()->request->has($form->getName())) {
                echo 'No form fields specified'; die();
            } else if($form->isValid()) {
                $this->container->get('doctrine')->getManager()->persist($course);
                $this->container->get('doctrine')->getManager()->flush($course);

                if($this->getRequest()->request->has('_submit_another')) {
                    return new RedirectResponse($this->container->get('router')->generate('new_course'));
                } else {
                    return new RedirectResponse($this->container->get('router')->generate('courses'));
                }
            }
        }
        return $this->render('PixelbonusSiteBundle:Courses:new.html.twig', array(
            'form' => $form->createView(),
        ));
    }

    /**
     * @Route("/course/{course}/delete", name="delete_course")
     * @Secure(roles="ROLE_USER")
     */
    public function deleteCourse(Course $course) {
        $course = $course->getCourse()->getId();
        $this->container->get('doctrine')->getManager()->remove($course);
        $this->container->get('doctrine')->getManager()->flush($course);
        return new RedirectResponse($this->container->get('router')->generate('courses'));
    }
}
{'fraction_non_alphanumeric': 0.1806864064602961, 'fraction_numerical': 0.00033647375504710633, 'mean_word_length': 2.6902545003103664, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 129, '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': '253805', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1619, 'n_words': 222}