Completed
Pull Request — dev (#26)
by nonanerz
03:18
created

DefaultController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
c 2
b 0
f 0
lcom 1
cbo 7
dl 0
loc 86
ccs 8
cts 8
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A indexAction() 0 4 1
A loginAction() 0 13 1
A usersListAction() 0 11 1
A usersAddAction() 0 23 2
1
<?php
2
3
namespace AppBundle\Controller;
4
5
//use AppBundle\Entity\Request;
6
use AppBundle\Entity\UserIntern;
7
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
9
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
10
use Symfony\Component\HttpFoundation\Request;
11
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
12
use Symfony\Component\Routing\Annotation\Route;
13
14
class DefaultController extends Controller
15
{
16
    /**
17
     * @Route("/", name="homepage")
18
     * @Template("@App/dashboard.html.twig")
19
     */
20
    public function indexAction()
21
    {
22
        return [];
23
    }
24
25
    /**
26
     * @Route("/login", name="login")
27
     *
28
     * @return \Symfony\Component\HttpFoundation\Response
29
     * @Method({"GET", "POST"})
30
     */
31 1
    public function loginAction()
32
    {
33 1
        $authenticationUtils = $this->get('security.authentication_utils');
34 1
        $error = $authenticationUtils->getLastAuthenticationError();
35 1
        $lastUsername = $authenticationUtils->getLastUsername();
36
37 1
        return $this->render(
38 1
            '@App/login.html.twig', array(
39 1
            'last_username' => $lastUsername, //$lastUsername,
40 1
            'error' => $error,
41
            )
42
        );
43
    }
44
45
    /**
46
     * @Route("/users", name="user_list")
47
     * @Template("@App/users.html.twig")
48
     *
49
     * @return array
50
     */
51
    public function usersListAction(Request $request)
52
    {
53
        $em = $this->getDoctrine()->getManager();
54
        $users = $em->getRepository(UserIntern::class)->findall();
55
        $paginator = $this->get('knp_paginator');
56
        $pagination = $paginator->paginate($users, $request->query->getInt('page', 1), 10);
57
58
        return [
59
            'users' => $pagination,
60
        ];
61
    }
62
63
    /**
64
     * @Route("/user/add", name="add_user")
65
     * @Template("@App/add.html.twig")
66
     *
67
     * @return array
68
     */
69
    public function usersAddAction(Request $request)
70
    {
71
        $em = $this->getDoctrine()->getManager();
72
        $user = new User();
73
        $form = $this->createForm(
74
            'AppBundle\Form\UserType', $user, [
75
            'action' => $this->generateUrl('add_user'),
76
            'method' => 'POST',
77
            ]
78
        )
79
            ->add(
80
                'Save', SubmitType::class, array(
81
                'attr' => ['class' => 'btn pull-right btn-warning'],
82
                )
83
            );
84
        $form->handleRequest($request);
85
        if ($form->isValid()) {
86
            $em->persist($user);
87
            $em->flush();
88
        }
89
90
        return ['form' => $form->createView()];
91
    }
92
93
    /**
94
     * @Route("/logout", name="logout")
95
     */
96
    public function logoutAction()
97
    {
98
    }
99
}
100