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\Customer; |
26
|
|
|
|
27
|
|
|
use Eccube\Application; |
28
|
|
|
use Eccube\Common\Constant; |
29
|
|
|
use Eccube\Controller\AbstractController; |
30
|
|
|
use Eccube\Entity\Master\CsvType; |
31
|
|
|
use Eccube\Event\EccubeEvents; |
32
|
|
|
use Eccube\Event\EventArgs; |
33
|
|
|
use Eccube\Form\Type\Admin\SearchCustomerType; |
34
|
|
|
use Symfony\Component\HttpFoundation\Request; |
35
|
|
|
use Symfony\Component\HttpFoundation\StreamedResponse; |
36
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
37
|
|
|
|
38
|
|
|
class CustomerController extends AbstractController |
|
|
|
|
39
|
|
|
{ |
40
|
6 |
|
public function index(Application $app, Request $request, $page_no = null) |
|
|
|
|
41
|
|
|
{ |
42
|
6 |
|
$session = $request->getSession(); |
43
|
6 |
|
$pagination = array(); |
44
|
6 |
|
$builder = $app['form.factory'] |
45
|
6 |
|
->createBuilder(SearchCustomerType::class); |
46
|
|
|
|
47
|
6 |
|
$event = new EventArgs( |
48
|
|
|
array( |
49
|
6 |
|
'builder' => $builder, |
50
|
|
|
), |
51
|
6 |
|
$request |
52
|
|
|
); |
53
|
6 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CUSTOMER_INDEX_INITIALIZE, $event); |
54
|
|
|
|
55
|
6 |
|
$searchForm = $builder->getForm(); |
56
|
|
|
|
57
|
|
|
//アコーディオンの制御初期化( デフォルトでは閉じる ) |
58
|
6 |
|
$active = false; |
59
|
|
|
|
60
|
6 |
|
$pageMaxis = $app['eccube.repository.master.page_max']->findAll(); |
61
|
6 |
|
$page_count = $app['config']['default_page_count']; |
62
|
|
|
|
63
|
6 |
|
if ('POST' === $request->getMethod()) { |
|
|
|
|
64
|
|
|
|
65
|
4 |
|
$searchForm->handleRequest($request); |
66
|
|
|
|
67
|
4 |
|
if ($searchForm->isValid()) { |
68
|
4 |
|
$searchData = $searchForm->getData(); |
69
|
|
|
|
70
|
|
|
// paginator |
71
|
4 |
|
$qb = $app['eccube.repository.customer']->getQueryBuilderBySearchData($searchData); |
72
|
4 |
|
$page_no = 1; |
73
|
|
|
|
74
|
4 |
|
$event = new EventArgs( |
75
|
|
|
array( |
76
|
4 |
|
'form' => $searchForm, |
77
|
4 |
|
'qb' => $qb, |
78
|
|
|
), |
79
|
4 |
|
$request |
80
|
|
|
); |
81
|
4 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CUSTOMER_INDEX_SEARCH, $event); |
82
|
|
|
|
83
|
4 |
|
$pagination = $app['paginator']()->paginate( |
84
|
4 |
|
$qb, |
85
|
4 |
|
$page_no, |
86
|
4 |
|
$page_count |
87
|
|
|
); |
88
|
|
|
|
89
|
|
|
// sessionのデータ保持 |
90
|
4 |
|
$session->set('eccube.admin.customer.search', $searchData); |
91
|
4 |
|
$session->set('eccube.admin.customer.search.page_no', $page_no); |
92
|
|
|
} |
93
|
|
|
} else { |
94
|
2 |
|
if (is_null($page_no) && $request->get('resume') != Constant::ENABLED) { |
95
|
|
|
// sessionを削除 |
96
|
1 |
|
$session->remove('eccube.admin.customer.search'); |
97
|
1 |
|
$session->remove('eccube.admin.customer.search.page_no'); |
98
|
|
|
} else { |
99
|
|
|
// pagingなどの処理 |
100
|
1 |
|
$searchData = $session->get('eccube.admin.customer.search'); |
101
|
1 |
|
if (is_null($page_no)) { |
102
|
|
|
$page_no = intval($session->get('eccube.admin.customer.search.page_no')); |
103
|
|
|
} else { |
104
|
1 |
|
$session->set('eccube.admin.customer.search.page_no', $page_no); |
105
|
|
|
} |
106
|
1 |
|
if (!is_null($searchData)) { |
107
|
|
|
// 表示件数 |
108
|
|
|
$pcount = $request->get('page_count'); |
109
|
|
|
$page_count = empty($pcount) ? $page_count : $pcount; |
110
|
|
|
|
111
|
|
|
$qb = $app['eccube.repository.customer']->getQueryBuilderBySearchData($searchData); |
112
|
|
|
|
113
|
|
|
$event = new EventArgs( |
114
|
|
|
array( |
115
|
|
|
'form' => $searchForm, |
116
|
|
|
'qb' => $qb, |
117
|
|
|
), |
118
|
|
|
$request |
119
|
|
|
); |
120
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CUSTOMER_INDEX_SEARCH, $event); |
121
|
|
|
|
122
|
|
|
$pagination = $app['paginator']()->paginate( |
123
|
|
|
$qb, |
124
|
|
|
$page_no, |
125
|
|
|
$page_count |
126
|
|
|
); |
127
|
|
|
|
128
|
|
|
// セッションから検索条件を復元 |
129
|
|
|
if (count($searchData['sex']) > 0) { |
130
|
|
|
$sex_ids = array(); |
131
|
|
|
foreach ($searchData['sex'] as $Sex) { |
132
|
|
|
$sex_ids[] = $Sex->getId(); |
133
|
|
|
} |
134
|
|
|
$searchData['sex'] = $app['eccube.repository.master.sex']->findBy(array('id' => $sex_ids)); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
if (!is_null($searchData['pref'])) { |
138
|
|
|
$searchData['pref'] = $app['eccube.repository.master.pref']->find($searchData['pref']->getId()); |
139
|
|
|
} |
140
|
|
|
$searchForm->setData($searchData); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
} |
144
|
6 |
|
return $app->render('Customer/index.twig', array( |
|
|
|
|
145
|
6 |
|
'searchForm' => $searchForm->createView(), |
146
|
6 |
|
'pagination' => $pagination, |
147
|
6 |
|
'pageMaxis' => $pageMaxis, |
148
|
6 |
|
'page_no' => $page_no, |
149
|
6 |
|
'page_count' => $page_count, |
150
|
6 |
|
'active' => $active, |
151
|
|
|
)); |
152
|
|
|
} |
153
|
|
|
|
154
|
1 |
|
public function resend(Application $app, Request $request, $id) |
|
|
|
|
155
|
|
|
{ |
156
|
1 |
|
$this->isTokenValid($app); |
157
|
|
|
|
158
|
1 |
|
$Customer = $app['orm.em'] |
159
|
1 |
|
->getRepository('Eccube\Entity\Customer') |
160
|
1 |
|
->find($id); |
161
|
|
|
|
162
|
1 |
|
if (is_null($Customer)) { |
163
|
|
|
throw new NotFoundHttpException(); |
164
|
|
|
} |
165
|
|
|
|
166
|
1 |
|
$activateUrl = $app->url('entry_activate', array('secret_key' => $Customer->getSecretKey())); |
167
|
|
|
|
168
|
|
|
// メール送信 |
169
|
1 |
|
$app['eccube.service.mail']->sendAdminCustomerConfirmMail($Customer, $activateUrl); |
170
|
|
|
|
171
|
1 |
|
$event = new EventArgs( |
172
|
|
|
array( |
173
|
1 |
|
'Customer' => $Customer, |
174
|
1 |
|
'activateUrl' => $activateUrl, |
175
|
|
|
), |
176
|
1 |
|
$request |
177
|
|
|
); |
178
|
1 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CUSTOMER_RESEND_COMPLETE, $event); |
179
|
|
|
|
180
|
1 |
|
$app->addSuccess('admin.customer.resend.complete', 'admin'); |
181
|
|
|
|
182
|
1 |
|
return $app->redirect($app->url('admin_customer')); |
183
|
|
|
} |
184
|
|
|
|
185
|
1 |
|
public function delete(Application $app, Request $request, $id) |
|
|
|
|
186
|
|
|
{ |
187
|
1 |
|
$this->isTokenValid($app); |
188
|
|
|
|
189
|
1 |
|
log_info('会員削除開始', array($id)); |
190
|
|
|
|
191
|
1 |
|
$session = $request->getSession(); |
192
|
1 |
|
$page_no = intval($session->get('eccube.admin.customer.search.page_no')); |
193
|
1 |
|
$page_no = $page_no ? $page_no : Constant::ENABLED; |
194
|
|
|
|
195
|
1 |
|
$Customer = $app['orm.em'] |
196
|
1 |
|
->getRepository('Eccube\Entity\Customer') |
197
|
1 |
|
->find($id); |
198
|
|
|
|
199
|
1 |
|
if (!$Customer) { |
200
|
|
|
$app->deleteMessage(); |
201
|
|
|
return $app->redirect($app->url('admin_customer_page', array('page_no' => $page_no)).'?resume='.Constant::ENABLED); |
|
|
|
|
202
|
|
|
} |
203
|
|
|
|
204
|
1 |
|
$Customer->setDelFlg(Constant::ENABLED); |
205
|
1 |
|
$app['orm.em']->persist($Customer); |
206
|
1 |
|
$app['orm.em']->flush(); |
207
|
|
|
|
208
|
1 |
|
log_info('会員削除完了', array($id)); |
209
|
|
|
|
210
|
1 |
|
$event = new EventArgs( |
211
|
|
|
array( |
212
|
1 |
|
'Customer' => $Customer, |
213
|
|
|
), |
214
|
1 |
|
$request |
215
|
|
|
); |
216
|
1 |
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CUSTOMER_DELETE_COMPLETE, $event); |
217
|
|
|
|
218
|
1 |
|
$app->addSuccess('admin.customer.delete.complete', 'admin'); |
219
|
|
|
|
220
|
1 |
|
return $app->redirect($app->url('admin_customer_page', array('page_no' => $page_no)).'?resume='.Constant::ENABLED); |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* 会員CSVの出力. |
225
|
|
|
* @param Application $app |
226
|
|
|
* @param Request $request |
|
|
|
|
227
|
|
|
* @return StreamedResponse |
228
|
|
|
*/ |
229
|
|
|
public function export(Application $app, Request $request) |
230
|
|
|
{ |
231
|
|
|
// タイムアウトを無効にする. |
232
|
|
|
set_time_limit(0); |
233
|
|
|
|
234
|
|
|
// sql loggerを無効にする. |
235
|
|
|
$em = $app['orm.em']; |
236
|
|
|
$em->getConfiguration()->setSQLLogger(null); |
237
|
|
|
|
238
|
|
|
$response = new StreamedResponse(); |
239
|
|
|
$response->setCallback(function () use ($app, $request) { |
240
|
|
|
|
241
|
|
|
// CSV種別を元に初期化. |
242
|
|
|
$app['eccube.service.csv.export']->initCsvType(CsvType::CSV_TYPE_CUSTOMER); |
243
|
|
|
|
244
|
|
|
// ヘッダ行の出力. |
245
|
|
|
$app['eccube.service.csv.export']->exportHeader(); |
246
|
|
|
|
247
|
|
|
// 会員データ検索用のクエリビルダを取得. |
248
|
|
|
$qb = $app['eccube.service.csv.export'] |
249
|
|
|
->getCustomerQueryBuilder($request); |
250
|
|
|
|
251
|
|
|
// データ行の出力. |
252
|
|
|
$app['eccube.service.csv.export']->setExportQueryBuilder($qb); |
253
|
|
View Code Duplication |
$app['eccube.service.csv.export']->exportData(function ($entity, $csvService) use ($app, $request) { |
254
|
|
|
|
255
|
|
|
$Csvs = $csvService->getCsvs(); |
256
|
|
|
|
257
|
|
|
/** @var $Customer \Eccube\Entity\Customer */ |
258
|
|
|
$Customer = $entity; |
259
|
|
|
|
260
|
|
|
$ExportCsvRow = new \Eccube\Entity\ExportCsvRow(); |
261
|
|
|
|
262
|
|
|
// CSV出力項目と合致するデータを取得. |
263
|
|
|
foreach ($Csvs as $Csv) { |
264
|
|
|
// 会員データを検索. |
265
|
|
|
$ExportCsvRow->setData($csvService->getData($Csv, $Customer)); |
266
|
|
|
|
267
|
|
|
$event = new EventArgs( |
268
|
|
|
array( |
269
|
|
|
'csvService' => $csvService, |
270
|
|
|
'Csv' => $Csv, |
271
|
|
|
'Customer' => $Customer, |
272
|
|
|
'ExportCsvRow' => $ExportCsvRow, |
273
|
|
|
), |
274
|
|
|
$request |
275
|
|
|
); |
276
|
|
|
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CUSTOMER_CSV_EXPORT, $event); |
277
|
|
|
|
278
|
|
|
$ExportCsvRow->pushData(); |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
//$row[] = number_format(memory_get_usage(true)); |
282
|
|
|
// 出力. |
283
|
|
|
$csvService->fputcsv($ExportCsvRow->getRow()); |
284
|
|
|
}); |
285
|
|
|
}); |
286
|
|
|
|
287
|
|
|
$now = new \DateTime(); |
288
|
|
|
$filename = 'customer_' . $now->format('YmdHis') . '.csv'; |
|
|
|
|
289
|
|
|
$response->headers->set('Content-Type', 'application/octet-stream'); |
290
|
|
|
$response->headers->set('Content-Disposition', 'attachment; filename=' . $filename); |
|
|
|
|
291
|
|
|
|
292
|
|
|
$response->send(); |
293
|
|
|
|
294
|
|
|
log_info("会員CSVファイル名", array($filename)); |
295
|
|
|
|
296
|
|
|
return $response; |
297
|
|
|
} |
298
|
|
|
} |
299
|
|
|
|