<?php
/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Customize\Controller;
use Eccube\Controller\AbstractController;
use Eccube\Entity\Page;
use Eccube\Event\EccubeEvents;
use Eccube\Event\EventArgs;
use Eccube\Repository\Master\DeviceTypeRepository;
use Eccube\Repository\PageRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
use Customize\Repository\StoreRepository;
use Customize\Repository\ProductSchoolRepository;
use Customize\Repository\ProductPriorityRepository;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
class UserDataController extends AbstractController
{
/**
* @var PageRepository
*/
protected $pageRepository;
/**
* @var DeviceTypeRepository
*/
protected $deviceTypeRepository;
/**
* @var StoreRepository
*/
protected $storeRepository;
/**
* @var ProductSchoolRepository
*/
protected $productSchoolRepository;
/**
* @var ProductPriorityRepository
*/
protected $productPriorityRepository;
/**
* UserDataController constructor.
*
* @param PageRepository $pageRepository
* @param DeviceTypeRepository $deviceTypeRepository
*/
public function __construct(
PageRepository $pageRepository,
DeviceTypeRepository $deviceTypeRepository,
StoreRepository $storeRepository,
ProductSchoolRepository $productSchoolRepository,
ProductPriorityRepository $productPriorityRepository
) {
$this->pageRepository = $pageRepository;
$this->deviceTypeRepository = $deviceTypeRepository;
$this->storeRepository = $storeRepository;
$this->productSchoolRepository = $productSchoolRepository;
$this->productPriorityRepository = $productPriorityRepository;
}
/**
* @Route("/%eccube_user_data_route%/store_info", name="store_info", methods={"GET"})
* @Template("@user_data/store_info.twig")
*
* @param Request $request
*
* @return array
*/
public function store_info(Request $request)
{
$Stores = $this->storeRepository->findAll();
if (null === $Stores) {
throw new NotFoundHttpException();
}
$event = new EventArgs(
[
'Stores' => $Stores,
'file' => '@user_data/store_info.twig',
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_USER_DATA_INDEX_INITIALIZE);
$arr_store_addr = [];
foreach($Stores as $s)
{
$addr = [];
$addr[] = $s->getPref() ? $s->getPref()->getName() : '';
$addr[] = $s->getAddr01();
$addr[] = $s->getAddr02();
$arr_store_addr[$s->getStoreId()] = implode(',', array_filter($addr));
}
return [
'Stores' => $Stores,
'Address' => $arr_store_addr
];
}
/**
* @Route("/%eccube_user_data_route%/mypage_itemlist", name="mypage_itemlist", methods={"GET"})
* @Template("@user_data/mypage_itemlist.twig")
*
* @param Request $request
*
* @return array
*/
public function mypage_itemlist(Request $request)
{
$School = $this->getUser()->getSchool();
// $Items = $this->productSchoolRepository->findBy(['School' => $School]);
$Items = $this->productSchoolRepository->getNecessityBySchool($School);
$man_item = [];
$woman_item = [];
$common_item = [];
foreach($Items as $Item){
if($Item->getProduct()->isEnable()) {
switch ($Item->getCommodityType()) {
case 1:
$man_item[] = $Item;
break;
case 2:
$woman_item[] = $Item;
break;
case 3:
$man_item[] = $Item;
$woman_item[] = $Item;
break;
default:
break;
}
}
}
// usort($man_item, function($a, $b) {
// return $this->productPriorityRepository->getMaxPriorityByProductId($a->getProduct()->getId()) < $this->productPriorityRepository->getMaxPriorityByProductId($b->getProduct()->getId());
// });
// usort($woman_item, function($a, $b) {
// return $this->productPriorityRepository->getMaxPriorityByProductId($a->getProduct()->getId()) < $this->productPriorityRepository->getMaxPriorityByProductId($b->getProduct()->getId());
// });
$event = new EventArgs(
[
'Items' => $Items,
'file' => '@user_data/mypage_itemlist.twig',
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_USER_DATA_INDEX_INITIALIZE);
return [
'MenItem' => $man_item,
'WomenItem' => $woman_item,
'CommonItem' => $common_item,
];
}
/**
* @Route("/%eccube_user_data_route%/{route}", name="user_data", requirements={"route": "([0-9a-zA-Z_\-]+\/?)+(?<!\/)"}, methods={"GET"})
*/
public function index(Request $request, $route)
{
$Page = $this->pageRepository->findOneBy(
[
'url' => $route,
'edit_type' => Page::EDIT_TYPE_USER,
]
);
if (null === $Page) {
throw new NotFoundHttpException();
}
$file = sprintf('@user_data/%s.twig', $Page->getFileName());
$event = new EventArgs(
[
'Page' => $Page,
'file' => $file,
],
$request
);
$this->eventDispatcher->dispatch($event, EccubeEvents::FRONT_USER_DATA_INDEX_INITIALIZE);
return $this->render($file);
}
}