Completed
Push — master ( 805611...3990be )
by Julito
40:58
created

CourseController::homeAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\CoreBundle\Controller;
5
6
use Chamilo\CoreBundle\Entity\Course;
7
use Chamilo\CoreBundle\Form\Type\CourseType;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Entity;
9
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
10
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
11
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
12
use Symfony\Component\HttpFoundation\Request;
13
use Symfony\Component\HttpFoundation\Response;
14
use Symfony\Component\Routing\Annotation\Route;
15
16
/**
17
 * Class CourseController.
18
 *
19
 * @Route("/courses")
20
 */
21
class CourseController extends AbstractController
22
{
23
    /**
24
     * @Route("/add")
25
     *
26
     * @Security("has_role('ROLE_TEACHER')")
27
     *
28
     * @return Response
29
     */
30
    public function addAction(Request $request)
31
    {
32
        exit;
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
33
        $form = $this->createForm(CourseType::class);
0 ignored issues
show
Unused Code introduced by
$form = $this->createFor...Type\CourseType::class) is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
34
35
        $form->handleRequest($request);
36
37
        if ($form->isSubmitted() && $form->isValid()) {
38
            $em = $this->getDoctrine()->getManager();
39
            $course = $form->getData();
40
            /*$em->persist($course);
41
            $em->flush();*/
42
            $this->addFlash('sonata_flash_success', 'Course created');
43
44
            return $this->redirectToRoute(
45
                'chamilo_core_course_welcome',
46
                ['cid' => $course->getId()]
47
            );
48
        }
49
50
        return $this->render('ChamiloThemeBundle:Course:add.html.twig', ['form' => $form->createView()]);
51
    }
52
53
    /**
54
     * Redirects legacy /courses/ABC/index.php to /courses/1/ (where 1 is the course id) see CourseHomeController
55
     *
56
     * @Route("/{courseCode}/index.php", name="chamilo_core_course_home_redirect")
57
     *
58
     * @Entity("course", expr="repository.findOneByCode(courseCode)")
59
     */
60
    public function homeRedirectAction(Course $course): Response
61
    {
62
        return $this->redirectToRoute('chamilo_core_course_home', ['cid' => $course->getId()]);
63
    }
64
65
    /**
66
     * @Route("/{cid}/welcome", name="chamilo_core_course_welcome")
67
     *
68
     * @Entity("course", expr="repository.find(cid)")
69
     */
70
    public function welcomeAction(Course $course): Response
71
    {
72
        return $this->render('@ChamiloTheme/Course/welcome.html.twig', ['course' => $course]);
73
    }
74
}
75