<commit_before><?php

namespace WebsiteBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use JMS\DiExtraBundle\Annotation as DI;
use WebsiteBundle\Services\Utils;


class DefaultController
{

    private $solrService;
    private $templating;
    private $mobileDetect;
    /**
     * @DI\InjectParams({
     *     "solrService" = @DI\Inject("solrService"),
     *     "templating" = @DI\Inject("templating"),
     *     "mobileDetect" = @DI\Inject("mobile_detect.mobile_detector")
     * })
     */
    public function __construct($solrService, $templating, $mobileDetect){
        $this->solrService = $solrService;
        $this->templating = $templating;
        $this->mobileDetect = $mobileDetect;
    }

    /**
     * @Route("/", name="homepage")
     * @Method("GET")
     */
    public function indexAction(Request $request)
    {
        $utils = new Utils;
        $_torrents = $this->solrService->popularAction();
        $torrents = $utils->makeTorrentsObject($_torrents);

        $templatePath = ($this->mobileDetect->isMobile()) ? "mobile/index.html.twig" : "default/index.html.twig" ;
        $tpl = $this->templating->render($templatePath, array("torrents" => $torrents));

        return new Response($tpl);
    }

    /**
     * @Route("/search", name="search")
     * @Method("GET")
     */
    public function searchAction(Request $request){
        $query = $request->query->get("query");
        $offset = ($request->query->get("offset")) ? $request->query->get("offset") : 1;
        $limit = 25;
        $utils = new Utils();
        $result = $this->solrService->searchAction($query, $limit, $offset);
        $torrents = $utils->makeTorrentsObject($result["torrents"]);

        $nbMaxPages = ($result["nbTorrentsFound"] > 10) ? 10 : $result["nbTorrentsFound"];
        $offset = ($offset < $nbMaxPages) ? $offset : $nbMaxPages;

        $templatePath = ($this->mobileDetect->isMobile()) ? "mobile/search-results.html.twig" : "default/search-results.html.twig" ;
        $tpl = $this->templating->render($templatePath,
            array("torrents" => $torrents,
                  "query" => $result["query"],
                  "pages" => $utils->createPagination($nbMaxPages, $offset),
                  "previousPage" => ($offset - 1),
                  "nextPage" => ($offset + 1),
                  "nbMaxPages" => $nbMaxPages)
        );

        return new Response($tpl);

    }

    /**
     * @Route("/torrent/{tracker}/{slug}", name="details")
     * @Method("GET")
     */
    public function torrentAction($tracker, $slug){
        $utils = new Utils();
        $torrent = $this->solrService->torrentAction($tracker, $slug);
        $moreLikeThis = $this->solrService->searchSimilarAction($slug);
        $similarTorrents = $utils->makeTorrentsObject($moreLikeThis);

        $templatePath = ($this->mobileDetect->isMobile()) ? "mobile/torrent-detail.html.twig" : "default/torrent-detail.html.twig" ;
        $tpl = $this->templating->render($templatePath,
            array("torrent" => $torrent,
                "similarTorrents" => $similarTorrents));
        return new Response($tpl);
    }

    /**
     * @Route("/torrents/{category}", name="torrentsPerCategory")
     * @Method("GET")
     */
    public function torrentsByCategoryAction($category, Request $request){
        $utils = new Utils();
        $offset = ($request->query->get("offset")) ? abs($request->query->get("offset")) : 1;
        $limit = 25;
        $nbMaxPages = 20;
        $offset = ($offset < $nbMaxPages) ? $offset : $nbMaxPages;
        $torrents = $utils->makeTorrentsObject($this->solrService->torrentsByCategoryAction($category, $offset, $limit));
        $templatePath = ($this->mobileDetect->isMobile()) ? "mobile/torrents-category.html.twig" : "default/torrent-category.html.twig" ;

        $tpl = $this->templating->render($templatePath,
            array("torrents" => $torrents,
                  "pages" => $utils->createPagination($nbMaxPages, $offset),
                  "previousPage" => ($offset - 1),
                  "nextPage" => ($offset + 1),
                  "nbMaxPages" => $nbMaxPages,
                  "category" => $category,
                  "categoryIcon" => $utils->getCategoryIconName($category),
                  "categoryName" => $utils->getCategoryName($category)
            ));
        return new Response($tpl);
    }

    public function headerAction(){
        $templatePath = ($this->mobileDetect->isMobile()) ? "mobile/header.html.twig" : "default/header.html.twig" ;
        $tpl = $this->templating->render($templatePath, $this->solrService->statsTrackersAction());
        return new Response($tpl);
    }

