<commit_before><?php

/**
 * This file is covered by the AGPLv3 license, which can be found at the LICENSE file in the root of this project.
 * @copyright 2017 subtitulamos.tv
 */

namespace App\Controllers;

use App\Entities\Episode;
use App\Services\Langs;

use Doctrine\ORM\EntityManager;

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Slim\Views\Twig;

class ShowController
{
    public function view($showId, RequestInterface $request, ResponseInterface $response, EntityManager $em, Twig $twig)
    {
        $show = $em->getRepository('App:Show')->find($showId);
        if (!$show) {
            throw new \Slim\Exception\NotFoundException($request, $response);
        }

        $seasonsRes = $em->createQuery('SELECT DISTINCT e.season FROM App:Episode e WHERE e.show = :id ORDER BY e.season ASC')
            ->setParameter('id', $showId)
            ->getResult();

        $seasons = [];
        foreach ($seasonsRes as $seasonRes) {
            $seasons[] = (int)$seasonRes['season'];
        }

        sort($seasons);

        if (empty($seasons)) {
            /*TODO: Error out*/
        }

        // Let's see if the URI contains the season, otherwise, fill it
        $route = $request->getAttribute('route');
        $season = (int)$route->getArgument('season');
        if (!in_array($season, $seasons)) {
            $season = $seasons[0];
        }

        $show = $em->createQuery('SELECT sw, e, v, s FROM App:Show sw JOIN sw.episodes e JOIN e.versions v JOIN v.subtitles s WHERE sw.id = :id AND e.season = :season ORDER BY e.number ASC')
            ->setParameter('id', $showId)
            ->setParameter('season', $season)
            ->getOneOrNullResult();

        if (!$show) {
            throw new \Slim\Exception\NotFoundException($request, $response);
        }

        $episodeList = [];
        foreach ($show->getEpisodes() as $ep) {
            $epInfo = [
                'id' => $ep->getId(),<commit_msg>Display last season by default on show view<commit_after><?php

/**
 * This file is covered by the AGPLv3 license, which can be found at the LICENSE file in the root of this project.
 * @copyright 2017 subtitulamos.tv
 */

namespace App\Controllers;

use App\Entities\Episode;
use App\Services\Langs;

use Doctrine\ORM\EntityManager;

use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Slim\Views\Twig;

class ShowController
{
    public function view($showId, RequestInterface $request, ResponseInterface $response, EntityManager $em, Twig $twig)
    {
        $show = $em->getRepository('App:Show')->find($showId);
        if (!$show) {
            throw new \Slim\Exception\NotFoundException($request, $response);
        }

        $seasonsRes = $em->createQuery('SELECT DISTINCT e.season FROM App:Episode e WHERE e.show = :id ORDER BY e.season ASC')
            ->setParameter('id', $showId)
            ->getResult();

        $seasons = [];
        foreach ($seasonsRes as $seasonRes) {
            $seasons[] = (int)$seasonRes['season'];
        }

        sort($seasons);

        if (empty($seasons)) {
            /*TODO: Error out*/
        }

        // Let's see if the URI contains the season, otherwise, fill it
        $route = $request->getAttribute('route');
        $season = (int)$route->getArgument('season');
        if (!in_array($season, $seasons)) {
            $season = $seasons[count($seasons) - 1];
        }

        $show = $em->createQuery('SELECT sw, e, v, s FROM App:Show sw JOIN sw.episodes e JOIN e.versions v JOIN v.subtitles s WHERE sw.id = :id AND e.season = :season ORDER BY e.number ASC')
            ->setParameter('id', $showId)
            ->setParameter('season', $season)
            ->getOneOrNullResult();

        if (!$show) {
            throw new \Slim\Exception\NotFoundException($request, $response);
        }

        $episodeList = [];
        foreach ($show->getEpisodes() as $ep) {
            $epInfo = [
                'id' => $ep->getId(),
{'fraction_non_alphanumeric': 0.139234211834908, 'fraction_numerical': 0.0029835902536051715, 'mean_word_length': 2.4591573516766982, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '503247', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1185, 'n_words': 323}