<commit_before><?php

namespace Waldo\DatatableBundle\Util;

use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\JsonResponse;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Expr\Join;

use Waldo\DatatableBundle\Util\Factory\Query\QueryInterface;
use Waldo\DatatableBundle\Util\Factory\Query\DoctrineBuilder;
use Waldo\DatatableBundle\Util\Formatter\Renderer;

class Datatable
{

    /**
     * @var Renderer
     */
    protected $rendererEngine;

    /**
     * @var array
     */
    protected $fixedData;

    /**
     * @var array
     */
    protected $config;

    /**
     * @var EntityManager
     */
    protected $em;

    /**
     * @var array
     */
    protected $multiple;

    /**
     * @var \Waldo\DatatableBundle\Util\Factory\Query\QueryInterface
     */
    protected $queryBuilder;

    /**
     * @var RequestStack
     */
    protected $request;

    /**
     * @var closure
     */
    protected $renderer;

    /**
     * @var array
     */
    protected $renderers;

    /**
     * @var Renderer
     */
    protected $rendererObj;

    /**
     * @var boolean
     */
    protected $search;

    /**
     * @var boolean
     */
    protected $globalSearch;

    /**
     * @var array
     */
    protected $searchFields = array();

    /**
     * @var array
     */
    protected $notFilterableFields = array();

    /**
     * @var array
     */
    protected $notSortableFields = array();

    /**
     * @var array
     */
    protected $hiddenFields = array();

    /**
     * @var array
     */
    protected static $instances = array();

    /**
     * @var Datatable
     */
    protected static $currentInstance;

    /**
     * class constructor
     *
     *
     * @param EntityManager $entityManager
     * @param RequestStack $request
     * @param DoctrineBuilder $doctrineBuilder
     * @param Renderer $renderer
     * @param array $config
     */
    public function __construct(
            EntityManager $entityManager,
            RequestStack $request,
            DoctrineBuilder $doctrineBuilder,
            Renderer $renderer, $config)
    {
        $this->em = $entityManager;
        $this->request = $request;
        $this->queryBuilder = $doctrineBuilder;
        $this->rendererEngine = $renderer;
        $this->config = $config;

        self::$currentInstance = $this;

        $this->applyDefaults();
    }

    /**
     * apply default value from datatable config
     *
     * @return void
     */
    protected function applyDefaults()
    {
        if (isset($this->config['all'])) {
            $this->search = $this->config['all']['search'];
        }
    }

    /**
     * add join
     *
     * @example:
     *      ->setJoin(
     *              'r.event',
     *              'e',
     *              \Doctrine\ORM\Query\Expr\Join::INNER_JOIN,
     *              \Doctrine\ORM\Query\Expr\Join::WITH,
     *              'e.name like %test%')
     *
     * @param string      $join          The relationship to join.
     * @param string      $alias         The alias of the join.
     * @param string|Join::INNER_JOIN    $type      The type of the join Join::INNER_JOIN | Join::LEFT_JOIN
     * @param string|null $conditionType The condition type constant. Either ON or WITH.
     * @param string|null $condition     The condition for the join.
     *
     * @return Datatable
     */
    public function addJoin($join, $alias, $type = Join::INNER_JOIN, $conditionType = null, $condition = null)
    {
        $this->queryBuilder->addJoin($join, $alias, $type, $conditionType, $condition);
        return $this;
    }

