Completed
Push — master ( 911a15...50617c )
by Julito
30:21
created

LegacyController   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 9

Importance

Changes 0
Metric Value
dl 0
loc 107
rs 10
c 0
b 0
f 0
wmc 10
lcom 0
cbo 9

1 Method

Rating   Name   Duplication   Size   Complexity  
D classicAction() 0 97 10
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Controller;
5
6
use Chamilo\CourseBundle\Controller\ToolBaseController;
7
use Doctrine\DBAL\Connection;
8
use Symfony\Component\HttpFoundation\Response;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
11
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
12
use Chamilo\CoreBundle\Framework\Container;
13
use Display;
14
15
/**
16
 * Class LegacyController
17
 * Manages the chamilo pages starting with Display::display_header and $tpl = new Template();
18
 * @package Chamilo\CoreBundle\Controller
19
 * @author Julio Montoya <[email protected]>
20
 */
21
class LegacyController extends ToolBaseController
22
{
23
    public $section;
24
25
    /**
26
     * @param string $name
27
     * @param Request $request
28
     * @return Response
29
     */
30
    public function classicAction($name, Request $request)
31
    {
32
        // get.
33
        $_GET = $request->query->all();
34
        // post.
35
        $_POST = $request->request->all();
36
37
        $rootDir = $this->get('kernel')->getRealRootDir();
38
39
        //$_REQUEST = $request->request->all();
40
        $mainPath = $rootDir.'main/';
41
        $fileToLoad = $mainPath.$name;
42
43
        // Setting legacy values inside the container
44
45
        /** @var Connection $dbConnection */
46
        $dbConnection = $this->container->get('database_connection');
47
        $em = $this->get('kernel')->getContainer()->get('doctrine.orm.entity_manager');
48
49
        $database = new \Database($dbConnection, array());
50
51
        $database->setConnection($dbConnection);
52
        $database->setManager($em);
53
        Container::$container = $this->container;
54
        Container::$dataDir = $this->container->get('kernel')->getDataDir();
55
        Container::$courseDir = $this->container->get('kernel')->getDataDir();
56
        //Container::$configDir = $this->container->get('kernel')->getConfigDir();
57
        $this->container->get('twig')->addGlobal('api_get_cidreq', api_get_cidreq());
58
59
        //$breadcrumb = $this->container->get('chamilo_core.block.breadcrumb');
60
61
        if (is_file($fileToLoad) &&
62
            \Security::check_abs_path($fileToLoad, $mainPath)
63
        ) {
64
            // Files inside /main need this variables to be set
65
            $is_allowed_in_course = api_is_allowed_in_course();
66
            $is_courseAdmin = api_is_course_admin();
67
            $is_platformAdmin = api_is_platform_admin();
68
69
            $toolNameFromFile = basename(dirname($fileToLoad));
70
            $charset = 'UTF-8';
71
            // Default values
72
            $_course = api_get_course_info();
73
            $_user = api_get_user_info();
74
            $debug = $this->container->get('kernel')->getEnvironment() == 'dev' ? true : false;
75
76
            // Loading file
77
            ob_start();
78
            require_once $fileToLoad;
79
            $out = ob_get_contents();
80
            ob_end_clean();
81
82
            // No browser cache when executing an exercise.
83
            if ($name == 'exercise/exercise_submit.php') {
84
                $responseHeaders = array(
85
                    'cache-control' => 'no-store, no-cache, must-revalidate'
86
                );
87
            }
88
89
            $js = isset($htmlHeadXtra) ? $htmlHeadXtra : array();
0 ignored issues
show
Bug introduced by
The variable $htmlHeadXtra seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
90
91
            // $interbreadcrumb is loaded in the require_once file.
92
            $interbreadcrumb = isset($interbreadcrumb) ? $interbreadcrumb : null;
0 ignored issues
show
Bug introduced by
The variable $interbreadcrumb seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
93
94
            $template = Container::$legacyTemplate;
95
            $defaultLayout = '@ChamiloTheme/Layout/layout_one_col.html.twig';
96
            if (!empty($template)) {
97
                $defaultLayout = $template;
98
            }
99
100
            $params = [
101
                'legacy_breadcrumb' => $interbreadcrumb,
102
                'js' => $js
103
            ];
104
105
            // This means the page comes from legacy use Display::display_header
106
            if (!empty($out)) {
107
                $params['content'] = $out;
108
            } else {
109
                // This means the page comes from legacy use of new Template()
110
                $legacyParams = \Template::$params;
111
                if (!empty($legacyParams)) {
112
                    $params = array_merge($legacyParams, $params);
113
                }
114
            }
115
116
            // Render using Symfony2 layouts see folder:
117
            // src/Chamilo/ThemeBundle/Resources/views/Layout
118
            return $this->render(
119
                $defaultLayout,
120
                $params
121
            );
122
        } else {
123
            // Found does not exist
124
            throw new NotFoundHttpException();
125
        }
126
    }
127
}
128