File: /virtual/nagasaki/public_html/ec/src/Eccube/Controller/Admin/Customer/CustomerController.php
<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
*
* http://www.lockon.co.jp/
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
namespace Eccube\Controller\Admin\Customer;
use Eccube\Application;
use Eccube\Common\Constant;
use Eccube\Controller\AbstractController;
use Eccube\Entity\Master\CsvType;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class CustomerController extends AbstractController
{
public function index(Application $app, Request $request, $page_no = null)
{
$session = $request->getSession();
$pagination = array();
$builder = $app['form.factory']
->createBuilder('admin_search_customer');
$event = new EventArgs(
array(
'builder' => $builder,
),
$request
);
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CUSTOMER_INDEX_INITIALIZE, $event);
$searchForm = $builder->getForm();
//アコーディオンの制御初期化( デフォルトでは閉じる )
$active = false;
$pageMaxis = $app['eccube.repository.master.page_max']->findAll();
$page_count = $app['config']['default_page_count'];
if ('POST' === $request->getMethod()) {
$searchForm->handleRequest($request);
if ($searchForm->isValid()) {
$searchData = $searchForm->getData();
// paginator
$qb = $app['eccube.repository.customer']->getQueryBuilderBySearchData($searchData);
$page_no = 1;
$event = new EventArgs(
array(
'form' => $searchForm,
'qb' => $qb,
),
$request
);
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CUSTOMER_INDEX_SEARCH, $event);
$pagination = $app['paginator']()->paginate(
$qb,
$page_no,
$page_count
);
// sessionのデータ保持
$session->set('eccube.admin.customer.search', $searchData);
$session->set('eccube.admin.customer.search.page_no', $page_no);
}
} else {
if (is_null($page_no) && $request->get('resume') != Constant::ENABLED) {
// sessionを削除
$session->remove('eccube.admin.customer.search');
$session->remove('eccube.admin.customer.search.page_no');
} else {
// pagingなどの処理
$searchData = $session->get('eccube.admin.customer.search');
if (is_null($page_no)) {
$page_no = intval($session->get('eccube.admin.customer.search.page_no'));
} else {
$session->set('eccube.admin.customer.search.page_no', $page_no);
}
if (!is_null($searchData)) {
// 表示件数
$pcount = $request->get('page_count');
$page_count = empty($pcount) ? $page_count : $pcount;
$qb = $app['eccube.repository.customer']->getQueryBuilderBySearchData($searchData);
$event = new EventArgs(
array(
'form' => $searchForm,
'qb' => $qb,
),
$request
);
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CUSTOMER_INDEX_SEARCH, $event);
$pagination = $app['paginator']()->paginate(
$qb,
$page_no,
$page_count
);
// セッションから検索条件を復元
if (count($searchData['sex']) > 0) {
$sex_ids = array();
foreach ($searchData['sex'] as $Sex) {
$sex_ids[] = $Sex->getId();
}
$searchData['sex'] = $app['eccube.repository.master.sex']->findBy(array('id' => $sex_ids));
}
if (!is_null($searchData['pref'])) {
$searchData['pref'] = $app['eccube.repository.master.pref']->find($searchData['pref']->getId());
}
$searchForm->setData($searchData);
}
}
}
return $app->render('Customer/index.twig', array(
'searchForm' => $searchForm->createView(),
'pagination' => $pagination,
'pageMaxis' => $pageMaxis,
'page_no' => $page_no,
'page_count' => $page_count,
'active' => $active,
));
}
public function resend(Application $app, Request $request, $id)
{
$this->isTokenValid($app);
$Customer = $app['orm.em']
->getRepository('Eccube\Entity\Customer')
->find($id);
if (is_null($Customer)) {
throw new NotFoundHttpException();
}
$activateUrl = $app->url('entry_activate', array('secret_key' => $Customer->getSecretKey()));
// メール送信
$app['eccube.service.mail']->sendAdminCustomerConfirmMail($Customer, $activateUrl);
$event = new EventArgs(
array(
'Customer' => $Customer,
'activateUrl' => $activateUrl,
),
$request
);
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CUSTOMER_RESEND_COMPLETE, $event);
$app->addSuccess('admin.customer.resend.complete', 'admin');
return $app->redirect($app->url('admin_customer'));
}
public function delete(Application $app, Request $request, $id)
{
$this->isTokenValid($app);
log_info('会員削除開始', array($id));
$session = $request->getSession();
$page_no = intval($session->get('eccube.admin.customer.search.page_no'));
$page_no = $page_no ? $page_no : Constant::ENABLED;
$Customer = $app['orm.em']
->getRepository('Eccube\Entity\Customer')
->find($id);
if (!$Customer) {
$app->deleteMessage();
return $app->redirect($app->url('admin_customer_page', array('page_no' => $page_no)).'?resume='.Constant::ENABLED);
}
$Customer->setDelFlg(Constant::ENABLED);
$app['orm.em']->persist($Customer);
$app['orm.em']->flush();
log_info('会員削除完了', array($id));
$event = new EventArgs(
array(
'Customer' => $Customer,
),
$request
);
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CUSTOMER_DELETE_COMPLETE, $event);
$app->addSuccess('admin.customer.delete.complete', 'admin');
return $app->redirect($app->url('admin_customer_page', array('page_no' => $page_no)).'?resume='.Constant::ENABLED);
}
/**
* 会員CSVの出力.
* @param Application $app
* @param Request $request
* @return StreamedResponse
*/
public function export(Application $app, Request $request)
{
// タイムアウトを無効にする.
set_time_limit(0);
// sql loggerを無効にする.
$em = $app['orm.em'];
$em->getConfiguration()->setSQLLogger(null);
$response = new StreamedResponse();
$response->setCallback(function () use ($app, $request) {
// CSV種別を元に初期化.
$app['eccube.service.csv.export']->initCsvType(CsvType::CSV_TYPE_CUSTOMER);
// ヘッダ行の出力.
$app['eccube.service.csv.export']->exportHeader();
// 会員データ検索用のクエリビルダを取得.
$qb = $app['eccube.service.csv.export']
->getCustomerQueryBuilder($request);
// データ行の出力.
$app['eccube.service.csv.export']->setExportQueryBuilder($qb);
$app['eccube.service.csv.export']->exportData(function ($entity, $csvService) use ($app, $request) {
$Csvs = $csvService->getCsvs();
/** @var $Customer \Eccube\Entity\Customer */
$Customer = $entity;
$ExportCsvRow = new \Eccube\Entity\ExportCsvRow();
// CSV出力項目と合致するデータを取得.
foreach ($Csvs as $Csv) {
// 会員データを検索.
$ExportCsvRow->setData($csvService->getData($Csv, $Customer));
$event = new EventArgs(
array(
'csvService' => $csvService,
'Csv' => $Csv,
'Customer' => $Customer,
'ExportCsvRow' => $ExportCsvRow,
),
$request
);
$app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CUSTOMER_CSV_EXPORT, $event);
$ExportCsvRow->pushData();
}
//$row[] = number_format(memory_get_usage(true));
// 出力.
$csvService->fputcsv($ExportCsvRow->getRow());
});
});
$now = new \DateTime();
$filename = 'customer_' . $now->format('YmdHis') . '.csv';
$response->headers->set('Content-Type', 'application/octet-stream');
$response->headers->set('Content-Disposition', 'attachment; filename=' . $filename);
$response->send();
log_info("会員CSVファイル名", array($filename));
return $response;
}
}