Completed
Push — master ( 82664b...176635 )
by Julito
88:10 queued 58:03
created

CourseController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
B addAction() 0 24 2
A welcomeAction() 0 4 1
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\Route;
9
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
10
use Symfony\Component\HttpFoundation\Response;
11
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
12
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
13
use Symfony\Component\HttpFoundation\Request;
14
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
15
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
16
17
/**
18
 * Class CourseController
19
 * @package Chamilo\CoreBundle\Controller
20
 */
21
class CourseController extends Controller
22
{
23
    /**
24
     * @Route("/add")
25
     * @Security("has_role('ROLE_TEACHER')")
26
     * @Template
27
     * @return Response
28
     */
29
    public function addAction(Request $request)
30
    {
31
        $form = $this->createForm(new CourseType());
32
33
        $form->handleRequest($request);
34
35
        if ($form->isValid()) {
36
            $em = $this->getDoctrine()->getManager();
37
            $course = $form->getData();
38
            $em->persist($course);
39
            $em->flush();
40
41
            $this->addFlash('sonata_flash_success', 'Course created');
42
43
            return $this->redirectToRoute(
44
                'chamilo_core_course_welcome',
45
                array('course' => $course)
46
            );
47
        }
48
49
        return array(
50
            'form' => $form->createView(),
51
        );
52
    }
53
54
    /**
55
     * @Route("/welcome/{course}")
56
     * @ParamConverter(
57
     *      "course",
58
     *      class="ChamiloCoreBundle:Course",
59
     *      options={"repository_method" = "findOneByCode"}
60
     * )
61
     * @Template
62
     */
63
    public function welcomeAction(Course $course)
64
    {
65
        return array('course' => $course);
66
    }
67
68
69
70
}
71