<commit_before><?php

namespace Numa\DOASiteBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\EntityRepository;
use Numa\Util\Util as Util;
use Symfony\Component\Stopwatch\Stopwatch;

class DefaultController extends Controller {

    public function indexAction() {
        $nocache = false;
        $em = $this->getDoctrine()->getManager();
        $hometabs = $this->get('mymemcache')->get('hometabs');
         
        if (empty($hometabs)) {
            $hometabs = $em->getRepository('NumaDOAAdminBundle:HomeTab')->findAll();
            $this->get('mymemcache')->set('hometabs', $hometabs);
            $nocache = true;
            //$this->get('memcache.default')->set('jsonCar', $jsonCar);
        }

        $tabs = array();
        foreach ($hometabs as $tab) {
            $cat = $tab->getCategoryName();
            $tabs[$cat][] = $tab;
        }

        $vehCategory = 1;
        $lftreec = $em->getRepository('NumaDOAAdminBundle:ListingFieldTree');
        $lflistc = $em->getRepository('NumaDOAAdminBundle:ListingFieldLists');
        $lftreec->setMemcached($this->get('mymemcache'));
        $lflistc->setMemcached($this->get('mymemcache'));

        $jsonCar = $lftreec->getJsonTreeModels(614);

        $jsonRvs = $lftreec->getJsonTreeModels(760);
        $vehicleChoices = $lflistc->findAllBy('Body Style', 1, true, true);
        $vehicleModel = $lflistc->findAllBy('Model', 1, true, false);
        $vehicleMake = $lftreec->findAllBy(614, 1, true, false);

        //die();

        $vehicleForm = $this->get('form.factory')->createNamedBuilder('', 'form', null, array(
                    'csrf_protection' => false,
                ))
                ->setMethod('GET')
                ->setAction($this->get('router')->generate('search_dispatch'))
                ->setAttributes(array("class" => "form-inline", 'role' => 'search', 'name' => 'search'))
                ->add('bodyStyle', 'choice', array(
                    'choices' => $vehicleChoices,
                    'empty_value' => 'Any Body Style',
                    'label' => "Body Style", "required" => false
                ))
                ->add('model', 'choice', array(
                    'choices' => $vehicleModel,
                    'empty_value' => 'Any Model',
                    'label' => "Model", "required" => false
                ))
                ->add('make', 'choice', array(
                    'choices' => $vehicleMake,
                    'empty_value' => 'Any Make',
                    'label' => "Make", "required" => false
                ))
                ->add('priceFrom', 'text', array('label' => 'Price from', "required" => false))
                ->add('priceTo', 'text', array('label' => 'to', "required" => false))
                ->add('yearFrom', 'choice', array('label' => 'Year from', 'choices' => Util::createYearRangeArray(), "required" => false))
                ->add('yearTo', 'choice', array('label' => 'to', 'choices' => Util::createYearRangeArray(), 'preferred_choices' => array(Util::yearMax), "required" => false))
                ->add('category_id', 'hidden', array('data' => 1))
                ->getForm();

        $marinaBoatType = $lflistc->findAllBy('Boat Type', 2, true, true);
        $marinaBoatMake = $lflistc->findAllBy('Boat Make', 2, true, true);

        $marineForm = $this->get('form.factory')->createNamedBuilder('', 'form', null, array(
                    'csrf_protection' => false,
                ))
                ->setMethod('GET')
                ->setAction($this->get('router')->generate('search_dispatch'))
                ->setAttributes(array("class" => "form-inline", 'role' => 'search', 'name' => 'search'))
                ->add('boatType', 'choice', array(
                    'choices' => $marinaBoatType,
                    'empty_value' => 'Any type',
                    'label' => "Type", "required" => false
                ))
                ->add('boatMake', 'choice', array(
                    'choices' => $marinaBoatMake,
                    'empty_value' => 'Any make',
                    'label' => "Make", "required" => false
                ))
                ->add('boatModel', 'text', array('label' => 'Model', "required" => false))
                ->add('priceFrom', 'text', array('label' => 'Price from', "required" => false))
                ->add('priceTo', 'text', array('label' => 'to', "required" => false))
                ->add('yearFrom', 'choice', array('label' => 'Year from', 'choices' => Util::createYearRangeArray()))
                ->add('yearTo', 'choice', array('label' => 'to', 'choices' => Util::createYearRangeArray(), 'preferred_choices' => array(Util::yearMax)))
                ->add('category_id', 'hidden', array('data' => 2))
                ->getForm();


        $rvMake = $lftreec->findAllBy(760, 4, true, true);
        $rvClasses = $lflistc->findAllBy('type', 4, true, true);


        $rvsForm = $this->get('form.factory')->createNamedBuilder('', 'form', null, array(
                    'csrf_protection' => false,
                ))
                ->setMethod('GET')
                ->setAction($this->get('router')->generate('search_dispatch'))
                ->setAttributes(array("class" => "form-inline", 'role' => 'search', 'name' => 'search'))
                ->add('modelRvs', 'choice', array('label' => 'Model', 'required' => false))
                ->add('makeRvs', 'choice', array(
                    'choices' => $rvMake,
                    'empty_value' => 'Any Make',
                    'label' => "Make", "required" => false
                ))
                ->add('category_id', 'hidden', array('data' => 4, 'required' => false))
                ->add('floorPlan', 'text', array('label' => 'Floor Plan', "required" => false))
                ->add('class', 'choice', array(
                    'choices' => $rvClasses,
                    'empty_value' => 'Any class',
                    'required' => false,
                    'label' => "Class", "required" => false
                ))
                ->add('priceFrom', 'text', array('label' => 'Price from', "required" => false))
                ->add('priceTo', 'text', array('label' => 'to', "required" => false))
                ->add('yearFrom', 'choice', array('label' => 'Year from', 'choices' => Util::createYearRangeArray(), 'required' => false))
                ->add('yearTo', 'choice', array('label' => 'to', 'choices' => Util::createYearRangeArray(), 'required' => false, 'preferred_choices' => array(Util::yearMax)))
                ->getForm();

        $motoMake = $lflistc->findAllBy('make', 3, true, false);
        $motoType = $lflistc->findAllBy('type', 3, true, true);

        $motorsportForm = $this->get('form.factory')->createNamedBuilder('', 'form', null, array(
                    'csrf_protection' => false,
                ))
                ->setMethod('GET')
                ->setAction($this->get('router')->generate('search_dispatch'))
                ->setAttributes(array("class" => "form-inline", 'role' => 'search', 'name' => 'search'))
                ->add('typeString', 'choice', array('label' => 'Type', 'choices' => $motoType, 'empty_value' => 'Any Type'))
                ->add('Model', 'text', array('label' => 'Model', 'required' => false))
                ->add('make', 'choice', array(
                    'choices' => $motoMake,
                    'empty_value' => 'Any Make',
                    'label' => "Make", "required" => false
                ))
                ->add('priceFrom', 'text', array('label' => 'Price from', 'required' => false))
                ->add('priceTo', 'text', array('label' => 'to', 'required' => false))
                ->add('yearFrom', 'choice', array('label' => 'Year from', 'required' => false))
                ->add('yearTo', 'choice', array('label' => 'to', 'required' => false))
                ->add('category_id', 'hidden', array('data' => 3))
                ->getForm();

        $agModel = $lflistc->findAllBy('Ag Application', 13, true);

        $agForm = $this->get('form.factory')->createNamedBuilder('', 'form', null, array(
                    'csrf_protection' => false,
                ))
                ->setMethod('GET')
                ->setAction($this->get('router')->generate('search_dispatch'))
                ->setAttributes(array("class" => "form-inline", 'role' => 'search', 'name' => 'search'))
                //->add('agApplication', 'choice', array('label' => ''))
                //->add('agApplication', 'choice', array('label' => 'Ag Application', 'choices' => $agModel, 'empty_value' => 'Any Ag Application', 'required' => false))
                ->add('Model', 'choice', array('label' => 'Model', 'required' => false))
                //->add('Make', 'choice', array('label' => 'Make','required'=>false))
                ->add('ag_applicationString', 'choice', array('label' => 'Type', 'choices' => $agModel, 'empty_value' => 'Any Make', 'required' => false))
                ->add('priceFrom', 'text', array('label' => 'Price from', 'required' => false))
                ->add('priceTo', 'text', array('label' => 'to', 'required' => false))
                ->add('yearFrom', 'choice', array('label' => 'Year from', 'required' => false))
                ->add('yearTo', 'choice', array('label' => 'to', 'required' => false))
                ->getForm();

        $response = $this->render('NumaDOASiteBundle:Default:index.html.twig', array(
            'tabs' => $tabs,
            'jsonCar' => $jsonCar,
            'jsonRvs' => $jsonRvs,
            'vehicleForm' => $vehicleForm->createView(),
            'motorsportForm' => $motorsportForm->createView(),
            'rvsForm' => $rvsForm->createView(),
            'agForm' => $agForm->createView(),
            'marineForm' => $marineForm->createView()));
        if (!$nocache) {
            $response->setPublic();
            $response->setSharedMaxAge(600);
            $response->setMaxAge(600);
        }
        return $response;
    }

