Failed Conditions
Push — master ( 29b6b8...0096af )
by Kentaro
33:12
created

Controller/Admin/Customer/CustomerController.php (1 issue)

Upgrade to new PHP Analysis Engine

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 Symfony\Component\HttpFoundation\Request;
32
use Symfony\Component\HttpFoundation\StreamedResponse;
33
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
34
35
class CustomerController extends AbstractController
36
{
37 2
    public function index(Application $app, Request $request, $page_no = null)
38
    {
39
        $session = $request->getSession();
40 2
        $pagination = array();
41
        $searchForm = $app['form.factory']
42
            ->createBuilder('admin_search_customer')
43
            ->getForm();
44
45
        //アコーディオンの制御初期化( デフォルトでは閉じる )
46 2
        $active = false;
47
48
        $pageMaxis = $app['eccube.repository.master.page_max']->findAll();
49
        $page_count = $app['config']['default_page_count'];
50
51
        if ('POST' === $request->getMethod()) {
52
53
            $searchForm->handleRequest($request);
54
55 View Code Duplication
            if ($searchForm->isValid()) {
56
                $searchData = $searchForm->getData();
57
58
                // paginator
59
                $qb = $app['eccube.repository.customer']->getQueryBuilderBySearchData($searchData);
60 1
                $page_no = 1;
61
                $pagination = $app['paginator']()->paginate(
62
                    $qb,
63
                    $page_no,
64
                    $page_count
65
                );
66
67
                // sessionのデータ保持
68
                $session->set('eccube.admin.customer.search', $searchData);
69
            }
70
        } else {
71
            if (is_null($page_no)) {
72
                // sessionを削除
73
                $session->remove('eccube.admin.customer.search');
74
            } else {
75
                // pagingなどの処理
76
                $searchData = $session->get('eccube.admin.customer.search');
77
                if (!is_null($searchData)) {
78
                    // 表示件数
79
                    $pcount = $request->get('page_count');
80
                    $page_count = empty($pcount) ? $page_count : $pcount;
81
82
                    $qb = $app['eccube.repository.customer']->getQueryBuilderBySearchData($searchData);
83
                    $pagination = $app['paginator']()->paginate(
84
                        $qb,
85
                        $page_no,
86
                        $page_count
87
                    );
88
89
                    // セッションから検索条件を復元
90 View Code Duplication
                    if (count($searchData['sex']) > 0) {
91
                        $sex_ids = array();
92
                        foreach ($searchData['sex'] as $Sex) {
93
                            $sex_ids[] = $Sex->getId();
94
                        }
95
                        $searchData['sex'] = $app['eccube.repository.master.sex']->findBy(array('id' => $sex_ids));
96
                    }
97
98
                    if (!is_null($searchData['pref'])) {
99
                        $searchData['pref'] = $app['eccube.repository.master.pref']->find($searchData['pref']->getId());
100
                    }
101
                    $searchForm->setData($searchData);
102
                }
103 1
            }
104 1
        }
105 2
        return $app->renderView('Customer/index.twig', array(
106 2
            'searchForm' => $searchForm->createView(),
107
            'pagination' => $pagination,
108
            'pageMaxis' => $pageMaxis,
109
            'page_no' => $page_no,
110
            'page_count' => $page_count,
111
            'active' => $active,
112
        ));
113 2
    }
114
115 1
    public function resend(Application $app, Request $request, $id)
116
    {
117
        $this->isTokenValid($app);
118
119
        $Customer = $app['orm.em']
120
            ->getRepository('Eccube\Entity\Customer')
121
            ->find($id);
122
123
        if (is_null($Customer)) {
124
            throw new NotFoundHttpException();
125
        }
126
127
        $activateUrl = $app->url('entry_activate', array('secret_key' => $Customer->getSecretKey()));
128
129
        // メール送信
130
        $app['eccube.service.mail']->sendAdminCustomerConfirmMail($Customer, $activateUrl);
131
132
        $app->addSuccess('admin.customer.resend.complete', 'admin');
133
134
        return $app->redirect($app->url('admin_customer'));
135 1
    }
136
137 1
    public function delete(Application $app, Request $request, $id)
138
    {
139
        $this->isTokenValid($app);
140
141
        $Customer = $app['orm.em']
142
            ->getRepository('Eccube\Entity\Customer')
143
            ->find($id);
144
145 1
        if (!$Customer) {
146
            $app->deleteMessage();
147
            return $app->redirect($app->url('admin_customer'));
148
        }
149
150
        $Customer->setDelFlg(Constant::ENABLED);
151
        $app['orm.em']->persist($Customer);
152
        $app['orm.em']->flush();
153
        $app->addSuccess('admin.customer.delete.complete', 'admin');
154
155
        return $app->redirect($app->url('admin_customer'));
156 1
    }
157
158
    /**
159
     * 会員CSVの出力.
160
     * @param Application $app
161
     * @param Request $request
162
     * @return StreamedResponse
163
     */
164
    public function export(Application $app, Request $request)
165
    {
166
        // タイムアウトを無効にする.
167
        set_time_limit(0);
168
169
        // sql loggerを無効にする.
170
        $em = $app['orm.em'];
171
        $em->getConfiguration()->setSQLLogger(null);
172
173
        $response = new StreamedResponse();
174
        $response->setCallback(function () use ($app, $request) {
175
176
            // CSV種別を元に初期化.
177
            $app['eccube.service.csv.export']->initCsvType(CsvType::CSV_TYPE_CUSTOMER);
178
179
            // ヘッダ行の出力.
180
            $app['eccube.service.csv.export']->exportHeader();
181
182
            // 会員データ検索用のクエリビルダを取得.
183
            $qb = $app['eccube.service.csv.export']
184
                ->getCustomerQueryBuilder($request);
185
186
            // データ行の出力.
187
            $app['eccube.service.csv.export']->setExportQueryBuilder($qb);
188 View Code Duplication
            $app['eccube.service.csv.export']->exportData(function ($entity, $csvService) {
189
190
                $Csvs = $csvService->getCsvs();
191
192
                /** @var $Customer \Eccube\Entity\Customer */
193
                $Customer = $entity;
194
195
                $row = array();
196
197
                // CSV出力項目と合致するデータを取得.
198
                foreach ($Csvs as $Csv) {
199
                    // 会員データを検索.
200
                    $row[] = $csvService->getData($Csv, $Customer);
201
                }
202
203
                //$row[] = number_format(memory_get_usage(true));
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
204
                // 出力.
205
                $csvService->fputcsv($row);
206
            });
207
        });
208
209
        $now = new \DateTime();
210
        $filename = 'customer_' . $now->format('YmdHis') . '.csv';
211
        $response->headers->set('Content-Type', 'application/octet-stream');
212
        $response->headers->set('Content-Disposition', 'attachment; filename=' . $filename);
213
        $response->send();
214
215 1
        return $response;
216 1
    }
217
}
218