1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AppBundle\Controller; |
4
|
|
|
|
5
|
|
|
use AppBundle\Entity\SurveyAnswer; |
6
|
|
|
use AppBundle\Entity\Survey; |
7
|
|
|
use AppBundle\Entity\SurveyType; |
8
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
9
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
10
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
11
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
12
|
|
|
use Symfony\Component\HttpFoundation\Request; |
13
|
|
|
|
14
|
|
|
class SurveyController extends Controller |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @Route("/surveys", name="surveys") |
18
|
|
|
* @Template("@App/surveys.html.twig") |
19
|
|
|
*/ |
20
|
|
|
public function surveysAction() |
21
|
|
|
{ |
22
|
|
|
$em = $this->getDoctrine()->getManager(); |
23
|
|
|
$surveys = $em->getRepository(Survey::class)->findSurveyByStatus('submited'); |
24
|
|
|
$surveyTypes = $em->getRepository(SurveyType::class)->findAll(); |
25
|
|
|
|
26
|
|
|
return [ |
27
|
|
|
'surveys' => $surveys, 'survey_types' => $surveyTypes, |
28
|
|
|
]; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @param Survey $survey |
33
|
|
|
* @Route("/survey/{id}", name="survey_get") |
34
|
|
|
* @Template("@App/survey.html.twig") |
35
|
|
|
* @ParamConverter("survey", class="AppBundle:Survey") |
36
|
|
|
*/ |
37
|
|
|
public function surveyAction(Survey $survey) |
38
|
|
|
{ |
39
|
|
|
$em = $this->getDoctrine()->getManager(); |
40
|
|
|
$fields = $em->getRepository(SurveyAnswer::class)->findAnswersBySurvey($survey); |
41
|
|
|
|
42
|
|
|
return [ |
43
|
|
|
'survey' => $survey, 'fields' => $fields, |
44
|
|
|
]; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param Request $request, SurveyType $surveyType |
|
|
|
|
49
|
|
|
* @Route("/survey/create/{survey_type}", name="survey_create") |
50
|
|
|
* @ParamConverter("surveyType", options={"mapping": {"survey_type": "name"}}) |
51
|
|
|
*/ |
52
|
|
View Code Duplication |
public function surveyCreateAction(Request $request, SurveyType $surveyType) |
|
|
|
|
53
|
|
|
{ |
54
|
|
|
$survey = new Survey(); |
55
|
|
|
$survey->setType($surveyType); |
56
|
|
|
$form = $this->createForm(\AppBundle\Form\SurveyType::class, $survey); |
57
|
|
|
$form->handleRequest($request); |
58
|
|
|
|
59
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
60
|
|
|
$em = $this->getDoctrine()->getManager(); |
61
|
|
|
$em->persist($survey); |
62
|
|
|
$em->flush(); |
63
|
|
|
|
64
|
|
|
return $this->redirectToRoute('homepage'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return $this->render('@App/surveyform.html.twig', array( |
68
|
|
|
'form' => $form->createView(), 'type' => $surveyType, |
69
|
|
|
)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @param Request $request, Survey $survey |
|
|
|
|
74
|
|
|
* @Route("/survey/delete/{id}", name="survey_delete") |
75
|
|
|
* @ParamConverter("survey", class="AppBundle:Survey") |
76
|
|
|
*/ |
77
|
|
View Code Duplication |
public function surveyDeleteAction(Request $request, Survey $survey) |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
$surveyType = $survey->getType(); |
80
|
|
|
|
81
|
|
|
$form = $this->createForm(\AppBundle\Form\SurveyType::class, $survey); |
82
|
|
|
$form->handleRequest($request); |
83
|
|
|
|
84
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
85
|
|
|
$em = $this->getDoctrine()->getManager(); |
86
|
|
|
$em->remove($survey); |
87
|
|
|
$em->flush(); |
88
|
|
|
|
89
|
|
|
return $this->redirectToRoute('homepage'); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return $this->render('@App/surveyform.html.twig', array( |
93
|
|
|
'form' => $form->createView(), 'type' => $surveyType, |
94
|
|
|
)); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.