    /**
     * execute
     *
     * @param int $hydrationMode
     *
     * @return JsonResponse
     */
    public function execute($hydrationMode = Query::HYDRATE_ARRAY)
    {
        $request = $this->request->getCurrentRequest();

        $iTotalRecords = $this->queryBuilder->getTotalRecords();
        $iTotalDisplayRecords = $this->queryBuilder->getTotalDisplayRecords();

        list($data, $objects) = $this->queryBuilder->getData($hydrationMode);

        $id_index = array_search('_identifier_', array_keys($this->getFields()));
        $ids = array();

        array_walk($data, function($val, $key) use ($id_index, &$ids) {
            $ids[$key] = $val[$id_index];
        });

        if (!is_null($this->fixedData)) {
            $this->fixedData = array_reverse($this->fixedData);
            foreach ($this->fixedData as $item) {<commit_msg>Remove unused parameter<commit_after><?php

namespace Waldo\DatatableBundle\Util;

use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\JsonResponse;

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Expr\Join;

use Waldo\DatatableBundle\Util\Factory\Query\QueryInterface;
use Waldo\DatatableBundle\Util\Factory\Query\DoctrineBuilder;
use Waldo\DatatableBundle\Util\Formatter\Renderer;

class Datatable
{

    /**
     * @var Renderer
     */
    protected $rendererEngine;

    /**
     * @var array
     */
    protected $fixedData;

    /**
     * @var array
     */
    protected $config;

    /**
     * @var EntityManager
     */
    protected $em;

    /**
     * @var array
     */
    protected $multiple;

    /**
     * @var \Waldo\DatatableBundle\Util\Factory\Query\QueryInterface
     */
    protected $queryBuilder;

    /**
     * @var RequestStack
     */
    protected $request;

    /**
     * @var closure
     */
    protected $renderer;

    /**
     * @var array
     */
    protected $renderers;

    /**
     * @var Renderer
     */
    protected $rendererObj;

    /**
     * @var boolean
     */
    protected $search;

    /**
     * @var boolean
     */
    protected $globalSearch;

    /**
     * @var array
     */
    protected $searchFields = array();

    /**
     * @var array
     */
    protected $notFilterableFields = array();

    /**
     * @var array
     */
    protected $notSortableFields = array();

    /**
     * @var array
     */
    protected $hiddenFields = array();

    /**
     * @var array
     */
    protected static $instances = array();

    /**
     * @var Datatable
     */
    protected static $currentInstance;

    /**
     * class constructor
     *
     *
     * @param EntityManager $entityManager
     * @param RequestStack $request
     * @param DoctrineBuilder $doctrineBuilder
     * @param Renderer $renderer
     * @param array $config
     */
    public function __construct(
            EntityManager $entityManager,
            RequestStack $request,
            DoctrineBuilder $doctrineBuilder,
            Renderer $renderer, $config)
    {
        $this->em = $entityManager;
        $this->request = $request;
        $this->queryBuilder = $doctrineBuilder;
        $this->rendererEngine = $renderer;
        $this->config = $config;

        self::$currentInstance = $this;

        $this->applyDefaults();
    }

    /**
     * apply default value from datatable config
     *
     * @return void
     */
    protected function applyDefaults()
    {
        if (isset($this->config['all'])) {
            $this->search = $this->config['all']['search'];
        }
    }

    /**
     * add join
     *
     * @example:
     *      ->setJoin(
     *              'r.event',
     *              'e',
     *              \Doctrine\ORM\Query\Expr\Join::INNER_JOIN,
     *              \Doctrine\ORM\Query\Expr\Join::WITH,
     *              'e.name like %test%')
     *
     * @param string      $join          The relationship to join.
     * @param string      $alias         The alias of the join.
     * @param string|Join::INNER_JOIN    $type      The type of the join Join::INNER_JOIN | Join::LEFT_JOIN
     * @param string|null $conditionType The condition type constant. Either ON or WITH.
     * @param string|null $condition     The condition for the join.
     *
     * @return Datatable
     */
    public function addJoin($join, $alias, $type = Join::INNER_JOIN, $conditionType = null, $condition = null)
    {
        $this->queryBuilder->addJoin($join, $alias, $type, $conditionType, $condition);
        return $this;
    }

    /**
     * execute
     *
     * @param int $hydrationMode
     *
     * @return JsonResponse
     */
    public function execute()
    {
        $request = $this->request->getCurrentRequest();

        $iTotalRecords = $this->queryBuilder->getTotalRecords();
        $iTotalDisplayRecords = $this->queryBuilder->getTotalDisplayRecords();

        list($data, $objects) = $this->queryBuilder->getData();

        $id_index = array_search('_identifier_', array_keys($this->getFields()));
        $ids = array();

        array_walk($data, function($val, $key) use ($id_index, &$ids) {
            $ids[$key] = $val[$id_index];
        });

        if (!is_null($this->fixedData)) {
            $this->fixedData = array_reverse($this->fixedData);
            foreach ($this->fixedData as $item) {
{'fraction_non_alphanumeric': 0.13397713397713398, 'fraction_numerical': 0.0, 'mean_word_length': 2.014386082301773, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, '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': '6135902', 'n_tokens_mistral': 2657, 'n_tokens_neox': 2602, 'n_words': 543}