Completed
Push — master ( 7daaad...a8dd9d )
by Julito
09:46
created

IndexController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 3 1
A toggleStudentViewAction() 0 14 4
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
12
/**
13
 * Class IndexController.
14
 */
15
class IndexController extends BaseController
16
{
17
    /**
18
     * Index home page.
19
     *
20
     * @Route("/", name="home", methods={"GET", "POST"}, options={"expose"=true})
21
     * @Route("/login", name="login", methods={"GET", "POST"}, options={"expose"=true})
22
     * @Route("/courses", name="courses", methods={"GET", "POST"}, options={"expose"=true})
23
     * @Route("/sessions", name="sessions", methods={"GET", "POST"}, options={"expose"=true})
24
     */
25
    public function indexAction(): Response
26
    {
27
        return $this->render('@ChamiloCore/Index/vue.html.twig');
28
    }
29
30
    /**
31
     * Toggle the student view action.
32
     *
33
     * @Route("/toggle_student_view", methods={"GET"})
34
     *
35
     * @Security("has_role('ROLE_TEACHER')")
36
     */
37
    public function toggleStudentViewAction(Request $request): Response
38
    {
39
        if (!api_is_allowed_to_edit(false, false, false, false)) {
40
            return '';
0 ignored issues
show
Bug Best Practice introduced by
The expression return '' returns the type string which is incompatible with the type-hinted return Symfony\Component\HttpFoundation\Response.
Loading history...
41
        }
42
        $studentView = $request->getSession()->get('studentview');
43
        if (empty($studentView) || 'studentview' === $studentView) {
44
            $request->getSession()->set('studentview', 'teacherview');
45
46
            return 'teacherview';
0 ignored issues
show
Bug Best Practice introduced by
The expression return 'teacherview' returns the type string which is incompatible with the type-hinted return Symfony\Component\HttpFoundation\Response.
Loading history...
47
        } else {
48
            $request->getSession()->set('studentview', 'studentview');
49
50
            return 'studentview';
0 ignored issues
show
Bug Best Practice introduced by
The expression return 'studentview' returns the type string which is incompatible with the type-hinted return Symfony\Component\HttpFoundation\Response.
Loading history...
51
        }
52
    }
53
}
54