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 Symfony\Component\Form\Extension\Core\Type\TextType; |
13
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
14
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
15
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
16
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
17
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType; |
18
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
19
|
|
|
use Symfony\Component\HttpFoundation\Request; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Class FormRequestController |
23
|
|
|
* @package AppBundle\Controller |
24
|
|
|
* @Route("/form_request", name="form_requests") |
25
|
|
|
*/ |
26
|
|
|
class FormRequestController extends Controller |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* @Route("", name="form_request_list") |
30
|
|
|
* @Template("@App/FormRequest/list.html.twig") |
31
|
|
|
* |
32
|
|
|
* @param Request $request |
33
|
|
|
* @return array |
34
|
|
|
*/ |
35
|
|
|
public function listAction(Request $request) |
36
|
|
|
{ |
37
|
|
|
$em = $this->getDoctrine()->getManager(); |
38
|
|
|
$filter = new Filter; |
39
|
|
|
$filterForm = $this->createForm(FormRequestFilterType::class, $filter) |
40
|
|
|
->add('Search', SubmitType::class); |
41
|
|
|
|
42
|
|
|
$filterForm->handleRequest($request); |
43
|
|
|
$formRequests = $this->get('knp_paginator')->paginate( |
44
|
|
|
$em->getRepository(FormRequest::class)->selectRequestFormsByParams($filter), |
45
|
|
|
$request->query->getInt('page', 1), |
46
|
|
|
10 |
47
|
|
|
); |
48
|
|
|
$approveForms =[]; |
49
|
|
|
|
50
|
|
|
foreach ($formRequests as $formRequest) { |
51
|
|
|
if ($formRequest->getStatus() == "pending") { |
52
|
|
|
$approveForms[$formRequest->getId()] = $this->createForm(FormRequestType::class, $formRequest, [ |
53
|
|
|
'method' => "PUT", |
54
|
|
|
'action' => $this->generateUrl('form_approve', ['id' => $formRequest->getId()]), |
55
|
|
|
]) |
56
|
|
|
->createView(); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
return [ |
60
|
|
|
'formRequests' => $formRequests, |
61
|
|
|
'approveForms' => $approveForms, |
62
|
|
|
'filterForm' => $filterForm->createView(), |
63
|
|
|
]; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @Route("/form_request/approve/{id}", name="form_approve") |
68
|
|
|
* |
69
|
|
|
* @Method("PUT") |
70
|
|
|
* @param Request $request |
71
|
|
|
* @param FormRequest $formRequest |
72
|
|
|
* @return RedirectResponse |
73
|
|
|
*/ |
74
|
|
|
public function activationAction(Request $request, FormRequest $formRequest) |
75
|
|
|
{ |
76
|
|
|
$em = $this->getDoctrine()->getManager(); |
77
|
|
|
$form = $this->createForm(FormRequestType::class, $formRequest, [ |
78
|
|
|
'method' => "PUT", |
79
|
|
|
'action' => $this->generateUrl('form_approve', ['id' => $formRequest->getId()]), |
80
|
|
|
]); |
81
|
|
|
$form->handleRequest($request); |
82
|
|
|
if ($form->isSubmitted()) { |
83
|
|
|
if ($form->isValid()) { |
84
|
|
|
$em->persist($formRequest); |
85
|
|
|
$em->flush(); |
86
|
|
|
//TODO send email to intern |
|
|
|
|
87
|
|
|
// $message = \Swift_Message::newInstance() |
88
|
|
|
// ->setSubject('Hello Email') |
89
|
|
|
// ->setFrom('[email protected]') |
90
|
|
|
// ->setTo('[email protected]') |
91
|
|
|
// ->setBody( |
92
|
|
|
// $this->renderView( |
93
|
|
|
// // app/Resources/views/Emails/registration.html.twig |
94
|
|
|
// 'Emails/registration.html.twig', |
95
|
|
|
// array('name' => $name) |
96
|
|
|
// ), |
97
|
|
|
// 'text/html' |
98
|
|
|
// ) |
99
|
|
|
// /* |
100
|
|
|
// * If you also want to include a plaintext version of the message |
101
|
|
|
// ->addPart( |
102
|
|
|
// $this->renderView( |
103
|
|
|
// 'Emails/registration.txt.twig', |
104
|
|
|
// array('name' => $name) |
105
|
|
|
// ), |
106
|
|
|
// 'text/plain' |
107
|
|
|
// ) |
108
|
|
|
// */ |
109
|
|
|
// ; |
110
|
|
|
// $this->get('mailer')->send($message); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
return $this->redirect($this->generateUrl("form_request_list")); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
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.