<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 \Psr\Http\Message\ResponseInterface;
use \Psr\Http\Message\RequestInterface;

use Doctrine\ORM\EntityManager;

use \Slim\Views\Twig;
use App\Entities\Episode;
use App\Services\Langs;

class EpisodeController
{
    public function view($id, RequestInterface $request, ResponseInterface $response, EntityManager $em, Twig $twig)
    {
        $ep = $em->createQuery("SELECT s, v, e FROM App:Episode e JOIN e.versions v JOIN v.subtitles s WHERE e.id = :id")
                   ->setParameter("id", $id)
                   ->getOneOrNullResult();
        
        if (!$ep) {
            throw new \Slim\Exception\NotFoundException($request, $response);
        }

        $langs = [];
        foreach ($ep->getVersions() as $version) {
            foreach ($version->getSubtitles() as $sub) {
                $lang = Langs::getLangCode($sub->getLang());
                if (!isset($langs[$lang])) {
                    $langs[$lang] = [];
                }

                $langs[$lang][] = $sub;
            }
        }
        
        return $twig->render($response, 'episode.twig', [
            'episode' => $ep,
            'langs' => $langs,
            'uploader_name' => "user"
        ]);
    }
}<commit_msg>Lang names on episode view are no longer the lang codes<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 \Psr\Http\Message\ResponseInterface;
use \Psr\Http\Message\RequestInterface;

use Doctrine\ORM\EntityManager;

use \Slim\Views\Twig;
use App\Entities\Episode;
use App\Services\Langs;

class EpisodeController
{
    public function view($id, RequestInterface $request, ResponseInterface $response, EntityManager $em, Twig $twig)
    {
        $ep = $em->createQuery("SELECT s, v, e FROM App:Episode e JOIN e.versions v JOIN v.subtitles s WHERE e.id = :id")
                   ->setParameter("id", $id)
                   ->getOneOrNullResult();
        
        if (!$ep) {
            throw new \Slim\Exception\NotFoundException($request, $response);
        }

        $langs = [];
        foreach ($ep->getVersions() as $version) {
            foreach ($version->getSubtitles() as $sub) {
                $lang = Langs::getLocalizedName(Langs::getLangCode($sub->getLang()));
                if (!isset($langs[$lang])) {
                    $langs[$lang] = [];
                }

                $langs[$lang][] = $sub;
            }
        }
        
        return $twig->render($response, 'episode.twig', [
            'episode' => $ep,
            'langs' => $langs,
            'uploader_name' => "user"
        ]);
    }
}
{'fraction_non_alphanumeric': 0.13675213675213677, 'fraction_numerical': 0.003418803418803419, 'mean_word_length': 2.096296296296296, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '3207573', 'n_tokens_mistral': 899, 'n_tokens_neox': 871, 'n_words': 218}