1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
6
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Controller; |
8
|
|
|
|
9
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; |
10
|
|
|
use Symfony\Component\HttpFoundation\Request; |
11
|
|
|
use Symfony\Component\HttpFoundation\Response; |
12
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
13
|
|
|
|
14
|
|
|
class IndexController extends BaseController |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @Route("/", name="index", methods={"GET", "POST"}, options={"expose"=true}) |
18
|
|
|
* @Route("/home", name="home", methods={"GET", "POST"}, options={"expose"=true}) |
19
|
|
|
* @Route("/login", name="login", methods={"GET", "POST"}, options={"expose"=true}) |
20
|
|
|
* |
21
|
|
|
* @Route("/course/{cid}/home", name="chamilo_core_course_home") |
22
|
|
|
* @Route("/courses", name="courses", methods={"GET", "POST"}, options={"expose"=true}) |
23
|
|
|
* |
24
|
|
|
* @Route("/sessions", name="sessions", methods={"GET", "POST"}, options={"expose"=true}) |
25
|
|
|
* @Route("/catalog/{slug}", name="catalog", methods={"GET", "POST"}, options={"expose"=true}) |
26
|
|
|
* @Route("/resources/document/{nodeId}/manager", methods={"GET"}, name="resources_filemanager") |
27
|
|
|
* @Route("/account/home", name="account", options={"expose"=true}, name="chamilo_core_account_home") |
28
|
|
|
*/ |
29
|
|
|
public function indexAction(): Response |
30
|
|
|
{ |
31
|
|
|
return $this->render('@ChamiloCore/Index/vue.html.twig'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Toggle the student view action. |
36
|
|
|
* |
37
|
|
|
* @Route("/toggle_student_view", methods={"GET"}) |
38
|
|
|
* |
39
|
|
|
* @Security("is_granted('ROLE_TEACHER')") |
40
|
|
|
*/ |
41
|
|
|
public function toggleStudentViewAction(Request $request): Response |
42
|
|
|
{ |
43
|
|
|
if (!api_is_allowed_to_edit(false, false, false, false)) { |
44
|
|
|
throw $this->createAccessDeniedException(); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
$studentView = $request->getSession()->get('studentview'); |
48
|
|
|
if (empty($studentView) || 'studentview' === $studentView) { |
49
|
|
|
$content = 'teacherview'; |
50
|
|
|
$request->getSession()->set('studentview', $content); |
51
|
|
|
} else { |
52
|
|
|
$content = 'studentview'; |
53
|
|
|
$request->getSession()->set('studentview', $content); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return new Response($content); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Use only in PHPUnit tests. |
61
|
|
|
*/ |
62
|
|
|
public function classic($name): Response |
63
|
|
|
{ |
64
|
|
|
if (1 !== (int) $_ENV['APP_DEBUG']) { |
65
|
|
|
exit; |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$rootDir = $this->getParameter('kernel.project_dir'); |
69
|
|
|
|
70
|
|
|
$mainPath = $rootDir.'/public/main/'; |
71
|
|
|
$fileToLoad = $mainPath.$name; |
72
|
|
|
|
73
|
|
|
ob_start(); |
74
|
|
|
require_once $fileToLoad; |
75
|
|
|
$content = ob_get_contents(); |
76
|
|
|
ob_end_clean(); |
77
|
|
|
|
78
|
|
|
return $this->render( |
79
|
|
|
'@ChamiloCore/Layout/layout_one_col.html.twig', |
80
|
|
|
['content' => $content] |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: