|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
|
4
|
|
|
|
|
5
|
|
|
namespace Chamilo\CoreBundle\Controller; |
|
6
|
|
|
|
|
7
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; |
|
8
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
9
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
10
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
|
11
|
|
|
use Symfony\Component\Serializer\Encoder\JsonEncoder; |
|
12
|
|
|
use Symfony\Component\Serializer\SerializerInterface; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* Class IndexController |
|
16
|
|
|
* author Julio Montoya <[email protected]>. |
|
17
|
|
|
*/ |
|
18
|
|
|
class IndexController extends BaseController |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* The Chamilo index home page. |
|
22
|
|
|
* |
|
23
|
|
|
* @Route("/", name="home", methods={"GET", "POST"}, options={"expose"=true}) |
|
24
|
|
|
*/ |
|
25
|
|
|
public function indexAction(SerializerInterface $serializer): Response |
|
26
|
|
|
{ |
|
27
|
|
|
$user = $this->getUser(); |
|
28
|
|
|
$data = null; |
|
29
|
|
|
if (!empty($user)) { |
|
30
|
|
|
$userClone = clone $user; |
|
31
|
|
|
$userClone->setPassword(''); |
|
32
|
|
|
$data = $serializer->serialize($userClone, JsonEncoder::FORMAT); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
return $this->render( |
|
36
|
|
|
'@ChamiloCore/Index/vue.html.twig', |
|
37
|
|
|
[ |
|
38
|
|
|
'is_authenticated' => json_encode(!empty($this->getUser())), |
|
39
|
|
|
'user' => $data ?? json_encode($data), |
|
40
|
|
|
'content' => '', |
|
41
|
|
|
] |
|
42
|
|
|
); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function resources(SerializerInterface $serializer): Response |
|
46
|
|
|
{ |
|
47
|
|
|
$user = $this->getUser(); |
|
48
|
|
|
$data = null; |
|
49
|
|
|
if (!empty($user)) { |
|
50
|
|
|
$userClone = clone $user; |
|
51
|
|
|
$userClone->setPassword(''); |
|
52
|
|
|
$data = $serializer->serialize($userClone, JsonEncoder::FORMAT); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return $this->render( |
|
56
|
|
|
'@ChamiloCore/Index/vue.html.twig', |
|
57
|
|
|
[ |
|
58
|
|
|
'is_authenticated' => json_encode(!empty($this->getUser())), |
|
59
|
|
|
'user' => $data ?? json_encode($data), |
|
60
|
|
|
'content' => '', |
|
61
|
|
|
] |
|
62
|
|
|
); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* Toggle the student view action. |
|
67
|
|
|
* |
|
68
|
|
|
* @Route("/toggle_student_view", methods={"GET"}) |
|
69
|
|
|
* |
|
70
|
|
|
* @Security("has_role('ROLE_TEACHER')") |
|
71
|
|
|
*/ |
|
72
|
|
|
public function toggleStudentViewAction(Request $request): Response |
|
73
|
|
|
{ |
|
74
|
|
|
if (!api_is_allowed_to_edit(false, false, false, false)) { |
|
75
|
|
|
return ''; |
|
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
$studentView = $request->getSession()->get('studentview'); |
|
78
|
|
|
if (empty($studentView) || 'studentview' === $studentView) { |
|
79
|
|
|
$request->getSession()->set('studentview', 'teacherview'); |
|
80
|
|
|
|
|
81
|
|
|
return 'teacherview'; |
|
|
|
|
|
|
82
|
|
|
} else { |
|
83
|
|
|
$request->getSession()->set('studentview', 'studentview'); |
|
84
|
|
|
|
|
85
|
|
|
return 'studentview'; |
|
|
|
|
|
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|