<commit_before><?php

namespace CanalTP\MttBundle\Controller;

class DefaultController extends AbstractController
{
    private function findNetwork($externalNetworkId, $networks)
    {
        foreach ($networks as $network) {
            if ($network['external_id'] == $externalNetworkId) {
                return $network;
            }
        }
        throw new \Exception(
            $this->get('translator')->trans(
                'controller.default.network_not_found_4_user',
                array(),
                'exceptions'
            )
        );

    }

    public function indexAction($externalNetworkId = null)
    {
        $networkManager = $this->get('canal_tp_mtt.network_manager');
        $mtt_user = $this->get('canal_tp_mtt.user');

        // TODO: Put the current or default Network of User.
        $networks = $mtt_user->getNetworks(
            $this->get('security.context')->getToken()->getUser()
        );
        $currentNetwork =
            $externalNetworkId == null ?
            $networks[0] :
            $this->findNetwork($externalNetworkId, $networks);
        // make currentNetwok a doctrine object
        $currentNetwork = $networkManager->find($currentNetwork);

        return $this->render(
            'CanalTPMttBundle:Default:index.html.twig',
            array(
                'currentNetwork'    => $currentNetwork,
                'tasks'             => $networkManager->getLastTasks($currentNetwork),
                'externalNetworkId' => $currentNetwork->getExternalId()
            )
        );
    }

    public function navigationAction($externalNetworkId, $current_season, $current_route = null)
    {
        // TODO: Put the default Network of User. (for $externalNetworkId)
        $mtt_navitia = $this->get('canal_tp_mtt.navitia');
        $networkManager = $this->get('canal_tp_mtt.network_manager');
        $network = $networkManager->findOneByExternalId($externalNetworkId);

        $result = $mtt_navitia->findAllLinesByMode(
            $network->getExternalCoverageId(),
            $network->getExternalId()
        );

        return $this->render(
            'CanalTPMttBundle:Default:navigation.html.twig',
            array(
                'result' => $result,
                'coverageId' => $network->getExternalCoverageId(),
                'current_route' => $current_route,
                'current_season' => $current_season
            )
        );
    }
}<commit_msg>METH-122 adding flashbag when rendering menu throws an exception<commit_after><?php

namespace CanalTP\MttBundle\Controller;

class DefaultController extends AbstractController
{
    private function findNetwork($externalNetworkId, $networks)
    {
        foreach ($networks as $network) {
            if ($network['external_id'] == $externalNetworkId) {
                return $network;
            }
        }
        throw new \Exception(
            $this->get('translator')->trans(
                'controller.default.network_not_found_4_user',
                array(),
                'exceptions'
            )
        );

    }

    public function indexAction($externalNetworkId = null)
    {
        $networkManager = $this->get('canal_tp_mtt.network_manager');
        $mtt_user = $this->get('canal_tp_mtt.user');

        // TODO: Put the current or default Network of User.
        $networks = $mtt_user->getNetworks(
            $this->get('security.context')->getToken()->getUser()
        );
        $currentNetwork =
            $externalNetworkId == null ?
            $networks[0] :
            $this->findNetwork($externalNetworkId, $networks);
        // make currentNetwok a doctrine object
        $currentNetwork = $networkManager->find($currentNetwork);

        return $this->render(
            'CanalTPMttBundle:Default:index.html.twig',
            array(
                'currentNetwork'    => $currentNetwork,
                'tasks'             => $networkManager->getLastTasks($currentNetwork),
                'externalNetworkId' => $currentNetwork->getExternalId()
            )
        );
    }

    public function navigationAction($externalNetworkId, $current_season, $current_route = null)
    {
        // TODO: Put the default Network of User. (for $externalNetworkId)
        $mtt_navitia = $this->get('canal_tp_mtt.navitia');
        $networkManager = $this->get('canal_tp_mtt.network_manager');
        $network = $networkManager->findOneByExternalId($externalNetworkId);
        try {
            $result = $mtt_navitia->findAllLinesByMode(
                $network->getExternalCoverageId(),
                $network->getExternalId()
            );
        } catch(\Exception $e) {
            $errorMessage = $e->getMessage();
            $result = array();
            $this->get('session')->getFlashBag()->add(
                'danger',
                $errorMessage
            );
        }
        return $this->render(
            'CanalTPMttBundle:Default:navigation.html.twig',
            array(
                'result'            => $result,
                'coverageId'        => $network->getExternalCoverageId(),
                'current_route'     => $current_route,
                'current_season'    => $current_season
            )
        );
    }
}
{'fraction_non_alphanumeric': 0.12083333333333333, 'fraction_numerical': 0.0013257575757575758, 'mean_word_length': 1.981931112365895, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 63, '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': '4869561', 'n_tokens_mistral': 1440, 'n_tokens_neox': 1397, 'n_words': 232}