Completed
Pull Request — dev (#19)
by
unknown
02:14
created

DefaultController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

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

4 Methods

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