Completed
Push — dev ( 1404ff...b5377b )
by
unknown
10s
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\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
    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 2
    public function loginAction()
32
    {
33 2
        $authenticationUtils = $this->get('security.authentication_utils');
34 2
        $error = $authenticationUtils->getLastAuthenticationError();
35 2
        $lastUsername = $authenticationUtils->getLastUsername();
36
37 2
        return $this->render('@App/login.html.twig', array(
38 2
            'last_username' => $lastUsername, //$lastUsername,
39 2
            '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