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