<commit_before><?php

namespace App\Controller\City;

use App\Annotation\ReverseProxy;
use App\App\Location;
use App\Controller\TBNController as BaseController;
use App\Entity\Agenda;
use App\Social\Twitter;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
 * Description of MenuDroitController.
 *
 * @author guillaume
 */
class WidgetsController extends BaseController
{
    const FB_MEMBERS_LIMIT = 100;

    const TWEET_LIMIT = 25;

    const WIDGET_ITEM_LIMIT = 7;

    /**
     * @Route("/tweeter-feed/{max_id}", name="app_agenda_tweeter_feed", requirements={"max_id": "\d+"})
     * @ReverseProxy(expires="1 hour")
     */
    public function twitterAction(Location $location, Twitter $twitter, RequestStack $requestStack, $max_id = null)
    {
        $results = $twitter->getTimeline($location, $max_id, self::TWEET_LIMIT);

        $nextLink = null;
        if (isset($results['search_metadata']['next_results'])) {
            \parse_str($results['search_metadata']['next_results'], $infos);

            if (isset($infos['?max_id'])) {
                $nextLink = $this->generateUrl('app_agenda_tweeter_feed', [
                    'location' => $location->getSlug(),
                    'max_id' => $infos['?max_id'],
                ]);
            }
        }

        if (!isset($results['statuses'])) {
            $results['statuses'] = [];
        }

        if (!\count($results['statuses']) && null === $requestStack->getParentRequest()) {
            return $this->redirectToRoute('app_agenda_agenda', ['location' => $location->getSlug()], Response::HTTP_MOVED_PERMANENTLY);
        }

        return $this->render('City/Hinclude/tweets.html.twig', [
            'tweets' => $results['statuses'],
            'hasNextLink' => $nextLink,
            'location' => $location
        ]);
    }

    /**
     * @Route("/soiree/{slug}--{id}/prochaines-soirees/{page}", name="app_agenda_prochaines_soirees", requirements={"slug": "[^/]+", "id": "\d+", "page": "\d+"})
     * @ReverseProxy(expires="tomorrow")
     */
    public function nextEventsAction(Location $location, $slug, $id = null, $page = 1)
    {
        $result = $this->checkEventUrl($location->getSlug(), $slug, $id, 'app_agenda_prochaines_soirees', [
            'page' => $page,
        ]);

        if ($result instanceof Response) {
            return $result;
        }
        $soiree = $result;

        if (!$soiree->getPlace()) {
            return $this->redirectToRoute('app_agenda_details', [
                'id' => $soiree->getId(),
                'slug' => $soiree->getSlug(),
                'location' => $location->getSlug(),
            ], Response::HTTP_MOVED_PERMANENTLY);
        }

        $em = $this->getDoctrine()->getManager();
        $repo = $em->getRepository(Agenda::class);

        $count = $repo->findAllNextCount($soiree);
        $current = $page * self::WIDGET_ITEM_LIMIT;

        if ($current < $count) {
            $hasNextLink = $this->generateUrl('app_agenda_prochaines_soirees', [<commit_msg>Removed unused check<commit_after><?php

namespace App\Controller\City;

use App\Annotation\ReverseProxy;
use App\App\Location;
use App\Controller\TBNController as BaseController;
use App\Entity\Agenda;
use App\Social\Twitter;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
 * Description of MenuDroitController.
 *
 * @author guillaume
 */
class WidgetsController extends BaseController
{
    const FB_MEMBERS_LIMIT = 100;

    const TWEET_LIMIT = 25;

    const WIDGET_ITEM_LIMIT = 7;

    /**
     * @Route("/tweeter-feed/{max_id}", name="app_agenda_tweeter_feed", requirements={"max_id": "\d+"})
     * @ReverseProxy(expires="1 hour")
     */
    public function twitterAction(Location $location, Twitter $twitter, RequestStack $requestStack, $max_id = null)
    {
        $results = $twitter->getTimeline($location, $max_id, self::TWEET_LIMIT);

        $nextLink = null;
        if (isset($results['search_metadata']['next_results'])) {
            \parse_str($results['search_metadata']['next_results'], $infos);

            if (isset($infos['?max_id'])) {
                $nextLink = $this->generateUrl('app_agenda_tweeter_feed', [
                    'location' => $location->getSlug(),
                    'max_id' => $infos['?max_id'],
                ]);
            }
        }

        if (!isset($results['statuses'])) {
            $results['statuses'] = [];
        }

        if (!\count($results['statuses']) && null === $requestStack->getParentRequest()) {
            return $this->redirectToRoute('app_agenda_agenda', ['location' => $location->getSlug()], Response::HTTP_MOVED_PERMANENTLY);
        }

        return $this->render('City/Hinclude/tweets.html.twig', [
            'tweets' => $results['statuses'],
            'hasNextLink' => $nextLink,
            'location' => $location
        ]);
    }

    /**
     * @Route("/soiree/{slug}--{id}/prochaines-soirees/{page}", name="app_agenda_prochaines_soirees", requirements={"slug": "[^/]+", "id": "\d+", "page": "\d+"})
     * @ReverseProxy(expires="tomorrow")
     */
    public function nextEventsAction(Location $location, $slug, $id = null, $page = 1)
    {
        $result = $this->checkEventUrl($location->getSlug(), $slug, $id, 'app_agenda_prochaines_soirees', [
            'page' => $page,
        ]);

        if ($result instanceof Response) {
            return $result;
        }
        $soiree = $result;

        $em = $this->getDoctrine()->getManager();
        $repo = $em->getRepository(Agenda::class);

        $count = $repo->findAllNextCount($soiree);
        $current = $page * self::WIDGET_ITEM_LIMIT;

        if ($current < $count) {
            $hasNextLink = $this->generateUrl('app_agenda_prochaines_soirees', [
{'fraction_non_alphanumeric': 0.16717120753447695, 'fraction_numerical': 0.0026908846283215607, 'mean_word_length': 2.82443729903537, 'pattern_counts': {'":': 8, '<': 7, '<?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': '1874523', 'n_tokens_mistral': 1893, 'n_tokens_neox': 1854, 'n_words': 291}