1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Loevgaard\DandomainAltapayBundle\Controller; |
4
|
|
|
|
5
|
|
|
use Loevgaard\DandomainAltapayBundle\Form\CountryMappingType; |
6
|
|
|
use Loevgaard\PakkelabelsBundle\Entity\CountryMapping; |
7
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
8
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
9
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller; |
10
|
|
|
use Symfony\Component\Form\Form; |
11
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
12
|
|
|
use Symfony\Component\HttpFoundation\Request; |
13
|
|
|
use Symfony\Component\HttpFoundation\Response; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @Route("/country-mapping") |
17
|
|
|
*/ |
18
|
|
|
class CountryMappingController extends Controller |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @Method("GET") |
22
|
|
|
* @Route("", name="loevgaard_pakkelabels_country_mapping_index") |
23
|
|
|
* |
24
|
|
|
* @param Request $request |
25
|
|
|
* |
26
|
|
|
* @return Response |
27
|
|
|
*/ |
28
|
|
|
public function indexAction(Request $request) |
|
|
|
|
29
|
|
|
{ |
30
|
|
|
/** @var CountryMapping[] $countryMappings */ |
31
|
|
|
$countryMappings = $this->get('doctrine') |
32
|
|
|
->getManager() |
33
|
|
|
->getRepository('LoevgaardPakkelabelsBundle:CountryMapping') |
34
|
|
|
->findAll(); |
35
|
|
|
|
36
|
|
|
return $this->render('@LoevgaardPakkelabels/country_mapping/index.html.twig', [ |
37
|
|
|
'countryMappings' => $countryMappings, |
38
|
|
|
]); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @Method("GET") |
43
|
|
|
* @Route("/{id}/show", name="loevgaard_pakkelabels_country_mapping_show") |
44
|
|
|
* |
45
|
|
|
* @param CountryMapping $countryMapping |
46
|
|
|
* |
47
|
|
|
* @return Response |
48
|
|
|
*/ |
49
|
|
|
public function showAction(CountryMapping $countryMapping) |
50
|
|
|
{ |
51
|
|
|
return $this->render('@LoevgaardPakkelabels/country_mapping/show.html.twig', [ |
52
|
|
|
'countryMapping' => $countryMapping, |
53
|
|
|
]); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @Method({"GET", "POST"}) |
58
|
|
|
* @Route("/new", name="loevgaard_pakkelabels_country_mapping_new") |
59
|
|
|
* |
60
|
|
|
* @param Request $request |
61
|
|
|
* |
62
|
|
|
* @return Response |
63
|
|
|
*/ |
64
|
|
View Code Duplication |
public function newAction(Request $request) |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$countryMapping = new CountryMapping(); |
67
|
|
|
$form = $this->getForm($countryMapping); |
68
|
|
|
$res = $this->handleUpdate($form, $countryMapping, $request); |
69
|
|
|
if($res) { |
70
|
|
|
return $res; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $this->updateResponse($countryMapping, $form); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @Method({"GET", "POST"}) |
78
|
|
|
* @Route("/{id}/edit", name="loevgaard_pakkelabels_country_mapping_edit") |
79
|
|
|
* |
80
|
|
|
* @param CountryMapping $countryMapping |
81
|
|
|
* @param Request $request |
82
|
|
|
* |
83
|
|
|
* @return Response |
84
|
|
|
*/ |
85
|
|
View Code Duplication |
public function editAction(CountryMapping $countryMapping, Request $request) |
|
|
|
|
86
|
|
|
{ |
87
|
|
|
$form = $this->getForm($countryMapping); |
88
|
|
|
$res = $this->handleUpdate($form, $countryMapping, $request); |
89
|
|
|
if($res) { |
90
|
|
|
return $res; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
return $this->updateResponse($countryMapping, $form); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @param Form $form |
98
|
|
|
* @param CountryMapping $countryMapping |
99
|
|
|
* @param Request $request |
100
|
|
|
* @return null|RedirectResponse |
101
|
|
|
*/ |
102
|
|
|
private function handleUpdate(Form $form, CountryMapping $countryMapping, Request $request) |
103
|
|
|
{ |
104
|
|
|
$form->handleRequest($request); |
105
|
|
|
|
106
|
|
|
if ($form->isSubmitted() && $form->isValid()) { |
107
|
|
|
$new = is_null($countryMapping->getId()); |
108
|
|
|
|
109
|
|
|
$em = $this->getDoctrine()->getManager(); |
110
|
|
|
$em->persist($countryMapping); |
111
|
|
|
$em->flush(); |
112
|
|
|
|
113
|
|
|
$translator = $this->get('translator'); |
114
|
|
|
|
115
|
|
|
$this->addFlash( |
116
|
|
|
'success', |
117
|
|
|
$new ? |
118
|
|
|
$translator->trans('country_mapping.new.created', [], 'LoevgaardPakkelabelsBundle') : |
119
|
|
|
$translator->trans('country_mapping.edit.updated', [], 'LoevgaardPakkelabelsBundle') |
120
|
|
|
); |
121
|
|
|
|
122
|
|
|
return $this->redirectToRoute('loevgaard_pakkelabels_country_mapping_edit', [ |
123
|
|
|
'id' => $countryMapping->getId() |
124
|
|
|
]); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
return null; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param CountryMapping $countryMapping |
132
|
|
|
* @param Form $form |
133
|
|
|
* @return Response |
134
|
|
|
*/ |
135
|
|
|
private function updateResponse(CountryMapping $countryMapping, Form $form) : Response |
136
|
|
|
{ |
137
|
|
|
return $this->render('@LoevgaardPakkelabels/country_mapping/edit.html.twig', [ |
138
|
|
|
'countryMapping' => $countryMapping, |
139
|
|
|
'form' => $form |
140
|
|
|
]); |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @param CountryMapping $countryMapping |
145
|
|
|
* @return Form |
146
|
|
|
*/ |
147
|
|
|
private function getForm(CountryMapping $countryMapping) : Form |
148
|
|
|
{ |
149
|
|
|
return $form = $this->createForm(CountryMappingType::class, $countryMapping); |
|
|
|
|
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
} |
153
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.