<commit_before><?php

namespace SPJ\GameBundle\Controller;

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

use SPJ\GameBundle\Entity\Picture;
use SPJ\GameBundle\Form\PictureType;

class PictureController extends Controller
{
    public function createAction(Request $request, $challengeId)
    {
        $user = $this->get('security.context')->getToken()->getUser();
        $challenge = $this->get('challenge_repository')->findOneById($challengeId);
        $picture = new Picture();
        $form = $this->createForm(new PictureType(), $picture, array(
            'action' => $this->generateUrl(
                'picture_create',
                array('challengeId' =>  $challengeId)
            ),
            'method' => 'POST',
        ));
        $form->add('submit', 'submit', array('label' => 'Create'));

        $form->handleRequest($request);

        if ($form->isValid()) {
            $pictureProperties = $this->get('picture_upload')->upload($picture->getFile());
            $picture->setPath($pictureProperties['path']);
            $picture->setMiniaturePath($pictureProperties['miniature_path']);
            $picture->setBlurredMiniaturePath($pictureProperties['blurred_miniature_path']);
            $picture->setDateCreated(new \DateTime());
            $picture->setUser($user);
            $picture->setChallenge($challenge);
            $picture->setExifProperties($pictureProperties['exif']);
            $em = $this->getDoctrine()->getManager();
            $em->persist($picture);
            $em->flush();

            return $this->render('SPJGameBundle:Picture:created.html.twig');
        }

        return $this->render('SPJGameBundle:Picture:create.html.twig', array(
            'picture' => $picture,
            'form'   => $form->createView(),
        ));
    }

    public function challengeListAction($challengeId, $page = 1)
    {
        $challenge = $this->get('challenge_repository')->findOneById($challengeId);
        return $this->render('SPJGameBundle:Picture:' . $challenge->getStatus() . '_challenge_list.html.twig', array(
            'pictures' => $this->get('picture_repository')->findByChallenge($challenge),
            'challenge' => $challenge
        ));
    }

    public function challengeUserShowAction($challengeId)
    {
        $challenge = $this->get('challenge_repository')->findOneById($challengeId);
        $user = $this->get('security.context')->getToken()->getUser();

        if ("" !== $user) {
            $picture = $this->get('picture_repository')->findOneByChallengeAndUser($challenge, $user);
        } else {
            $picture = null;
        }
        $templateName = $challenge->getStatus() === 'inprogress' ? 'SPJGameBundle:Picture:challenge_user_show_inprogress.html.twig' : 'SPJGameBundle:Picture:challenge_user_show.html.twig';
        return $this->render($templateName, array(
            'picture' => $picture,
            'challenge' => $challenge
        ));
    }

    public function showAction($pictureId)
    {
        $picture = $this->get('picture_repository')->findOneById($pictureId);
        $user = $this->get('security.context')->getToken()->getUser();
        return $this->render('SPJGameBundle:Picture:show.html.twig', array(
            'picture' => $picture
        ));
    }
}<commit_msg>did some code arrangements<commit_after><?php

namespace SPJ\GameBundle\Controller;

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

use SPJ\GameBundle\Entity\Picture;
use SPJ\GameBundle\Form\PictureType;

class PictureController extends Controller
{
    public function createAction(Request $request, $challengeId)
    {
        $user = $this->get('security.context')->getToken()->getUser();
        $challenge = $this->get('challenge_repository')->findOneById($challengeId);
        $picture = new Picture();
        $form = $this->createForm(new PictureType(), $picture, array(
            'action' => $this->generateUrl(
                'picture_create',
                array('challengeId' =>  $challengeId)
            ),
            'method' => 'POST',
        ));
        $form->add('submit', 'submit', array('label' => 'Create'));

        $form->handleRequest($request);

        if ($form->isValid()) {
            $pictureProperties = $this->get('picture_upload')->upload($picture->getFile());
            $picture->setPath($pictureProperties['path']);
            $picture->setMiniaturePath($pictureProperties['miniature_path']);
            $picture->setBlurredMiniaturePath($pictureProperties['blurred_miniature_path']);
            $picture->setDateCreated(new \DateTime());
            $picture->setUser($user);
            $picture->setChallenge($challenge);
            $picture->setExifProperties($pictureProperties['exif']);
            $em = $this->getDoctrine()->getManager();
            $em->persist($picture);
            $em->flush();

            return $this->render('SPJGameBundle:Picture:created.html.twig');
        }

        return $this->render('SPJGameBundle:Picture:create.html.twig', array(
            'picture' => $picture,
            'form'   => $form->createView(),
        ));
    }

    public function challengeListAction($challengeId, $page = 1)
    {
        $challenge = $this->get('challenge_repository')->findOneById($challengeId);
        $pictures = $this->get('picture_repository')->findByChallenge($challenge);
        $templateName = 'SPJGameBundle:Picture:' . $challenge->getStatus() . '_challenge_list.html.twig';

        return $this->render(
            $templateName,
            array(
                'pictures' => $pictures,
                'challenge' => $challenge
            )
        );
    }

    public function challengeUserShowAction($challengeId)
    {
        $challenge = $this->get('challenge_repository')->findOneById($challengeId);
        $user = $this->get('security.context')->getToken()->getUser();

        $picture = null;
        if ("" !== $user) {
            $picture = $this->get('picture_repository')->findOneByChallengeAndUser($challenge, $user);
        }

        $templateName = $challenge->getStatus() === 'inprogress' ?
            'SPJGameBundle:Picture:challenge_user_show_inprogress.html.twig' :
            'SPJGameBundle:Picture:challenge_user_show.html.twig';

        return $this->render(
            $templateName,
            array(
                'picture' => $picture,
                'challenge' => $challenge
            )
        );
    }

    public function showAction($pictureId)
    {
        $picture = $this->get('picture_repository')->findOneById($pictureId);
        $user = $this->get('security.context')->getToken()->getUser();

        return $this->render(
            'SPJGameBundle:Picture:show.html.twig',
            array(
                'picture' => $picture
            )
        );
    }
}
{'fraction_non_alphanumeric': 0.15998846929950994, 'fraction_numerical': 0.0002882675122513693, 'mean_word_length': 2.7047517351841965, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 121, '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': '366846', 'n_tokens_mistral': 2020, 'n_tokens_neox': 1853, 'n_words': 257}