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
|
1 |
|
public function surveysAction(Request $request) |
21
|
|
|
{ |
22
|
1 |
|
$em = $this->getDoctrine()->getManager(); |
23
|
1 |
|
$surveys = $em->getRepository(Survey::class)->findSurveyByStatus('submited'); |
24
|
1 |
|
$surveyTypes = $em->getRepository(SurveyType::class)->findAll(); |
25
|
1 |
|
$paginator = $this->get('knp_paginator'); |
26
|
1 |
|
$pagination = $paginator->paginate($surveys, $request->query->getInt('page', 1), 10); |
27
|
|
|
|
28
|
|
|
return [ |
29
|
1 |
|
'surveys' => $pagination, 'survey_types' => $surveyTypes, |
30
|
|
|
]; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param Survey $survey |
35
|
|
|
* @Route("/survey/{id}", name="survey_get") |
36
|
|
|
* @Template("@App/survey.html.twig") |
37
|
|
|
* @ParamConverter("survey", class="AppBundle:Survey") |
38
|
|
|
*/ |
39
|
1 |
|
public function surveyAction(Survey $survey) |
40
|
|
|
{ |
41
|
1 |
|
$em = $this->getDoctrine()->getManager(); |
42
|
1 |
|
$fields = $em->getRepository(SurveyAnswer::class)->findAnswersBySurvey($survey); |
43
|
|
|
|
44
|
|
|
return [ |
45
|
1 |
|
'survey' => $survey, 'fields' => $fields, |
46
|
|
|
]; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param Request $request, SurveyType $surveyType |
|
|
|
|
51
|
|
|
* @Route("/survey/create/{survey_type}", name="survey_create") |
52
|
|
|
* @ParamConverter("surveyType", options={"mapping": {"survey_type": "name"}}) |
53
|
|
|
*/ |
54
|
1 |
View Code Duplication |
public function surveyCreateAction(Request $request, SurveyType $surveyType) |
|
|
|
|
55
|
|
|
{ |
56
|
1 |
|
$survey = new Survey(); |
57
|
1 |
|
$survey->setType($surveyType); |
58
|
1 |
|
$form = $this->createForm(\AppBundle\Form\SurveyType::class, $survey); |
59
|
1 |
|
$form->handleRequest($request); |
60
|
|
|
|
61
|
1 |
|
if ($form->isSubmitted() && $form->isValid()) { |
62
|
1 |
|
$em = $this->getDoctrine()->getManager(); |
63
|
1 |
|
$em->persist($survey); |
64
|
1 |
|
$em->flush(); |
65
|
|
|
|
66
|
1 |
|
return $this->redirectToRoute('homepage'); |
67
|
|
|
} |
68
|
|
|
|
69
|
1 |
|
return $this->render('@App/surveyform.html.twig', array( |
70
|
1 |
|
'form' => $form->createView(), 'type' => $surveyType, |
71
|
|
|
)); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param Request $request, Survey $survey |
|
|
|
|
76
|
|
|
* @Route("/survey/delete/{id}", name="survey_delete") |
77
|
|
|
* @ParamConverter("survey", class="AppBundle:Survey") |
78
|
|
|
*/ |
79
|
1 |
View Code Duplication |
public function surveyDeleteAction(Request $request, Survey $survey) |
|
|
|
|
80
|
|
|
{ |
81
|
1 |
|
$surveyType = $survey->getType(); |
82
|
|
|
|
83
|
1 |
|
$form = $this->createForm(\AppBundle\Form\SurveyType::class, $survey); |
84
|
1 |
|
$form->handleRequest($request); |
85
|
|
|
|
86
|
1 |
|
if ($form->isSubmitted() && $form->isValid()) { |
87
|
1 |
|
$em = $this->getDoctrine()->getManager(); |
88
|
1 |
|
$em->remove($survey); |
89
|
1 |
|
$em->flush(); |
90
|
|
|
|
91
|
1 |
|
return $this->redirectToRoute('homepage'); |
92
|
|
|
} |
93
|
|
|
|
94
|
1 |
|
return $this->render('@App/surveyform.html.twig', array( |
95
|
1 |
|
'form' => $form->createView(), 'type' => $surveyType, |
96
|
|
|
)); |
97
|
|
|
} |
98
|
|
|
} |
99
|
|
|
|
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.