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