<commit_before><?php

namespace Dzangocart\Bundle\DzangocartBundle\Controller;

use DateTime;

use Dzangocart\Bundle\DzangocartBundle\Form\Type\OrderFilterType;

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

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class OrderController extends Controller
{
    /**
     * @Route("/", name="dzangocart_orders")
     * @Template("DzangocartBundle:Order:index.html.twig")
     */
    public function indexAction(Request $request)
    {
        $dzangocart_config = $this->container->getParameter('dzangocart.config');

        if ($request->isXmlHttpRequest() || $request->getRequestFormat() == 'json') {

            $params = $this->getFilters($request->query);
            $params['sort_by'] = $this->getSortOrder($request->query);

            $data = $this->get('dzangocart')
                ->getOrders($params);

            $data['datetime_format'] = $dzangocart_config['datetime_format'];

            $view = $this->renderView('DzangocartBundle:Order:index.json.twig', $data);

            return new Response($view, 200, array('Content-Type' => 'application/json'));
        } else {
            $form = $this->createForm(
                new OrderFilterType(),
                array(
                    'date_from' => (new DateTime())->modify('first day of this month'),
                    'date_to' => new DateTime()
                )
            );

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

    /**
     * @Route("/{id}", name="dzangocart_order", requirements={"id": "\d+"})
     * @Template()
     */
    public function showAction(Request $request, $id)
    {
        $dzangocart_config = $this->container->getParameter('dzangocart.config');

        $params = array(
            'id' => $id
        );

        $order = $this->get('dzangocart')
            ->getOrder($params);

        return array(
            'order' => $order,
            'config' => $dzangocart_config,
            'data' => print_r($order, true)
        );
    }

    protected function getFilters(ParameterBag $query)
    {
        $filters = array();

        $filters['search'] = $query->get('sSearch');
        $filters['limit'] = $query->get('iDisplayLength');
        $filters['offset'] = $query->get('iDisplayStart');

        $_filters = $query->get('filters');

        foreach ($date_fields = array('date_from', 'date_to') as $field) {
            $value = $_filters[$field];
            if (!empty($value)) {
                $filters[$field] = $value;
            }
        }

        $filters['test'] = @$_filters['test'] ? true : false;
/*
        if (array_key_exists('customer', $_filters)) {
            $filters['customer'] = $_filters['customer'];
        }
*/

        return $filters;
    }

    protected function getSortOrder(ParameterBag $query)
    {
        $sort_by = array();

        $columns = $this->getSortColumns();

        $n = $query->get('iSortingCols');

        for ($i = 0; $i < $n; $i++) {
            $index = $query->get('iSortCol_' . $i);

            if (array_key_exists($index, $columns)) {

                $column = $columns[$index];

                if (!is_array($column)) {
                    $column = array($column);
                }

                foreach ($column as $c) {
                    $sort_by[] = $c;
                    $sort_by[] = $query->get('sSortDir_' . $i, 'asc');
                }<commit_msg>modified orderController<commit_after><?php

namespace Dzangocart\Bundle\DzangocartBundle\Controller;

use DateTime;

use Dzangocart\Bundle\DzangocartBundle\Form\Type\OrderFilterType;

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

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class OrderController extends Controller
{
    /**
     * @Route("/", name="dzangocart_orders")
     * @Template("DzangocartBundle:Order:index.html.twig")
     */
    public function indexAction(Request $request)
    {
        $dzangocart_config = $this->container->getParameter('dzangocart.config');

        if ($request->isXmlHttpRequest() || $request->getRequestFormat() == 'json') {

            $params = $this->getFilters($request->query);
            $params['sort_by'] = $this->getSortOrder($request->query);

            $data = $this->get('dzangocart')
                ->getOrders($params);

            $data['datetime_format'] = $dzangocart_config['datetime_format'];

            $view = $this->renderView('DzangocartBundle:Order:index.json.twig', $data);

            return new Response($view, 200, array('Content-Type' => 'application/json'));
        } else {
            $form = $this->createForm(
                new OrderFilterType(),
                array(
                    'date_from' => (new DateTime())->modify('first day of this month'),
                    'date_to' => new DateTime()
                )
            );

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

    /**
     * @Route("/{id}", name="dzangocart_order", requirements={"id": "\d+"})
     * @Template()
     */
    public function showAction(Request $request, $id)
    {
        $dzangocart_config = $this->container->getParameter('dzangocart.config');

        $params = array(
            'id' => $id
        );

        $order = $this->get('dzangocart')
            ->getOrder($params);

        return array(
            'order' => $order,
            'config' => $dzangocart_config,
            'data' => print_r($order, true)
        );
    }

    protected function getFilters(ParameterBag $query)
    {
        $filters = array();

        $filters['search'] = $query->get('search');
        $filters['limit'] = $query->get('length');
        $filters['offset'] = $query->get('start');

        $_filters = $query->get('filters');

        foreach ($date_fields = array('date_from', 'date_to') as $field) {
            $value = $_filters[$field];
            if (!empty($value)) {
                $filters[$field] = $value;
            }
        }

        $filters['test'] = @$_filters['test'] ? true : false;
/*
        if (array_key_exists('customer', $_filters)) {
            $filters['customer'] = $_filters['customer'];
        }
*/

        return $filters;
    }

    protected function getSortOrder(ParameterBag $query)
    {
        $sort_by = array();

        $columns = $this->getSortColumns();

        $n = $query->get('sortingCols');

        for ($i = 0; $i < $n; $i++) {
            $index = $query->get('sortCol_' . $i);

            if (array_key_exists($index, $columns)) {

                $column = $columns[$index];

                if (!is_array($column)) {
                    $column = array($column);
                }

                foreach ($column as $c) {
                    $sort_by[] = $c;
                    $sort_by[] = $query->get('sortDir_' . $i, 'asc');
                }
{'fraction_non_alphanumeric': 0.16013901884774762, 'fraction_numerical': 0.0010693757519048255, 'mean_word_length': 2.1331658291457285, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 73, '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': '218976', 'n_tokens_mistral': 2219, 'n_tokens_neox': 2131, 'n_words': 359}