<commit_before><?php

namespace Project\AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use JMS\SecurityExtraBundle\Annotation\Secure;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Project\AppBundle\Entity\Lesson;
use Symfony\Component\HttpFoundation\Response;
use Project\AppBundle\Form\SpeakerType;
use Project\AppBundle\Form\ModuleType;
use Project\AppBundle\Entity\Speaker;
use Project\AppBundle\Entity\Module;

/**
 * Archive controller.
 *
 * @Route("/agenda")
 */
class AgendaController extends Controller
{
    /**
     * @Secure("ROLE_STUDENT")
     * @Route("/", name="project_app_agenda_index")
     * @Method("GET")
     * @Template("ProjectAppBundle:Agenda:index.html.twig")
     */
    public function indexAction()
    {
        $speakerEntity = new Speaker();
        
        $formSpeaker = $this->createForm(new SpeakerType(), $speakerEntity, array());
        $formSpeaker->add('user', 'entity', array(
            'query_builder' => function($entity) { return $entity->createQueryBuilder('p')->orderBy('p.id', 'ASC'); },
            'property' => 'user',
            'class' => 'ProjectAppBundle:Speaker',
        ));
            
        $moduleEntity = new Module();
        $moduleForm = $this->createForm(new ModuleType(), $moduleEntity, array());
        $moduleForm->add('name', 'entity', array(
            'query_builder' => function($entity) { return $entity->createQueryBuilder('p')->orderBy('p.id', 'ASC'); },
            'property' => 'name',
            'class' => 'ProjectAppBundle:Module',
        ));

        return array('formSpeaker' => $formSpeaker->createView(), 'formModule' => $moduleForm->createView());
    }
    
    /**
     * @Secure("ROLE_SUPER_ADMIN")
     * @Route("/add", name="agenda_add_lesson")
     * @Template()
     * @Method("POST")
     * 
     * @return \Symfony\Component\HttpFoundation\Response (bool)
     */
    public function addAction($data)
    {
        // Change return header as json
        $response = new Response(json_encode(true));
        $response->headers->set('Content-Type', 'application/json');

        // Decode received data
        $data = json_decode($data);

        // Convert retrieve data to DateTime to avoid error
        $startDate = new \DateTime($data->startDate);
        $endDate = new \DateTime($data->endDate);

        // Fill the entity and save it
        $entity = new Lesson();
        
        $em = $this->getDoctrine()->getManager();
        $speakerEntity = $em->getRepository('ProjectAppBundle:Speaker')->find($data->speakerId);
        $moduleEntity = $em->getRepository('ProjectAppBundle:Module')->find($data->moduleId);

        $entity->setName($data->name);
        $entity->setStartDate($startDate);
        $entity->setEndDate($endDate);
        $entity->setTimecard(1);
        $entity->setSpeaker($speakerEntity);
        $entity->setModule($moduleEntity);

        $em->persist($entity);
        $em->flush();

        return $response;
    }


    /**
     * @Secure("ROLE_SUPER_ADMIN")
     * @Route("/delete", name="agenda_delete_lesson")
     * @Template()
     * @Method("POST")
     * 
     * @return \Symfony\Component\HttpFoundation\Response (bool)
     */
    public function deleteAction($id)<commit_msg>Correct roles security<commit_after><?php

namespace Project\AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use JMS\SecurityExtraBundle\Annotation\Secure;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Project\AppBundle\Entity\Lesson;
use Symfony\Component\HttpFoundation\Response;
use Project\AppBundle\Form\SpeakerType;
use Project\AppBundle\Form\ModuleType;
use Project\AppBundle\Entity\Speaker;
use Project\AppBundle\Entity\Module;

/**
 * Archive controller.
 *
 * @Route("/agenda")
 */
class AgendaController extends Controller
{
    /**
     * @Secure({"ROLE_STUDENT", "ROLE_SPEAKER", "ROLE_MANAGER"})
     * @Route("/", name="project_app_agenda_index")
     * @Method("GET")
     * @Template("ProjectAppBundle:Agenda:index.html.twig")
     */
    public function indexAction()
    {
        $speakerEntity = new Speaker();
        
        $formSpeaker = $this->createForm(new SpeakerType(), $speakerEntity, array());
        $formSpeaker->add('user', 'entity', array(
            'query_builder' => function($entity) { return $entity->createQueryBuilder('p')->orderBy('p.id', 'ASC'); },
            'property' => 'user',
            'class' => 'ProjectAppBundle:Speaker',
        ));
            
        $moduleEntity = new Module();
        $moduleForm = $this->createForm(new ModuleType(), $moduleEntity, array());
        $moduleForm->add('name', 'entity', array(
            'query_builder' => function($entity) { return $entity->createQueryBuilder('p')->orderBy('p.id', 'ASC'); },
            'property' => 'name',
            'class' => 'ProjectAppBundle:Module',
        ));

        return array('formSpeaker' => $formSpeaker->createView(), 'formModule' => $moduleForm->createView());
    }
    
    /**
     * @Secure("ROLE_MANAGER")
     * @Route("/add", name="agenda_add_lesson")
     * @Template()
     * @Method("POST")
     * 
     * @return \Symfony\Component\HttpFoundation\Response (bool)
     */
    public function addAction($data)
    {
        // Change return header as json
        $response = new Response(json_encode(true));
        $response->headers->set('Content-Type', 'application/json');

        // Decode received data
        $data = json_decode($data);

        // Convert retrieve data to DateTime to avoid error
        $startDate = new \DateTime($data->startDate);
        $endDate = new \DateTime($data->endDate);

        // Fill the entity and save it
        $entity = new Lesson();
        
        $em = $this->getDoctrine()->getManager();
        $speakerEntity = $em->getRepository('ProjectAppBundle:Speaker')->find($data->speakerId);
        $moduleEntity = $em->getRepository('ProjectAppBundle:Module')->find($data->moduleId);

        $entity->setName($data->name);
        $entity->setStartDate($startDate);
        $entity->setEndDate($endDate);
        $entity->setTimecard(1);
        $entity->setSpeaker($speakerEntity);
        $entity->setModule($moduleEntity);

        $em->persist($entity);
        $em->flush();

        return $response;
    }


    /**
     * @Secure("ROLE_MANAGER")
     * @Route("/delete", name="agenda_delete_lesson")
     * @Template()
     * @Method("POST")
     * 
     * @return \Symfony\Component\HttpFoundation\Response (bool)
     */
    public function deleteAction($id)
{'fraction_non_alphanumeric': 0.1601750547045952, 'fraction_numerical': 0.00029175784099197665, 'mean_word_length': 3.0785246876859014, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 81, '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': '7146025', 'n_tokens_mistral': 2010, 'n_tokens_neox': 1980, 'n_words': 325}