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

DefaultController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A loginAction() 0 11 1
A indexAction() 0 4 1
A usersListAction() 0 11 1
A usersAddAction() 0 19 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('@App/login.html.twig', array(
38 1
            'last_username' => $lastUsername, //$lastUsername,
39 1
            'error' => $error,
40
        ));
41
    }
42
43
    /**
44
     * @Route("/users", name="user_list")
45
     * @Template("@App/users.html.twig")
46
     *
47
     * @return array
48
     */
49
    public function usersListAction(Request $request)
50
    {
51
        $em = $this->getDoctrine()->getManager();
52
        $users = $em->getRepository(UserIntern::class)->findall();
53
        $paginator = $this->get('knp_paginator');
54
        $pagination = $paginator->paginate($users, $request->query->getInt('page', 1), 10);
55
56
        return [
57
            'users' => $pagination,
58
        ];
59
    }
60
61
    /**
62
     * @Route("/user/add", name="add_user")
63
     * @Template("@App/add.html.twig")
64
     *
65
     * @return array
66
     */
67
    public function usersAddAction(Request $request)
68
    {
69
        $em = $this->getDoctrine()->getManager();
70
        $user = new User();
71
        $form = $this->createForm('AppBundle\Form\UserType', $user, [
72
            'action' => $this->generateUrl('add_user'),
73
            'method' => 'POST',
74
        ])
75
            ->add('Save', SubmitType::class, array(
76
                'attr' => ['class' => 'btn pull-right btn-warning'],
77
            ));
78
        $form->handleRequest($request);
79
        if ($form->isValid()) {
80
            $em->persist($user);
81
            $em->flush();
82
        }
83
84
        return ['form' => $form->createView()];
85
    }
86
87
    /**
88
     * @Route("/logout", name="logout")
89
     */
90
    public function logoutAction()
91
    {
92
    }
93
}
94