<commit_before><?php

namespace Leha\HistoriqueBundle\Controller;

use Leha\CommonBundle\Controller\AbstractController;
use Leha\HistoriqueBundle\Entity\Requete;
use Leha\HistoriqueBundle\Entity;
use Leha\HistoriqueBundle\Entity\AttributRequete;
use Leha\CentralBundle\Entity\EchantillonAttribut;
use Leha\CentralBundle\Entity\Attribut;
use Leha\HistoriqueBundle\Form\Type\HistorySearchType;
use Leha\HistoriqueBundle\Model\HistorySearch;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

/**
 * Class DefaultController
 *
 * @Template
 *
 * @package Leha\HistoriqueBundle\Controller
 */
class DefaultController extends AbstractController
{
    /**
     * Liste les requêtes de l'utilisateur
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function indexAction()
    {
        $requetes = $this->getUser()->getRequetes();

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

    /**
     * Permet la création d'une nouvelle requête
     *
     * @param Request $request
     *
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
     */
    public function editAction(Request $request, Requete $requete = null)
    {
        if ($requete == null) {
            $requete = new Requete();
        }

        $form = $this->createFormBuilder($requete)
            ->add('libelle', 'text')
            ->getForm();

		$process = $this->container->get('leha_requete.handler')
            ->process($request, $form);

		if ($process) {
			return $this->redirectRoute('leha_historique_search', array(
				'id' => $requete->getId()
            ));
		}

        return array(
            'form' => $form->createView(),
            'requete' => $requete
        );
    }

