Completed
Pull Request — dev (#26)
by nonanerz
11:38
created

DefaultController::indexAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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',
39
            array(
40 1
            'last_username' => $lastUsername, //$lastUsername,
41 1
            'error' => $error,
42
            )
43
        );
44
    }
45
46
    /**
47
     * @Route("/users", name="user_list")
48
     * @Template("@App/users.html.twig")
49
     *
50
     * @return array
51
     */
52
    public function usersListAction(Request $request)
53
    {
54
        $em = $this->getDoctrine()->getManager();
55
        $users = $em->getRepository(UserIntern::class)->findall();
56
        $paginator = $this->get('knp_paginator');
57
        $pagination = $paginator->paginate($users, $request->query->getInt('page', 1), 10);
58
59
        return [
60
            'users' => $pagination,
61
        ];
62
    }
63
64
    /**
65
     * @Route("/user/add", name="add_user")
66
     * @Template("@App/add.html.twig")
67
     *
68
     * @return array
69
     */
70
    public function usersAddAction(Request $request)
71
    {
72
        $em = $this->getDoctrine()->getManager();
73
        $user = new User();
74
        $form = $this->createForm(
75
            'AppBundle\Form\UserType',
76
            $user,
77
            ['action' => $this->generateUrl('add_user'), 'method' => 'POST']
78
        )
79
            ->add(
80
                'Save',
81
                SubmitType::class,
82
                array('attr' => ['class' => 'btn pull-right btn-warning'])
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