<commit_before><?php

/*
 * This file is part of the BluemesaCoreBundle.
 * 
 * Copyright (c) 2016 BlueMesa LabDB Contributors <<EMAIL>>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Bluemesa\Bundle\CoreBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

use Doctrine\ORM\NoResultException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Exception\RouteNotFoundException;

use Bluemesa\Bundle\CoreBundle\Filter\RedirectFilterInterface;

/**
 * Base class for CRUD operations
 *
 * @author <NAME> <<EMAIL>>
 */
abstract class CRUDController extends AbstractController
{
    const ENTITY_CLASS = null;
    const ENTITY_NAME = 'entity|entities';

    /**
     * {@inheritdoc}
     */
    protected function getObjectManager($object = null)
    {
        $object = (null == $object) ? $this->getEntityClass() : $object;
        
        return parent::getObjectManager($object);
    }
    
    /**
     * List entities
     *
     * @Route("/")
     * @Route("/list/{filter}")
     * @Template()
     *
     * @return Symfony\Component\HttpFoundation\Response
     */
    public function listAction(Request $request)
    {
        $filter = $this->getFilter();       
        if (($filter instanceof RedirectFilterInterface)&&($filter->needRedirect())) {
            
            return $this->getFilterRedirect($filter);
        }
        
        $paginator  = $this->getPaginator();
        $page = $this->getCurrentPage($request);
        $repository = $this->getObjectManager()->getRepository($this->getEntityClass());
        $count = $repository->getListCount($filter);
        $query = $repository->getListQuery($filter)->setHint('knp_paginator.count', $count);
        $entities = $paginator->paginate($query, $page, 25, array('distinct' => false));
        
        return array('entities' => $entities, 'filter' => $filter);
    }

    /**
     * Show entity
     *
     * @Route("/show/{id}")
     * @Template()
     *
     * @param mixed $id
     *
     * @return Symfony\Component\HttpFoundation\Response
     */
    public function showAction($id)
    {
        $entity = $this->getEntity($id);

        return array('entity' => $entity);
    }

    /**
     * Create entity
     *
     * @Route("/new")
     * @Template()
     *
     * @return Symfony\Component\HttpFoundation\Response
     */
    public function createAction(Request $request)
    {<commit_msg>Injecting $request to actions<commit_after><?php

/*
 * This file is part of the BluemesaCoreBundle.
 * 
 * Copyright (c) 2016 BlueMesa LabDB Contributors <<EMAIL>>
 * 
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Bluemesa\Bundle\CoreBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

use Doctrine\ORM\NoResultException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Exception\RouteNotFoundException;

use Bluemesa\Bundle\CoreBundle\Filter\RedirectFilterInterface;

/**
 * Base class for CRUD operations
 *
 * @author <NAME> <<EMAIL>>
 */
abstract class CRUDController extends AbstractController
{
    const ENTITY_CLASS = null;
    const ENTITY_NAME = 'entity|entities';

    /**
     * {@inheritdoc}
     */
    protected function getObjectManager($object = null)
    {
        $object = (null == $object) ? $this->getEntityClass() : $object;
        
        return parent::getObjectManager($object);
    }
    
    /**
     * List entities
     *
     * @Route("/")
     * @Route("/list/{filter}")
     * @Template()
     *
     * @return Symfony\Component\HttpFoundation\Response
     */
    public function listAction(Request $request)
    {
        $filter = $this->getFilter();       
        if (($filter instanceof RedirectFilterInterface)&&($filter->needRedirect())) {
            
            return $this->getFilterRedirect($filter);
        }
        
        $paginator  = $this->getPaginator();
        $page = $this->getCurrentPage($request);
        $repository = $this->getObjectManager()->getRepository($this->getEntityClass());
        $count = $repository->getListCount($filter);
        $query = $repository->getListQuery($filter)->setHint('knp_paginator.count', $count);
        $entities = $paginator->paginate($query, $page, 25, array('distinct' => false));
        
        return array('entities' => $entities, 'filter' => $filter);
    }

    /**
     * Show entity
     *
     * @Route("/show/{id}")
     * @Template()
     *
     * @param mixed $id
     *
     * @return Symfony\Component\HttpFoundation\Response
     */
    public function showAction(Request $request, $id)
    {
        $entity = $this->getEntity($id);

        return array('entity' => $entity);
    }

    /**
     * Create entity
     *
     * @Route("/new")
     * @Template()
     *
     * @return Symfony\Component\HttpFoundation\Response
     */
    public function createAction(Request $request)
    {
{'fraction_non_alphanumeric': 0.1368558625840179, 'fraction_numerical': 0.0022404779686333084, 'mean_word_length': 2.865079365079365, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 49, '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': '5368880', 'n_tokens_mistral': 1523, 'n_tokens_neox': 1513, 'n_words': 303}