    public function categoriesAction() {

        //$stopwatch = new Stopwatch();
//        $stopwatch->start('eventName');
//        dump($stopwatch);
        $em = $this->getDoctrine()->getManager();
        $categories = $em->getRepository('NumaDOAAdminBundle:Dcategory')->findAll();
        $dealers = array();
        foreach ($categories as $cat) {
            $dealer = $em->getRepository('NumaDOAAdminBundle:Catalogrecords')->findBy(array('category_id' => $cat->getId()));
            $dealers[$cat->getId()] = $dealer;
        }

//        $event = $stopwatch->stop('eventName');
//        dump($stopwatch);
        return $this->render('NumaDOASiteBundle:Default:categories.html.twig', array('categories' => $categories, 'dealers' => $dealers));
    }

    public function categoryAction(request $request) {
        $em = $this->getDoctrine()->getManager();
        $idCat = $request->get('idcategory');
        $cat_name = $request->get('category_name');
        //$category = $em->getRepository('NumaDOAAdminBundle:Catalogcategory')->findOneById($idCat);
        $catalogs = $em->getRepository('NumaDOAAdminBundle:Catalogrecords')->xfindByDCategory($idCat);<commit_msg>dealers count memcached<commit_after><?php

namespace Numa\DOASiteBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\EntityRepository;
use Numa\Util\Util as Util;
use Symfony\Component\Stopwatch\Stopwatch;

class DefaultController extends Controller {

    public function indexAction() {
        $nocache = false;
        $em = $this->getDoctrine()->getManager();
        $hometabs = $this->get('mymemcache')->get('hometabs');
         
        if (empty($hometabs)) {
            $hometabs = $em->getRepository('NumaDOAAdminBundle:HomeTab')->findAll();
            $this->get('mymemcache')->set('hometabs', $hometabs);
            $nocache = true;
            //$this->get('memcache.default')->set('jsonCar', $jsonCar);
        }

        $tabs = array();
        foreach ($hometabs as $tab) {
            $cat = $tab->getCategoryName();
            $tabs[$cat][] = $tab;
        }

        $vehCategory = 1;
        $lftreec = $em->getRepository('NumaDOAAdminBundle:ListingFieldTree');
        $lflistc = $em->getRepository('NumaDOAAdminBundle:ListingFieldLists');
        $lftreec->setMemcached($this->get('mymemcache'));
        $lflistc->setMemcached($this->get('mymemcache'));

        $jsonCar = $lftreec->getJsonTreeModels(614);

        $jsonRvs = $lftreec->getJsonTreeModels(760);
        $vehicleChoices = $lflistc->findAllBy('Body Style', 1, true, true);
        $vehicleModel = $lflistc->findAllBy('Model', 1, true, false);
        $vehicleMake = $lftreec->findAllBy(614, 1, true, false);

        //die();

        $vehicleForm = $this->get('form.factory')->createNamedBuilder('', 'form', null, array(
                    'csrf_protection' => false,
                ))
                ->setMethod('GET')
                ->setAction($this->get('router')->generate('search_dispatch'))
                ->setAttributes(array("class" => "form-inline", 'role' => 'search', 'name' => 'search'))
                ->add('bodyStyle', 'choice', array(
                    'choices' => $vehicleChoices,
                    'empty_value' => 'Any Body Style',
                    'label' => "Body Style", "required" => false
                ))
                ->add('model', 'choice', array(
                    'choices' => $vehicleModel,
                    'empty_value' => 'Any Model',
                    'label' => "Model", "required" => false
                ))
                ->add('make', 'choice', array(
                    'choices' => $vehicleMake,
                    'empty_value' => 'Any Make',
                    'label' => "Make", "required" => false
                ))
                ->add('priceFrom', 'text', array('label' => 'Price from', "required" => false))
                ->add('priceTo', 'text', array('label' => 'to', "required" => false))
                ->add('yearFrom', 'choice', array('label' => 'Year from', 'choices' => Util::createYearRangeArray(), "required" => false))
                ->add('yearTo', 'choice', array('label' => 'to', 'choices' => Util::createYearRangeArray(), 'preferred_choices' => array(Util::yearMax), "required" => false))
                ->add('category_id', 'hidden', array('data' => 1))
                ->getForm();

        $marinaBoatType = $lflistc->findAllBy('Boat Type', 2, true, true);
        $marinaBoatMake = $lflistc->findAllBy('Boat Make', 2, true, true);

        $marineForm = $this->get('form.factory')->createNamedBuilder('', 'form', null, array(
                    'csrf_protection' => false,
                ))
                ->setMethod('GET')
                ->setAction($this->get('router')->generate('search_dispatch'))
                ->setAttributes(array("class" => "form-inline", 'role' => 'search', 'name' => 'search'))
                ->add('boatType', 'choice', array(
                    'choices' => $marinaBoatType,
                    'empty_value' => 'Any type',
                    'label' => "Type", "required" => false
                ))
                ->add('boatMake', 'choice', array(
                    'choices' => $marinaBoatMake,
                    'empty_value' => 'Any make',
                    'label' => "Make", "required" => false
                ))
                ->add('boatModel', 'text', array('label' => 'Model', "required" => false))
                ->add('priceFrom', 'text', array('label' => 'Price from', "required" => false))
                ->add('priceTo', 'text', array('label' => 'to', "required" => false))
                ->add('yearFrom', 'choice', array('label' => 'Year from', 'choices' => Util::createYearRangeArray()))
                ->add('yearTo', 'choice', array('label' => 'to', 'choices' => Util::createYearRangeArray(), 'preferred_choices' => array(Util::yearMax)))
                ->add('category_id', 'hidden', array('data' => 2))
                ->getForm();


        $rvMake = $lftreec->findAllBy(760, 4, true, true);
        $rvClasses = $lflistc->findAllBy('type', 4, true, true);


        $rvsForm = $this->get('form.factory')->createNamedBuilder('', 'form', null, array(
                    'csrf_protection' => false,
                ))
                ->setMethod('GET')
                ->setAction($this->get('router')->generate('search_dispatch'))
                ->setAttributes(array("class" => "form-inline", 'role' => 'search', 'name' => 'search'))
                ->add('modelRvs', 'choice', array('label' => 'Model', 'required' => false))
                ->add('makeRvs', 'choice', array(
                    'choices' => $rvMake,
                    'empty_value' => 'Any Make',
                    'label' => "Make", "required" => false
                ))
                ->add('category_id', 'hidden', array('data' => 4, 'required' => false))
                ->add('floorPlan', 'text', array('label' => 'Floor Plan', "required" => false))
                ->add('class', 'choice', array(
                    'choices' => $rvClasses,
                    'empty_value' => 'Any class',
                    'required' => false,
                    'label' => "Class", "required" => false
                ))
                ->add('priceFrom', 'text', array('label' => 'Price from', "required" => false))
                ->add('priceTo', 'text', array('label' => 'to', "required" => false))
                ->add('yearFrom', 'choice', array('label' => 'Year from', 'choices' => Util::createYearRangeArray(), 'required' => false))
                ->add('yearTo', 'choice', array('label' => 'to', 'choices' => Util::createYearRangeArray(), 'required' => false, 'preferred_choices' => array(Util::yearMax)))
                ->getForm();

        $motoMake = $lflistc->findAllBy('make', 3, true, false);
        $motoType = $lflistc->findAllBy('type', 3, true, true);

        $motorsportForm = $this->get('form.factory')->createNamedBuilder('', 'form', null, array(
                    'csrf_protection' => false,
                ))
                ->setMethod('GET')
                ->setAction($this->get('router')->generate('search_dispatch'))
                ->setAttributes(array("class" => "form-inline", 'role' => 'search', 'name' => 'search'))
                ->add('typeString', 'choice', array('label' => 'Type', 'choices' => $motoType, 'empty_value' => 'Any Type'))
                ->add('Model', 'text', array('label' => 'Model', 'required' => false))
                ->add('make', 'choice', array(
                    'choices' => $motoMake,
                    'empty_value' => 'Any Make',
                    'label' => "Make", "required" => false
                ))
                ->add('priceFrom', 'text', array('label' => 'Price from', 'required' => false))
                ->add('priceTo', 'text', array('label' => 'to', 'required' => false))
                ->add('yearFrom', 'choice', array('label' => 'Year from', 'required' => false))
                ->add('yearTo', 'choice', array('label' => 'to', 'required' => false))
                ->add('category_id', 'hidden', array('data' => 3))
                ->getForm();

        $agModel = $lflistc->findAllBy('Ag Application', 13, true);

        $agForm = $this->get('form.factory')->createNamedBuilder('', 'form', null, array(
                    'csrf_protection' => false,
                ))
                ->setMethod('GET')
                ->setAction($this->get('router')->generate('search_dispatch'))
                ->setAttributes(array("class" => "form-inline", 'role' => 'search', 'name' => 'search'))
                //->add('agApplication', 'choice', array('label' => ''))
                //->add('agApplication', 'choice', array('label' => 'Ag Application', 'choices' => $agModel, 'empty_value' => 'Any Ag Application', 'required' => false))
                ->add('Model', 'choice', array('label' => 'Model', 'required' => false))
                //->add('Make', 'choice', array('label' => 'Make','required'=>false))
                ->add('ag_applicationString', 'choice', array('label' => 'Type', 'choices' => $agModel, 'empty_value' => 'Any Make', 'required' => false))
                ->add('priceFrom', 'text', array('label' => 'Price from', 'required' => false))
                ->add('priceTo', 'text', array('label' => 'to', 'required' => false))
                ->add('yearFrom', 'choice', array('label' => 'Year from', 'required' => false))
                ->add('yearTo', 'choice', array('label' => 'to', 'required' => false))
                ->getForm();

        $response = $this->render('NumaDOASiteBundle:Default:index.html.twig', array(
            'tabs' => $tabs,
            'jsonCar' => $jsonCar,
            'jsonRvs' => $jsonRvs,
            'vehicleForm' => $vehicleForm->createView(),
            'motorsportForm' => $motorsportForm->createView(),
            'rvsForm' => $rvsForm->createView(),
            'agForm' => $agForm->createView(),
            'marineForm' => $marineForm->createView()));
        if (!$nocache) {
            $response->setPublic();
            $response->setSharedMaxAge(600);
            $response->setMaxAge(600);
        }
        return $response;
    }

    public function categoriesAction() {

        //$stopwatch = new Stopwatch();
//        $stopwatch->start('eventName');
//        dump($stopwatch);
        $em = $this->getDoctrine()->getManager();
        $categories = $this->get('mymemcache')->get('dealer_categories');

        if (empty($categories)) {
            $categories = $em->getRepository('NumaDOAAdminBundle:Dcategory')->findAll();
        }
        $dealers = $this->get('mymemcache')->get('dealers_count');

        if (empty($dealers)) {
            $dealers=array();
            foreach ($categories as $cat) {
                $dealer = $em->getRepository('NumaDOAAdminBundle:Catalogrecords')->findBy(array('category_id' => $cat->getId()));
                $dealers[$cat->getId()] = $dealer;
            }
        }

//        $event = $stopwatch->stop('eventName');
//        dump($stopwatch);
        return $this->render('NumaDOASiteBundle:Default:categories.html.twig', array('categories' => $categories, 'dealers' => $dealers));
    }

    public function categoryAction(request $request) {
        $em = $this->getDoctrine()->getManager();
        $idCat = $request->get('idcategory');
        $cat_name = $request->get('category_name');
        //$category = $em->getRepository('NumaDOAAdminBundle:Catalogcategory')->findOneById($idCat);
        $catalogs = $em->getRepository('NumaDOAAdminBundle:Catalogrecords')->xfindByDCategory($idCat);
{'fraction_non_alphanumeric': 0.19835721775602935, 'fraction_numerical': 0.0029709891646277527, 'mean_word_length': 2.2370244661292604, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 565, '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': '3223483', 'n_tokens_mistral': 6769, 'n_tokens_neox': 6432, 'n_words': 1206}