nanasess /
ec-cube
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 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 | 2 | class CustomerController extends AbstractController |
|
| 38 | { |
||
| 39 | public function index(Application $app, Request $request, $page_no = null) |
||
| 40 | 2 | { |
|
| 41 | $session = $request->getSession(); |
||
| 42 | $pagination = array(); |
||
| 43 | $builder = $app['form.factory'] |
||
| 44 | ->createBuilder('admin_search_customer'); |
||
| 45 | |||
| 46 | 2 | $event = new EventArgs( |
|
| 47 | array( |
||
| 48 | 'builder' => $builder, |
||
| 49 | ), |
||
| 50 | $request |
||
| 51 | ); |
||
| 52 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CUSTOMER_INDEX_INITIALIZE, $event); |
||
| 53 | |||
| 54 | $searchForm = $builder->getForm(); |
||
| 55 | |||
| 56 | //アコーディオンの制御初期化( デフォルトでは閉じる ) |
||
| 57 | $active = false; |
||
| 58 | |||
| 59 | $pageMaxis = $app['eccube.repository.master.page_max']->findAll(); |
||
| 60 | 1 | $page_count = $app['config']['default_page_count']; |
|
| 61 | |||
| 62 | if ('POST' === $request->getMethod()) { |
||
| 63 | |||
| 64 | $searchForm->handleRequest($request); |
||
| 65 | |||
| 66 | View Code Duplication | if ($searchForm->isValid()) { |
|
| 67 | $searchData = $searchForm->getData(); |
||
| 68 | |||
| 69 | // paginator |
||
| 70 | $qb = $app['eccube.repository.customer']->getQueryBuilderBySearchData($searchData); |
||
| 71 | $page_no = 1; |
||
| 72 | |||
| 73 | $event = new EventArgs( |
||
| 74 | array( |
||
| 75 | 'form' => $searchForm, |
||
| 76 | 'qb' => $qb, |
||
| 77 | ), |
||
| 78 | $request |
||
| 79 | ); |
||
| 80 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CUSTOMER_INDEX_SEARCH, $event); |
||
| 81 | |||
| 82 | $pagination = $app['paginator']()->paginate( |
||
| 83 | $qb, |
||
| 84 | $page_no, |
||
| 85 | $page_count |
||
| 86 | ); |
||
| 87 | |||
| 88 | // sessionのデータ保持 |
||
| 89 | $session->set('eccube.admin.customer.search', $searchData); |
||
| 90 | } |
||
| 91 | } else { |
||
| 92 | if (is_null($page_no)) { |
||
| 93 | // sessionを削除 |
||
| 94 | $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 | 1 | $qb = $app['eccube.repository.customer']->getQueryBuilderBySearchData($searchData); |
|
| 104 | 1 | ||
| 105 | 2 | $event = new EventArgs( |
|
| 106 | 2 | array( |
|
| 107 | 'form' => $searchForm, |
||
| 108 | 'qb' => $qb, |
||
| 109 | ), |
||
| 110 | $request |
||
| 111 | ); |
||
| 112 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CUSTOMER_INDEX_SEARCH, $event); |
||
| 113 | 2 | ||
| 114 | $pagination = $app['paginator']()->paginate( |
||
| 115 | 1 | $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 | 1 | } |
|
| 136 | return $app->render('Customer/index.twig', array( |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 137 | 1 | 'searchForm' => $searchForm->createView(), |
|
| 138 | 'pagination' => $pagination, |
||
| 139 | 'pageMaxis' => $pageMaxis, |
||
| 140 | 'page_no' => $page_no, |
||
| 141 | 'page_count' => $page_count, |
||
| 142 | 'active' => $active, |
||
| 143 | )); |
||
| 144 | } |
||
| 145 | 1 | ||
| 146 | public function resend(Application $app, Request $request, $id) |
||
| 147 | { |
||
| 148 | $this->isTokenValid($app); |
||
| 149 | |||
| 150 | $Customer = $app['orm.em'] |
||
| 151 | ->getRepository('Eccube\Entity\Customer') |
||
| 152 | ->find($id); |
||
| 153 | |||
| 154 | if (is_null($Customer)) { |
||
| 155 | throw new NotFoundHttpException(); |
||
| 156 | 1 | } |
|
| 157 | |||
| 158 | $activateUrl = $app->url('entry_activate', array('secret_key' => $Customer->getSecretKey())); |
||
| 159 | |||
| 160 | // メール送信 |
||
| 161 | $app['eccube.service.mail']->sendAdminCustomerConfirmMail($Customer, $activateUrl); |
||
| 162 | |||
| 163 | $event = new EventArgs( |
||
| 164 | array( |
||
| 165 | 'Customer' => $Customer, |
||
| 166 | 'activateUrl' => $activateUrl, |
||
| 167 | ), |
||
| 168 | $request |
||
| 169 | ); |
||
| 170 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CUSTOMER_RESEND_COMPLETE, $event); |
||
| 171 | |||
| 172 | $app->addSuccess('admin.customer.resend.complete', 'admin'); |
||
| 173 | |||
| 174 | return $app->redirect($app->url('admin_customer')); |
||
| 175 | } |
||
| 176 | |||
| 177 | public function delete(Application $app, Request $request, $id) |
||
| 178 | { |
||
| 179 | $this->isTokenValid($app); |
||
| 180 | |||
| 181 | $Customer = $app['orm.em'] |
||
| 182 | ->getRepository('Eccube\Entity\Customer') |
||
| 183 | ->find($id); |
||
| 184 | |||
| 185 | if (!$Customer) { |
||
| 186 | $app->deleteMessage(); |
||
| 187 | return $app->redirect($app->url('admin_customer')); |
||
| 188 | } |
||
| 189 | |||
| 190 | $Customer->setDelFlg(Constant::ENABLED); |
||
| 191 | $app['orm.em']->persist($Customer); |
||
| 192 | $app['orm.em']->flush(); |
||
| 193 | |||
| 194 | $event = new EventArgs( |
||
| 195 | array( |
||
| 196 | 'Customer' => $Customer, |
||
| 197 | ), |
||
| 198 | $request |
||
| 199 | ); |
||
| 200 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CUSTOMER_DELETE_COMPLETE, $event); |
||
| 201 | |||
| 202 | $app->addSuccess('admin.customer.delete.complete', 'admin'); |
||
| 203 | |||
| 204 | 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 | 1 | // タイムアウトを無効にする. |
|
| 216 | 1 | 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 |