Completed
Pull Request — dev (#40)
by
unknown
11:22
created

FormRequestController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
B listAction() 0 30 3
A activationAction() 0 23 3
1
<?php
2
3
namespace AppBundle\Controller;
4
5
use AppBundle\Entity\FormRequest;
6
use AppBundle\Entity\User;
7
use AppBundle\Entity\DTO\Filter;
8
use AppBundle\Form\DTO\FormRequestFilterType;
9
use AppBundle\Form\User\EditType;
10
use AppBundle\Form\User\ActivationType;
11
use AppBundle\Form\FormRequestType;
12
use AppBundle\Notification\EmailNotification;
13
use Symfony\Component\Form\Extension\Core\Type\TextType;
14
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
15
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
16
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
17
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
18
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
19
use Symfony\Component\HttpFoundation\RedirectResponse;
20
use Symfony\Component\HttpFoundation\Request;
21
22
/**
23
 * Class FormRequestController
24
 * @package AppBundle\Controller
25
 * @Route("/form_request", name="form_requests")
26
 */
27
class FormRequestController extends Controller
28
{
29
    /**
30
     * @Route("", name="form_request_list")
31
     * @Template("@App/FormRequest/list.html.twig")
32
     *
33
     * @param Request $request
34
     * @return array
35
     */
36
    public function listAction(Request $request)
37
    {
38
        $em = $this->getDoctrine()->getManager();
39
        $filter = new Filter;
40
        $filterForm = $this->createForm(FormRequestFilterType::class, $filter)
41
            ->add('Search', SubmitType::class);
42
43
        $filterForm->handleRequest($request);
44
        $formRequests = $this->get('knp_paginator')->paginate(
45
            $em->getRepository(FormRequest::class)->selectRequestFormsByParams($filter),
46
            $request->query->getInt('page', 1),
47
            10
48
        );
49
        $approveForms =[];
50
51
        foreach ($formRequests as $formRequest) {
52
            if ($formRequest->getStatus() == "pending") {
53
                $approveForms[$formRequest->getId()] = $this->createForm(FormRequestType::class, $formRequest, [
54
                    'method' => "PUT",
55
                    'action' => $this->generateUrl('form_approve', ['id' => $formRequest->getId()]),
56
                ])
57
                    ->createView();
58
            }
59
        }
60
        return [
61
            'formRequests' => $formRequests,
62
            'approveForms' => $approveForms,
63
            'filterForm' => $filterForm->createView(),
64
        ];
65
    }
66
67
    /**
68
     * @Route("/form_request/approve/{id}", name="form_approve")
69
     *
70
     * @Method("PUT")
71
     * @param  Request $request
72
     * @param  FormRequest $formRequest
73
     * @return RedirectResponse
74
     */
75
    public function activationAction(Request $request, FormRequest $formRequest)
76
    {
77
        $em = $this->getDoctrine()->getManager();
78
        $form = $this->createForm(FormRequestType::class, $formRequest, [
79
            'method' => "PUT",
80
            'action' => $this->generateUrl('form_approve', ['id' => $formRequest->getId()]),
81
        ]);
82
        $form->handleRequest($request);
83
        if ($form->isSubmitted()) {
84
            if ($form->isValid()) {
85
                $em->persist($formRequest);
86
                $em->flush();
87
                $this->get('app.email_notification')->sendNotification(
88
//                    $formRequest->getUser()->getEmail(),
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
89
                    "[email protected]",
90
                    "Form request action",
91
                    "Hello, ".$formRequest->getUser()->getFirstName().". Your form request was".$formRequest->getStatus().'.'
92
                );
93
            }
94
        }
95
96
        return $this->redirect($this->generateUrl("form_request_list"));
97
    }
98
}
99