app/Customize/Controller/UserDataController.php line 206

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Customize\Controller;
  13. use Eccube\Controller\AbstractController;
  14. use Eccube\Entity\Page;
  15. use Eccube\Event\EccubeEvents;
  16. use Eccube\Event\EventArgs;
  17. use Eccube\Repository\Master\DeviceTypeRepository;
  18. use Eccube\Repository\PageRepository;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. use Customize\Repository\StoreRepository;
  23. use Customize\Repository\ProductSchoolRepository;
  24. use Customize\Repository\ProductPriorityRepository;
  25. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  26. class UserDataController extends AbstractController
  27. {
  28.     /**
  29.      * @var PageRepository
  30.      */
  31.     protected $pageRepository;
  32.     /**
  33.      * @var DeviceTypeRepository
  34.      */
  35.     protected $deviceTypeRepository;
  36.     /**
  37.      * @var StoreRepository
  38.      */
  39.     protected $storeRepository;
  40.     /**
  41.      * @var ProductSchoolRepository
  42.      */
  43.     protected $productSchoolRepository;
  44.     /**
  45.      * @var ProductPriorityRepository
  46.      */
  47.     protected $productPriorityRepository;
  48.     /**
  49.      * UserDataController constructor.
  50.      *
  51.      * @param PageRepository $pageRepository
  52.      * @param DeviceTypeRepository $deviceTypeRepository
  53.      */
  54.     public function __construct(
  55.         PageRepository $pageRepository,
  56.         DeviceTypeRepository $deviceTypeRepository,
  57.         StoreRepository $storeRepository,
  58.         ProductSchoolRepository $productSchoolRepository,
  59.         ProductPriorityRepository $productPriorityRepository
  60.     ) {
  61.         $this->pageRepository $pageRepository;
  62.         $this->deviceTypeRepository $deviceTypeRepository;
  63.         $this->storeRepository $storeRepository;
  64.         $this->productSchoolRepository $productSchoolRepository;
  65.         $this->productPriorityRepository $productPriorityRepository;
  66.     }
  67.     /**
  68.      * @Route("/%eccube_user_data_route%/store_info", name="store_info", methods={"GET"})
  69.      * @Template("@user_data/store_info.twig")
  70.      *
  71.      * @param Request $request
  72.      *
  73.      * @return array
  74.      */
  75.     public function store_info(Request $request)
  76.     {
  77.         $Stores $this->storeRepository->findAll();
  78.         if (null === $Stores) {
  79.             throw new NotFoundHttpException();
  80.         }
  81.         $event = new EventArgs(
  82.             [
  83.                 'Stores' => $Stores,
  84.                 'file' => '@user_data/store_info.twig',
  85.             ],
  86.             $request
  87.         );
  88.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_USER_DATA_INDEX_INITIALIZE);
  89.         $arr_store_addr = [];
  90.         foreach($Stores as $s)
  91.         {
  92.             $addr = [];
  93.             $addr[] = $s->getPref() ? $s->getPref()->getName() : '';
  94.             $addr[] = $s->getAddr01();
  95.             $addr[] = $s->getAddr02();
  96.             $arr_store_addr[$s->getStoreId()] = implode(','array_filter($addr));
  97.         }
  98.         return [
  99.             'Stores' => $Stores,
  100.             'Address' => $arr_store_addr
  101.         ];
  102.     }
  103.     /**
  104.      * @Route("/%eccube_user_data_route%/mypage_itemlist", name="mypage_itemlist", methods={"GET"})
  105.      * @Template("@user_data/mypage_itemlist.twig")
  106.      *
  107.      * @param Request $request
  108.      *
  109.      * @return array
  110.      */
  111.     public function mypage_itemlist(Request $request)
  112.     {
  113.         $School $this->getUser()->getSchool();
  114.         // $Items = $this->productSchoolRepository->findBy(['School' => $School]);
  115.         $Items $this->productSchoolRepository->getNecessityBySchool($School);
  116.         $man_item = [];
  117.         $woman_item = [];
  118.         $common_item = [];
  119.         foreach($Items as $Item){
  120.             if($Item->getProduct()->isEnable()) {
  121.                 switch ($Item->getCommodityType()) {
  122.                     case 1:
  123.                         $man_item[] = $Item;
  124.                         break;
  125.                     case 2:
  126.                         $woman_item[] = $Item;
  127.                         break;
  128.                     case 3:
  129.                         $man_item[] = $Item;
  130.                         $woman_item[] = $Item;
  131.                         break;
  132.                     default:
  133.                         break;
  134.                 }
  135.             }
  136.         }
  137.         // usort($man_item, function($a, $b) {
  138.         //     return $this->productPriorityRepository->getMaxPriorityByProductId($a->getProduct()->getId()) < $this->productPriorityRepository->getMaxPriorityByProductId($b->getProduct()->getId());
  139.         // });
  140.         // usort($woman_item, function($a, $b) {
  141.         //     return $this->productPriorityRepository->getMaxPriorityByProductId($a->getProduct()->getId()) < $this->productPriorityRepository->getMaxPriorityByProductId($b->getProduct()->getId());
  142.         // });
  143.         $event = new EventArgs(
  144.             [
  145.                 'Items' => $Items,
  146.                 'file' => '@user_data/mypage_itemlist.twig',
  147.             ],
  148.             $request
  149.         );
  150.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_USER_DATA_INDEX_INITIALIZE);
  151.         return [
  152.             'MenItem' => $man_item,
  153.             'WomenItem' => $woman_item,
  154.             'CommonItem' => $common_item,
  155.         ];
  156.     }
  157.     /**
  158.      * @Route("/%eccube_user_data_route%/{route}", name="user_data", requirements={"route": "([0-9a-zA-Z_\-]+\/?)+(?<!\/)"}, methods={"GET"})
  159.      */
  160.     public function index(Request $request$route)
  161.     {
  162.         $Page $this->pageRepository->findOneBy(
  163.             [
  164.                 'url' => $route,
  165.                 'edit_type' => Page::EDIT_TYPE_USER,
  166.             ]
  167.         );
  168.         if (null === $Page) {
  169.             throw new NotFoundHttpException();
  170.         }
  171.         $file sprintf('@user_data/%s.twig'$Page->getFileName());
  172.         $event = new EventArgs(
  173.             [
  174.                 'Page' => $Page,
  175.                 'file' => $file,
  176.             ],
  177.             $request
  178.         );
  179.         $this->eventDispatcher->dispatch($eventEccubeEvents::FRONT_USER_DATA_INDEX_INITIALIZE);
  180.         return $this->render($file);
  181.     }
  182. }