<commit_before><?php

namespace Skaphandrus\AppBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Skaphandrus\AppBundle\Entity\SkPhoto;
use Skaphandrus\AppBundle\Utils\Utils;
use Skaphandrus\AppBundle\Entity\SkKeyword;
use Skaphandrus\AppBundle\Form\SkPhotoType;

/**
 * SkPhoto controller.
 *
 */
class SkPhotoController extends Controller {

    /**
     * Lists all SkPhoto entities.
     *
     */
    public function indexAction(Request $request) {

        $fos_user = $this->get('security.token_storage')->getToken()->getUser();
//        $params = array($fos_user->getId());
        $params = $request->query->all();

        $contests = $this->getDoctrine()->getRepository('SkaphandrusAppBundle:SkPhotoContest')->findBy(array('isVisible' => true), array('beginAt' => 'DESC'));

        $species = $this->getDoctrine()->getRepository('SkaphandrusAppBundle:SkPhoto')->getUserSpeciesFromPhotos($fos_user->getId());

        $tags = $this->getDoctrine()->getRepository('SkaphandrusAppBundle:SkPhoto')->getUserTagsFromPhotos($fos_user->getId());

//        $qb = $this->getDoctrine()->getRepository('SkaphandrusAppBundle:SkPhoto')->getQueryBuilder4($params, 20);
        $qb = $this->getDoctrine()->getRepository('SkaphandrusAppBundle:SkPhoto')->getUserPhotos($fos_user->getId(), $params, 21);
        $query = $qb->getQuery();

//        dump($tags);

        $paginator = $this->get('knp_paginator');
        $pagination = $paginator->paginate(
                $query, $this->get('request')->query->getInt('page', 1)/* page number */, 21/* limit per page */
        );

        // parameters to template
        return $this->render('SkaphandrusAppBundle:SkPhoto:index.html.twig', array(
                    'species' => $species,
                    'tags' => $tags,
                    'contests' => $contests,
                    'pagination' => $pagination,
                    'params' => $params
        ));

//        $em = $this->getDoctrine()->getManager();
//
//        ##@LM
//        $fos_user = $this->get('security.token_storage')->getToken()->getUser();
//        $entities = $em->getRepository('SkaphandrusAppBundle:SkPhoto')->findByFosUser($fos_user );
//
//        return $this->render('SkaphandrusAppBundle:SkPhoto:index.html.twig', array(
//                    'entities' => $entities,
//        ));
    }

    /**
     * Creates a new SkPhoto entity.
     *
     */
    public function createAction(Request $request) {
        $entity = new SkPhoto();

        ##@LM
        $fos_user = $this->get('security.token_storage')->getToken()->getUser();
        $entity->setFosUser($fos_user);

        $form = $this->createCreateForm($entity);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();

//            $entity->upload();
            // Add tags from custom field
            $tags = explode(',', $request->request->get('tags'));
            foreach ($tags as $tag) {
                $keyword = $this->getDoctrine()->getRepository('SkaphandrusAppBundle:SkKeyword')
                        ->findLikeKeyword($tag);

                if (!$keyword) {
                    $keyword = new SkKeyword();
                    $keyword->setKeyword($tag);

                    $em->persist($keyword);
                    $em->flush();
                }
                $entity->addKeyword($keyword);
            }

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

            ##@LM
            $this->get('session')->getFlashBag()->add('notice', 'form.common.message.changes_saved');

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

        return $this->render('SkaphandrusAppBundle:SkPhoto:new.html.twig', array(
                    'entity' => $entity,
                    'keywords' => explode(',', $request->request->get('tags')),
                    'form' => $form->createView(),
        ));
    }

    /**
     * Creates a form to create a SkPhoto entity.
     *
     * @param SkPhoto $entity The entity
     *
     * @return \Symfony\Component\Form\Form The form<commit_msg>photo<commit_after><?php

namespace Skaphandrus\AppBundle\Controller;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Skaphandrus\AppBundle\Entity\SkPhoto;
use Skaphandrus\AppBundle\Utils\Utils;
use Skaphandrus\AppBundle\Entity\SkKeyword;
use Skaphandrus\AppBundle\Form\SkPhotoType;

/**
 * SkPhoto controller.
 *
 */
class SkPhotoController extends Controller {