    public function footerAction(){<commit_msg>fix bug categories<commit_after><?php

namespace WebsiteBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use JMS\DiExtraBundle\Annotation as DI;
use WebsiteBundle\Services\Utils;


class DefaultController
{

    private $solrService;
    private $templating;
    private $mobileDetect;
    /**
     * @DI\InjectParams({
     *     "solrService" = @DI\Inject("solrService"),
     *     "templating" = @DI\Inject("templating"),
     *     "mobileDetect" = @DI\Inject("mobile_detect.mobile_detector")
     * })
     */
    public function __construct($solrService, $templating, $mobileDetect){
        $this->solrService = $solrService;
        $this->templating = $templating;
        $this->mobileDetect = $mobileDetect;
    }

    /**
     * @Route("/", name="homepage")
     * @Method("GET")
     */
    public function indexAction(Request $request)
    {
        $utils = new Utils;
        $_torrents = $this->solrService->popularAction();
        $torrents = $utils->makeTorrentsObject($_torrents);

        $templatePath = ($this->mobileDetect->isMobile()) ? "mobile/index.html.twig" : "default/index.html.twig" ;
        $tpl = $this->templating->render($templatePath, array("torrents" => $torrents));

        return new Response($tpl);
    }

    /**
     * @Route("/search", name="search")
     * @Method("GET")
     */
    public function searchAction(Request $request){
        $query = $request->query->get("query");
        $offset = ($request->query->get("offset")) ? $request->query->get("offset") : 1;
        $limit = 25;
        $utils = new Utils();
        $result = $this->solrService->searchAction($query, $limit, $offset);
        $torrents = $utils->makeTorrentsObject($result["torrents"]);

        $nbMaxPages = ($result["nbTorrentsFound"] > 10) ? 10 : $result["nbTorrentsFound"];
        $offset = ($offset < $nbMaxPages) ? $offset : $nbMaxPages;

        $templatePath = ($this->mobileDetect->isMobile()) ? "mobile/search-results.html.twig" : "default/search-results.html.twig" ;
        $tpl = $this->templating->render($templatePath,
            array("torrents" => $torrents,
                  "query" => $result["query"],
                  "pages" => $utils->createPagination($nbMaxPages, $offset),
                  "previousPage" => ($offset - 1),
                  "nextPage" => ($offset + 1),
                  "nbMaxPages" => $nbMaxPages)
        );

        return new Response($tpl);

    }

    /**
     * @Route("/torrent/{tracker}/{slug}", name="details")
     * @Method("GET")
     */
    public function torrentAction($tracker, $slug){
        $utils = new Utils();
        $torrent = $this->solrService->torrentAction($tracker, $slug);
        $moreLikeThis = $this->solrService->searchSimilarAction($slug);
        $similarTorrents = $utils->makeTorrentsObject($moreLikeThis);

        $templatePath = ($this->mobileDetect->isMobile()) ? "mobile/torrent-detail.html.twig" : "default/torrent-detail.html.twig" ;
        $tpl = $this->templating->render($templatePath,
            array("torrent" => $torrent,
                "similarTorrents" => $similarTorrents));
        return new Response($tpl);
    }

    /**
     * @Route("/torrents/{category}", name="torrentsPerCategory")
     * @Method("GET")
     */
    public function torrentsByCategoryAction($category, Request $request){
        $utils = new Utils();
        $offset = ($request->query->get("offset")) ? abs($request->query->get("offset")) : 1;
        $limit = 25;
        $nbMaxPages = 20;
        $offset = ($offset < $nbMaxPages) ? $offset : $nbMaxPages;
        $torrents = $utils->makeTorrentsObject($this->solrService->torrentsByCategoryAction($category, $offset, $limit));
        $templatePath = ($this->mobileDetect->isMobile()) ? "mobile/torrents-category.html.twig" : "default/torrents-category.html.twig" ;

        $tpl = $this->templating->render($templatePath,
            array("torrents" => $torrents,
                  "pages" => $utils->createPagination($nbMaxPages, $offset),
                  "previousPage" => ($offset - 1),
                  "nextPage" => ($offset + 1),
                  "nbMaxPages" => $nbMaxPages,
                  "category" => $category,
                  "categoryIcon" => $utils->getCategoryIconName($category),
                  "categoryName" => $utils->getCategoryName($category)
            ));
        return new Response($tpl);
    }

    public function headerAction(){
        $templatePath = ($this->mobileDetect->isMobile()) ? "mobile/header.html.twig" : "default/header.html.twig" ;
        $tpl = $this->templating->render($templatePath, $this->solrService->statsTrackersAction());
        return new Response($tpl);
    }

    public function footerAction(){
{'fraction_non_alphanumeric': 0.16543402101985208, 'fraction_numerical': 0.003114052160373686, 'mean_word_length': 2.915047619047619, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 145, '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': '3865178', 'n_tokens_mistral': 3128, 'n_tokens_neox': 3043, 'n_words': 473}