<commit_before><?php

namespace Oro\Bundle\DashboardBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Oro\Bundle\DashboardBundle\Manager;

class DashboardController extends Controller
{
    /**
     * @Route(
     *      "/index/{name}",
     *      name="oro_dashboard_index",
     *      requirements={"name"="[\w-]*"},
     *      defaults={"name" = ""}
     * )
     */
    public function indexAction($name = null)
    {
        /** @var Manager $manager */
        $manager = $this->get('oro_dashboard.manager');
        if (empty($name)) {
            $name = $manager->getDefaultDashboardName();
        }
        /**
         * @todo: change work with session after user state will be implement
         */
        if ($this->get('request')->get('change_dashboard', false)) {
            $this->get('session')->set('saved_dashboard', $name);
        } else {
            $name = $this->get('session')->get('saved_dashboard', $manager->getDefaultDashboardName());
        }

        $template  = isset($dashboard['twig']) ? $dashboard['twig'] : 'OroDashboardBundle:Index:default.html.twig';

        $dashboards = $manager->getDashboards();

        foreach ($dashboards as $dashboard) {
            //todo: stub (must be rewrite)
            if ($dashboard->getDashboard()->getName() == $name) {
                break;
            }
        }

        return $this->render(
            $template,
            [
                'pageTitle'     => $dashboard->getConfig()['label'],
                'dashboardName' => $name,
                'dashboards'    => $dashboards,
                'widgets'       => $dashboard->getWidgets(),
            ]
        );
    }

    /**
     * @Route(
     *      "/widget/{widget}/{bundle}/{name}",
     *      name="oro_dashboard_widget",<commit_msg>BAP-3904: Modify manager to support getting dashboard and widgets<commit_after><?php

namespace Oro\Bundle\DashboardBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Oro\Bundle\DashboardBundle\Manager;

class DashboardController extends Controller
{
    /**
     * @Route(
     *      "/index/{name}",
     *      name="oro_dashboard_index",
     *      requirements={"name"="[\w-]*"},
     *      defaults={"name" = ""}
     * )
     */
    public function indexAction($name = null)
    {
        /** @var Manager $manager */
        $manager = $this->get('oro_dashboard.manager');
        if (empty($name)) {
            $name = $manager->getDefaultDashboardName();
        }
        /**
         * @todo: change work with session after user state will be implement
         */
        if ($this->get('request')->get('change_dashboard', false)) {
            $this->get('session')->set('saved_dashboard', $name);
        } else {
            $name = $this->get('session')->get('saved_dashboard', $manager->getDefaultDashboardName());
        }



        $dashboards = $manager->getDashboards();

        foreach ($dashboards as $dashboard) {
            //todo: stub (must be rewrite)
            if ($dashboard->getDashboard()->getName() == $name) {
                break;
            }
        }
        //todo: stub (must be rewrite)
        $config = $dashboard->getConfig();

        $template  = isset($config['twig']) ? $config['twig'] : 'OroDashboardBundle:Index:default.html.twig';

        return $this->render(
            $template,
            [
                'pageTitle'     => $config['label'],
                'dashboardName' => $name,
                'dashboards'    => $dashboards,
                'widgets'       => $dashboard->getWidgets(),
            ]
        );
    }

    /**
     * @Route(
     *      "/widget/{widget}/{bundle}/{name}",
     *      name="oro_dashboard_widget",
{'fraction_non_alphanumeric': 0.1576980568011958, 'fraction_numerical': 0.000996512207274539, 'mean_word_length': 2.1075851393188856, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 41, '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': '7249661', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1140, 'n_words': 186}