    /**
     * Lists all SkPhoto entities.
     *
     */
    public function indexAction(Request $request) {

        $fos_user = $this->get('security.token_storage')->getToken()->getUser();
//        $params = array($fos_user->getId());
        $params = $request->query->all();

        $contests = $this->getDoctrine()->getRepository('SkaphandrusAppBundle:SkPhotoContest')->findBy(array('isVisible' => true), array('beginAt' => 'DESC'));

        $species = $this->getDoctrine()->getRepository('SkaphandrusAppBundle:SkPhoto')->getUserSpeciesFromPhotos($fos_user->getId());

        $tags = $this->getDoctrine()->getRepository('SkaphandrusAppBundle:SkPhoto')->getUserTagsFromPhotos($fos_user->getId());

//        $qb = $this->getDoctrine()->getRepository('SkaphandrusAppBundle:SkPhoto')->getQueryBuilder4($params, 20);
        $qb = $this->getDoctrine()->getRepository('SkaphandrusAppBundle:SkPhoto')->getUserPhotos($fos_user->getId(), $params, 21);
        $query = $qb->getQuery();

//        dump($tags);

        $paginator = $this->get('knp_paginator');
        $pagination = $paginator->paginate(
                $query, $this->get('request')->query->getInt('page', 1)/* page number */, 21/* limit per page */
        );

        // parameters to template
        return $this->render('SkaphandrusAppBundle:SkPhoto:index.html.twig', array(
                    'species' => $species,
                    'tags' => $tags,
                    'contests' => $contests,
                    'pagination' => $pagination,
                    'params' => $params
        ));

//        $em = $this->getDoctrine()->getManager();
//
//        ##@LM
//        $fos_user = $this->get('security.token_storage')->getToken()->getUser();
//        $entities = $em->getRepository('SkaphandrusAppBundle:SkPhoto')->findByFosUser($fos_user );
//
//        return $this->render('SkaphandrusAppBundle:SkPhoto:index.html.twig', array(
//                    'entities' => $entities,
//        ));
    }

    /**
     * Creates a new SkPhoto entity.
     *
     */
    public function createAction(Request $request) {
        $entity = new SkPhoto();

        ##@LM
        $fos_user = $this->get('security.token_storage')->getToken()->getUser();
        $entity->setFosUser($fos_user);

        $form = $this->createCreateForm($entity);
        $form->handleRequest($request);

        if ($form->isValid()) {
            $em = $this->getDoctrine()->getManager();



            if ($request->request->get('tags') != NULL and $request->request->get('tags') != ""):



//            $entity->upload();
                // Add tags from custom field
                $tags = explode(',', $request->request->get('tags'));
                foreach ($tags as $tag) {
                    $keyword = $this->getDoctrine()->getRepository('SkaphandrusAppBundle:SkKeyword')
                            ->findLikeKeyword($tag);

                    if (!$keyword) {
                        $keyword = new SkKeyword();
                        $keyword->setKeyword($tag);

                        $em->persist($keyword);
                        $em->flush();
                    }
                    $entity->addKeyword($keyword);
                }
            endif;
            $em->persist($entity);
            $em->flush();

            ##@LM
            $this->get('session')->getFlashBag()->add('notice', 'form.common.message.changes_saved');

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

        return $this->render('SkaphandrusAppBundle:SkPhoto:new.html.twig', array(
                    'entity' => $entity,
                    'keywords' => explode(',', $request->request->get('tags')),
                    'form' => $form->createView(),
        ));
    }

    /**
     * Creates a form to create a SkPhoto entity.
     *
     * @param SkPhoto $entity The entity
     *
     * @return \Symfony\Component\Form\Form The form
{'fraction_non_alphanumeric': 0.17220229140145815, 'fraction_numerical': 0.0018516375419511631, 'mean_word_length': 2.290936785986291, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 171, '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': '4227668', 'n_tokens_mistral': 2529, 'n_tokens_neox': 2454, 'n_words': 363}