Completed
Pull Request — dev (#19)
by
unknown
03:10
created

DefaultController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

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

4 Methods

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