<commit_before><?php

namespace TobiasOlry\Talkly\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\EntityManager;

use TobiasOlry\Talkly\Entity\Topic;
use TobiasOlry\Talkly\Form\CreateTopicType;
use TobiasOlry\Talkly\Form\LectureTopicType;

use TobiasOlry\Talkly\Security\Security;

class TopicController
{
    private $formFactory;
    private $urlGenerator;
    private $twig;
    private $security;
    private $topicService;

    public function __construct(
        $topicService,
        $formFactory,
        $urlGenerator,
        \Twig_Environment $twig,
        Security $security
    ) {
        $this->topicService = $topicService;
        $this->formFactory  = $formFactory;
        $this->urlGenerator = $urlGenerator;
        $this->twig         = $twig;
        $this->security     = $security;
    }

    public function createAction(Request $request)
    {
        $topic = new Topic($this->security->getUser());

        $form = $this->formFactory->create(
            new CreateTopicType(),
            $topic
        );

        $form->handleRequest($request);
        $this->topicService->add($topic);

        $request->getSession()->getFlashBag()->add('topic-' . $topic->getId() . '-success', 'topic created');

        return $this->redirect($topic, 'list');
    }

    public function showAction(Request $request)
    {
        $topic = $this->topicService->getTopic($request->get('id'));

        $form = $this->formFactory->create(
            new LectureTopicType(),
            $topic
        );

        return new Response(
            $this->twig->render(
                'topic/show.html.twig',
                [
                    'topic' => $topic,
                    'form'  => $form->createView()
                ]
            )
        );
    }

    public function castVoteAction(Request $request)
    {
        $topic = $this->topicService->getTopic($request->get('id'));
        $voter = $this->security->getUser();

        $this->topicService->addVote($topic, $voter);

        $request->getSession()->getFlashBag()->add('topic-' . $topic->getId() . '-success', 'vote cast');

        return $this->redirect($topic, $request->get('view', 'list'));
    }

    public function retractVoteAction(Request $request)
    {
        $topic = $this->topicService->getTopic($request->get('id'));
        $voter = $this->security->getUser();

        $this->topicService->removeVote($topic, $voter);

        $request->getSession()->getFlashBag()->add('topic-' . $topic->getId() . '-success', 'vote retracted');

        return $this->redirect($topic, $request->get('view', 'list'));
    }

    public function commentAction(Request $request)
    {
        $topic   = $this->topicService->getTopic($request->get('id'));
        $user    = $this->security->getUser();
        $comment = $request->get('comment');

        $this->topicService->comment($topic, $user, $comment);

        $request->getSession()->getFlashBag()->add('topic-' . $topic->getId() . '-success', 'comment added');

        return $this->redirect($topic, $request->get('view', 'show'));
    }

    public function archiveAction(Request $request)
    {
        $topic = $this->topicService->getTopic($request->get('id'), $allowArchived = true);

        $form = $this->formFactory->create(
            new LectureTopicType(),
            $topic
        );

        $form->handleRequest($request);
        $this->topicService->update($topic);

        $request->getSession()->getFlashBag()->add('topic-' . $topic->getId() . '-success', 'lecture updated');

        return $this->redirect($topic, $request->get('view', 'list'));
    }

    public function addSpeakerAction(Request $request)
    {<commit_msg>archive action can only be executed from topic-show<commit_after><?php

namespace TobiasOlry\Talkly\Controller;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\EntityManager;

use TobiasOlry\Talkly\Entity\Topic;
use TobiasOlry\Talkly\Form\CreateTopicType;
use TobiasOlry\Talkly\Form\LectureTopicType;

use TobiasOlry\Talkly\Security\Security;

class TopicController
{
    private $formFactory;
    private $urlGenerator;
    private $twig;
    private $security;
    private $topicService;

    public function __construct(
        $topicService,
        $formFactory,
        $urlGenerator,
        \Twig_Environment $twig,
        Security $security
    ) {
        $this->topicService = $topicService;
        $this->formFactory  = $formFactory;
        $this->urlGenerator = $urlGenerator;
        $this->twig         = $twig;
        $this->security     = $security;
    }

    public function createAction(Request $request)
    {
        $topic = new Topic($this->security->getUser());

        $form = $this->formFactory->create(
            new CreateTopicType(),
            $topic
        );

        $form->handleRequest($request);
        $this->topicService->add($topic);

        $request->getSession()->getFlashBag()->add('topic-' . $topic->getId() . '-success', 'topic created');

        return $this->redirect($topic, 'list');
    }

    public function showAction(Request $request)
    {
        $topic = $this->topicService->getTopic($request->get('id'));

        $form = $this->formFactory->create(
            new LectureTopicType(),
            $topic
        );

        return new Response(
            $this->twig->render(
                'topic/show.html.twig',
                [
                    'topic' => $topic,
                    'form'  => $form->createView()
                ]
            )
        );
    }

    public function castVoteAction(Request $request)
    {
        $topic = $this->topicService->getTopic($request->get('id'));
        $voter = $this->security->getUser();

        $this->topicService->addVote($topic, $voter);

        $request->getSession()->getFlashBag()->add('topic-' . $topic->getId() . '-success', 'vote cast');

        return $this->redirect($topic, $request->get('view', 'list'));
    }

    public function retractVoteAction(Request $request)
    {
        $topic = $this->topicService->getTopic($request->get('id'));
        $voter = $this->security->getUser();

        $this->topicService->removeVote($topic, $voter);

        $request->getSession()->getFlashBag()->add('topic-' . $topic->getId() . '-success', 'vote retracted');

        return $this->redirect($topic, $request->get('view', 'list'));
    }

    public function commentAction(Request $request)
    {
        $topic   = $this->topicService->getTopic($request->get('id'));
        $user    = $this->security->getUser();
        $comment = $request->get('comment');

        $this->topicService->comment($topic, $user, $comment);

        $request->getSession()->getFlashBag()->add('topic-' . $topic->getId() . '-success', 'comment added');

        return $this->redirect($topic, $request->get('view', 'show'));
    }

    public function archiveAction(Request $request)
    {
        $topic = $this->topicService->getTopic($request->get('id'), $allowArchived = true);

        $form = $this->formFactory->create(
            new LectureTopicType(),
            $topic
        );

        $form->handleRequest($request);
        $this->topicService->update($topic);

        $request->getSession()->getFlashBag()->add('topic-' . $topic->getId() . '-success', 'lecture updated');

        return $this->redirect($topic, 'show');
    }

    public function addSpeakerAction(Request $request)
    {
{'fraction_non_alphanumeric': 0.16476471342479804, 'fraction_numerical': 0.0, 'mean_word_length': 2.6161335187760777, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 164, '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': '3133991', 'n_tokens_mistral': 2287, 'n_tokens_neox': 2184, 'n_words': 372}