|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of EC-CUBE |
|
4
|
|
|
* |
|
5
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
|
6
|
|
|
* |
|
7
|
|
|
* http://www.lockon.co.jp/ |
|
8
|
|
|
* |
|
9
|
|
|
* This program is free software; you can redistribute it and/or |
|
10
|
|
|
* modify it under the terms of the GNU General Public License |
|
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
|
12
|
|
|
* of the License, or (at your option) any later version. |
|
13
|
|
|
* |
|
14
|
|
|
* This program is distributed in the hope that it will be useful, |
|
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17
|
|
|
* GNU General Public License for more details. |
|
18
|
|
|
* |
|
19
|
|
|
* You should have received a copy of the GNU General Public License |
|
20
|
|
|
* along with this program; if not, write to the Free Software |
|
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
22
|
|
|
*/ |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
namespace Eccube\Controller\Admin\Setting\System; |
|
26
|
|
|
|
|
27
|
|
|
use Doctrine\Common\Persistence\Mapping\MappingException; |
|
28
|
|
|
use Eccube\Application; |
|
29
|
|
|
use Eccube\Controller\AbstractController; |
|
30
|
|
|
use Eccube\Event\EccubeEvents; |
|
31
|
|
|
use Eccube\Event\EventArgs; |
|
32
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
33
|
|
|
|
|
34
|
|
|
class MasterdataController extends AbstractController |
|
|
|
|
|
|
35
|
|
|
{ |
|
36
|
2 |
|
public function index(Application $app, Request $request, $entity = null) |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
2 |
|
$data = array(); |
|
39
|
|
|
|
|
40
|
2 |
|
$builder = $app['form.factory']->createBuilder('admin_system_masterdata'); |
|
41
|
|
|
|
|
42
|
2 |
|
$event = new EventArgs( |
|
43
|
|
|
array( |
|
44
|
2 |
|
'builder' => $builder, |
|
45
|
2 |
|
), |
|
46
|
|
|
$request |
|
47
|
2 |
|
); |
|
48
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MASTERDATA_INDEX_INITIALIZE, $event); |
|
49
|
|
|
|
|
50
|
2 |
|
$form = $builder->getForm(); |
|
51
|
|
|
|
|
52
|
2 |
|
if ('POST' === $request->getMethod()) { |
|
53
|
1 |
|
$form->handleRequest($request); |
|
54
|
1 |
|
if ($form->isValid()) { |
|
55
|
1 |
|
$event = new EventArgs( |
|
56
|
|
|
array( |
|
57
|
1 |
|
'form' => $form, |
|
58
|
1 |
|
), |
|
59
|
|
|
$request |
|
60
|
1 |
|
); |
|
61
|
1 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MASTERDATA_INDEX_COMPLETE, $event); |
|
62
|
|
|
|
|
63
|
1 |
|
if ($event->hasResponse()) { |
|
64
|
|
|
return $event->getResponse(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
1 |
|
return $app->redirect($app->url('admin_setting_system_masterdata_view', array('entity' => $form['masterdata']->getData()))); |
|
68
|
|
|
} |
|
69
|
2 |
|
} elseif (!is_null($entity)) { |
|
70
|
1 |
|
$form->submit(array('masterdata' => $entity)); |
|
71
|
1 |
|
if ($form['masterdata']->isValid()) { |
|
72
|
1 |
|
$entityName = str_replace('-', '\\', $entity); |
|
73
|
|
|
try { |
|
74
|
1 |
|
$masterdata = $app['orm.em']->getRepository($entityName)->findBy(array(), array('rank' => 'ASC')); |
|
75
|
1 |
|
$data['data'] = array(); |
|
76
|
1 |
|
$data['masterdata_name'] = $entity; |
|
77
|
1 |
|
foreach ($masterdata as $value) { |
|
78
|
1 |
|
$data['data'][$value['id']]['id'] = $value['id']; |
|
79
|
1 |
|
$data['data'][$value['id']]['name'] = $value['name']; |
|
80
|
1 |
|
} |
|
81
|
1 |
|
$data['data'][] = array( |
|
82
|
1 |
|
'id' => '', |
|
83
|
1 |
|
'name' => '', |
|
84
|
|
|
); |
|
85
|
1 |
|
} catch (MappingException $e) { |
|
|
|
|
|
|
86
|
|
|
} |
|
87
|
1 |
|
} |
|
88
|
1 |
|
} |
|
89
|
|
|
|
|
90
|
2 |
|
$builder2 = $app['form.factory']->createBuilder('admin_system_masterdata_edit', $data); |
|
91
|
|
|
|
|
92
|
2 |
|
$event = new EventArgs( |
|
93
|
|
|
array( |
|
94
|
2 |
|
'builder' => $builder2, |
|
95
|
2 |
|
), |
|
96
|
|
|
$request |
|
97
|
2 |
|
); |
|
98
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MASTERDATA_INDEX_FORM2_INITIALIZE, $event); |
|
99
|
|
|
|
|
100
|
2 |
|
$form2 = $builder2->getForm(); |
|
101
|
|
|
|
|
102
|
2 |
|
return $app->render('Setting/System/masterdata.twig', array( |
|
103
|
2 |
|
'form' => $form->createView(), |
|
104
|
2 |
|
'form2' => $form2->createView(), |
|
105
|
2 |
|
)); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
3 |
|
public function edit(Application $app, Request $request) |
|
|
|
|
|
|
109
|
|
|
{ |
|
110
|
3 |
|
$builder2 = $app['form.factory']->createBuilder('admin_system_masterdata_edit'); |
|
111
|
|
|
|
|
112
|
3 |
|
$event = new EventArgs( |
|
113
|
|
|
array( |
|
114
|
3 |
|
'builder' => $builder2, |
|
115
|
3 |
|
), |
|
116
|
|
|
$request |
|
117
|
3 |
|
); |
|
118
|
3 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MASTERDATA_EDIT_INITIALIZE, $event); |
|
119
|
|
|
|
|
120
|
3 |
|
$form2 = $builder2->getForm(); |
|
121
|
|
|
|
|
122
|
3 |
|
if ('POST' === $request->getMethod()) { |
|
123
|
2 |
|
$form2->handleRequest($request); |
|
124
|
|
|
|
|
125
|
2 |
|
if ($form2->isValid()) { |
|
126
|
2 |
|
$data = $form2->getData(); |
|
127
|
|
|
|
|
128
|
2 |
|
$entityName = str_replace('-', '\\', $data['masterdata_name']); |
|
129
|
2 |
|
$entity = new $entityName(); |
|
130
|
2 |
|
$rank = 0; |
|
131
|
|
|
$ids = array_map(function ($v) {return $v['id'];}, $data['data']); |
|
|
|
|
|
|
132
|
2 |
|
foreach ($data['data'] as $key => $value) { |
|
133
|
2 |
|
if ($value['id'] !== null && $value['name'] !== null) { |
|
134
|
2 |
|
$entity->setId($value['id']); |
|
135
|
2 |
|
$entity->setName($value['name']); |
|
136
|
2 |
|
$entity->setRank($rank++); |
|
137
|
2 |
|
$app['orm.em']->merge($entity); |
|
138
|
2 |
|
} elseif (!in_array($key, $ids)) { |
|
139
|
|
|
// remove |
|
140
|
|
|
$delKey = $app['orm.em']->getRepository($entityName)->find($key); |
|
141
|
|
|
if ($delKey) { |
|
142
|
|
|
$app['orm.em']->remove($delKey); |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
2 |
|
} |
|
146
|
|
|
|
|
147
|
|
|
try { |
|
148
|
2 |
|
$app['orm.em']->flush(); |
|
149
|
|
|
|
|
150
|
2 |
|
$event = new EventArgs( |
|
151
|
|
|
array( |
|
152
|
2 |
|
'form' => $form2, |
|
153
|
2 |
|
), |
|
154
|
|
|
$request |
|
155
|
2 |
|
); |
|
156
|
2 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MASTERDATA_EDIT_COMPLETE, $event); |
|
157
|
|
|
|
|
158
|
2 |
|
$app->addSuccess('admin.register.complete', 'admin'); |
|
159
|
2 |
|
} catch (\Exception $e) { |
|
160
|
|
|
// 外部キー制約などで削除できない場合に例外エラーになる |
|
161
|
|
|
$app->addError('admin.register.failed', 'admin'); |
|
162
|
|
|
} |
|
163
|
|
|
|
|
164
|
2 |
|
return $app->redirect($app->url('admin_setting_system_masterdata_view', array('entity' => $data['masterdata_name']))); |
|
165
|
|
|
} |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
1 |
|
$builder = $app['form.factory']->createBuilder('admin_system_masterdata'); |
|
169
|
|
|
|
|
170
|
1 |
|
$event = new EventArgs( |
|
171
|
|
|
array( |
|
172
|
1 |
|
'builder' => $builder, |
|
173
|
1 |
|
), |
|
174
|
|
|
$request |
|
175
|
1 |
|
); |
|
176
|
1 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MASTERDATA_EDIT_FORM_INITIALIZE, $event); |
|
177
|
|
|
|
|
178
|
1 |
|
$form = $builder->getForm(); |
|
179
|
1 |
|
$parameter = array_merge($request->request->all(), array('masterdata' => $form2['masterdata_name']->getData())); |
|
180
|
1 |
|
$form->submit($parameter); |
|
181
|
|
|
|
|
182
|
1 |
|
return $app->render('Setting/System/masterdata.twig', array( |
|
183
|
1 |
|
'form' => $form->createView(), |
|
184
|
1 |
|
'form2' => $form2->createView(), |
|
185
|
1 |
|
)); |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
|