<commit_before><?php

namespace IZJ\UserBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Form\FormError;
use IZJ\UserBundle\Entity\User;
use IZJ\UserBundle\Form\UserType;

class UserController extends Controller
{
    public function indexAction(Request $request)
    {
       

        // $users = $em->getRepository('IZJUserBundle:User')->findAll();

        /*
        $res = 'Lista de Usuarios: <br />';

        foreach($users as $user)
        {
        	$res .= 'Usuarios: '. $user-> getUserName() . ' - Email: '. $user->getEmail() . '<br />';
        }

        return new Response($res);
        */

        $searchQuery = $request->get('query');

        if(!empty($searchQuery))
        {
            $finder = $this->container->get('fos_elastica.finder.app.user');
            $users = $finder->createPaginatorAdapter($searchQuery);
        }
        else
        {
            $em = $this->getDoctrine()->getManager();
            $dql = "SELECT u FROM IZJUserBundle:User u ORDER BY u.id DESC";
            $users = $em->createQuery($dql);
        }
        
        $paginator = $this->get('knp_paginator');
        $pagination = $paginator->paginate(
        	$users, $request->query->getInt('page',1),
        	4
        );

        $deleteFormAjax = $this->createCustomForm(':USER_ID', 'DELETE', 'izj_user_delete');

        return $this->render('IZJUserBundle:User:index.html.twig', array('pagination' => $pagination,
            'delete_form_ajax'=> $deleteFormAjax->createView()));
    }

    public function addAction()
    {
        $user = new User();
        $form = $this->createCreateForm($user);

        return $this->render('IZJUserBundle:User:add.html.twig', array('form' => $form->createView()));
    }

    private function createCreateForm(User $item)
    {
        /*$form = $this->createForm(new UserType(), $item, array(
                'action' => $this->generateUrl('izj_user_create'),
                'method' => 'POST'
            ));*/
        $form = $this->createForm(UserType::class, $item, array(
                'action' => $this->generateUrl('izj_user_create'),
                'method' => 'POST'
            ));<commit_msg>15.kursua iñda: Elastic Serach<commit_after><?php

namespace IZJ\UserBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Form\FormError;
use IZJ\UserBundle\Entity\User;
use IZJ\UserBundle\Form\UserType;

class UserController extends Controller
{
    public function indexAction(Request $request)
    {
       
        // $users = $em->getRepository('IZJUserBundle:User')->findAll();

        /*
        $res = 'Lista de Usuarios: <br />';

        foreach($users as $user)
        {
        	$res .= 'Usuarios: '. $user-> getUserName() . ' - Email: '. $user->getEmail() . '<br />';
        }

        return new Response($res);
        */

        $searchQuery = $request->get('query');

        if(!empty($searchQuery))
        {
            $finder = $this->container->get('fos_elastica.finder.app.user');
            $users = $finder->createPaginatorAdapter($searchQuery);
        }
        else
        {
            $em = $this->getDoctrine()->getManager();
            $dql = "SELECT u FROM IZJUserBundle:User u ORDER BY u.id DESC";
            $users = $em->createQuery($dql);
        }
        
        $paginator = $this->get('knp_paginator');
        $pagination = $paginator->paginate(
        	$users, $request->query->getInt('page',1),
        	5
        );

        $deleteFormAjax = $this->createCustomForm(':USER_ID', 'DELETE', 'izj_user_delete');

        return $this->render('IZJUserBundle:User:index.html.twig', array('pagination' => $pagination,
            'delete_form_ajax'=> $deleteFormAjax->createView()));
    }

    public function addAction()
    {
        $user = new User();
        $form = $this->createCreateForm($user);

        return $this->render('IZJUserBundle:User:add.html.twig', array('form' => $form->createView()));
    }

    private function createCreateForm(User $item)
    {
        /*$form = $this->createForm(new UserType(), $item, array(
                'action' => $this->generateUrl('izj_user_create'),
                'method' => 'POST'
            ));*/
        $form = $this->createForm(UserType::class, $item, array(
                'action' => $this->generateUrl('izj_user_create'),
                'method' => 'POST'
            ));
{'fraction_non_alphanumeric': 0.159798149705635, 'fraction_numerical': 0.001261564339781329, 'mean_word_length': 2.4521044992743106, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 71, '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': '6195232', 'n_tokens_mistral': 1449, 'n_tokens_neox': 1422, 'n_words': 241}