    public function searchAction(Request $request, Requete $requete)
    {
        $em = $this->getDoctrine()->getManager();

        $form_builder = $this->createFormBuilder();

        $attributs_requete = $em->getRepository('LehaHistoriqueBundle:AttributRequete')->getByRequeteType($requete, AttributRequete::ATTRIBUT_REQUETE_FORM);

        $form = $this->get('form.factory')->create(new HistorySearchType(), new HistorySearch($attributs_requete), array('attribut_requete' => $attributs_requete));

        $echantillons = null;
        if ($request->isMethod('POST')) {
            $repo_echantillon = $this->getDoctrine()->getRepository('LehaCentralBundle:Echantillon');

            /**
             * @var $historySearch \Leha\HistoriqueBundle\Model\HistorySearch
             */
            $historySearch = $form->bind($request)->getData();


            //$post_data = $form->bind($request)->getData();
            //$post_data = $post_data->attributes;

/*

            $post_use_data = array();
			foreach ($attributs_requete as $attribut_requete) {
                $attribut = $attribut_requete->getAttribut();
                if (isset($post_data[$attribut->getFieldId()]) && $post_data[$attribut->getFieldId()] != '') {
                    if ($attribut->getScope() == Attribut::SCOPE_ECHANTILLON) {
                        $options = $attribut->getOptions();
                        $filter .= 'e.'.$attribut->getName().' = :'.$attribut->getFieldId();
                        $post_use_data[$attribut->getFieldId()] = $post_data[$attribut->getFieldId()];
                    }
                }
            }


*/

            $post_use_data = array();
            $queryBuilder = $repo_echantillon->getQueryBuilderFiltered($historySearch->getEchantillonProperties());

            $queryBuilder->setMaxResults(1000);

            $echantillons = $queryBuilder->getQuery()->getResult();

            $echantillons_id = array();
            foreach ($echantillons as $echantillon) {
                $echantillons_id[] = $echantillon->getId();
            }

            if (sizeof($echantillons_id) > 0) {
                foreach ($attributs_requete as $attribut_requete) {
                    $attribut = $attribut_requete->getAttribut();
                    if (isset($post_data[$attribut->getFieldId()]) && $post_data[$attribut->getFieldId()] != '') {
                        if ($attribut->getScope() == Attribut::SCOPE_ATTRIBUT) {
                            $echantillons_attribut = $em->createQuery('select e from LehaCentralBundle:AttributEchantillon e where e.attribut = :attributId and e.echantillon in (:echantillonsId) and e.value like :valeur')
                                ->setParameter('attributId', $attribut->getId())
                                ->setParameter('echantillonsId', $echantillons_id)<commit_msg>Suppression commentaire<commit_after><?php

namespace Leha\HistoriqueBundle\Controller;

use Leha\CommonBundle\Controller\AbstractController;
use Leha\HistoriqueBundle\Entity\Requete;
use Leha\HistoriqueBundle\Entity;
use Leha\HistoriqueBundle\Entity\AttributRequete;
use Leha\CentralBundle\Entity\EchantillonAttribut;
use Leha\CentralBundle\Entity\Attribut;
use Leha\HistoriqueBundle\Form\Type\HistorySearchType;
use Leha\HistoriqueBundle\Model\HistorySearch;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

/**
 * Class DefaultController
 *
 * @Template
 *
 * @package Leha\HistoriqueBundle\Controller
 */
class DefaultController extends AbstractController
{
    /**
     * Liste les requêtes de l'utilisateur
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function indexAction()
    {
        $requetes = $this->getUser()->getRequetes();

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

    /**
     * Permet la création d'une nouvelle requête
     *
     * @param Request $request
     *
     * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
     */
    public function editAction(Request $request, Requete $requete = null)
    {
        if ($requete == null) {
            $requete = new Requete();
        }

        $form = $this->createFormBuilder($requete)
            ->add('libelle', 'text')
            ->getForm();

		$process = $this->container->get('leha_requete.handler')
            ->process($request, $form);

		if ($process) {
			return $this->redirectRoute('leha_historique_search', array(
				'id' => $requete->getId()
            ));
		}

        return array(
            'form' => $form->createView(),
            'requete' => $requete
        );
    }

    public function searchAction(Request $request, Requete $requete)
    {
        $em = $this->getDoctrine()->getManager();

        $form_builder = $this->createFormBuilder();

        $attributs_requete = $em->getRepository('LehaHistoriqueBundle:AttributRequete')->getByRequeteType($requete, AttributRequete::ATTRIBUT_REQUETE_FORM);

        $form = $this->get('form.factory')->create(new HistorySearchType(), new HistorySearch($attributs_requete), array('attribut_requete' => $attributs_requete));

        $echantillons = null;
        if ($request->isMethod('POST')) {
            $repo_echantillon = $this->getDoctrine()->getRepository('LehaCentralBundle:Echantillon');

            /**
             * @var $historySearch \Leha\HistoriqueBundle\Model\HistorySearch
             */
            $historySearch = $form->bind($request)->getData();

            $queryBuilder = $repo_echantillon->getQueryBuilderFiltered($historySearch->getEchantillonProperties());

            $queryBuilder->setMaxResults(1000);

            $echantillons = $queryBuilder->getQuery()->getResult();

            $echantillons_id = array();
            foreach ($echantillons as $echantillon) {
                $echantillons_id[] = $echantillon->getId();
            }

            if (sizeof($echantillons_id) > 0) {
                foreach ($attributs_requete as $attribut_requete) {
                    $attribut = $attribut_requete->getAttribut();
                    if (isset($post_data[$attribut->getFieldId()]) && $post_data[$attribut->getFieldId()] != '') {
                        if ($attribut->getScope() == Attribut::SCOPE_ATTRIBUT) {
                            $echantillons_attribut = $em->createQuery('select e from LehaCentralBundle:AttributEchantillon e where e.attribut = :attributId and e.echantillon in (:echantillonsId) and e.value like :valeur')
                                ->setParameter('attributId', $attribut->getId())
                                ->setParameter('echantillonsId', $echantillons_id)
{'fraction_non_alphanumeric': 0.1349206349206349, 'fraction_numerical': 0.0011671335200746965, 'mean_word_length': 2.668236301369863, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 101, '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': '3399745', 'n_tokens_mistral': 2532, 'n_tokens_neox': 2451, 'n_words': 375}