app/Customize/Controller/Admin/School/ShopGuideController.php line 184

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\Admin\School;
  13. use Eccube\Controller\AbstractController;
  14. use Eccube\Entity\Page;
  15. use Eccube\Entity\PageLayout;
  16. use Eccube\Event\EccubeEvents;
  17. use Eccube\Event\EventArgs;
  18. use Customize\Form\Type\Admin\ShopGuideEditType;
  19. use Eccube\Repository\Master\DeviceTypeRepository;
  20. use Eccube\Repository\PageLayoutRepository;
  21. use Eccube\Repository\PageRepository;
  22. use Eccube\Util\CacheUtil;
  23. use Eccube\Util\StringUtil;
  24. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  25. use Symfony\Component\Filesystem\Filesystem;
  26. use Symfony\Component\HttpFoundation\Request;
  27. use Symfony\Component\Routing\Annotation\Route;
  28. use Symfony\Component\Routing\RouterInterface;
  29. use Twig\Environment;
  30. use Customize\Repository\SchoolRepository;
  31. class ShopGuideController extends AbstractController
  32. {
  33.     /**
  34.      * @var PageRepository
  35.      */
  36.     protected $pageRepository;
  37.     /**
  38.      * @var PageLayoutRepository
  39.      */
  40.     protected $pageLayoutRepository;
  41.     /**
  42.      * @var DeviceTypeRepository
  43.      */
  44.     protected $deviceTypeRepository;
  45.     /**
  46.      * @var SchoolRepository
  47.      */
  48.     protected $schoolRepository;
  49.     /**
  50.      * PageController constructor.
  51.      *
  52.      * @param PageRepository $pageRepository
  53.      * @param DeviceTypeRepository $deviceTypeRepository
  54.      */
  55.     public function __construct(
  56.         PageRepository $pageRepository,
  57.         PageLayoutRepository $pageLayoutRepository,
  58.         DeviceTypeRepository $deviceTypeRepository,
  59.         SchoolRepository $schoolRepository
  60.     ) {
  61.         $this->pageRepository $pageRepository;
  62.         $this->pageLayoutRepository $pageLayoutRepository;
  63.         $this->deviceTypeRepository $deviceTypeRepository;
  64.         $this->schoolRepository $schoolRepository;
  65.     }
  66.     /**
  67.      * @Route("/%eccube_admin_route%/school/shop_guide/{id}/edit/{page_id}", requirements={"id" = "\d+"}, requirements={"page_id" = "\d+"},name="admin_school_shop_guide_edit", methods={"GET", "POST"})
  68.      * @Template("@admin/School/shop_guide.twig")
  69.      */
  70.     public function edit(Request $request$id nullEnvironment $twigCacheUtil $cacheUtil$page_id null)
  71.     {
  72.         $Page $this->pageRepository->newPage();
  73.         $fs = new Filesystem();
  74.         if($page_id == '4'){
  75.             $guide_file_name 'Block/School/delivery_guide'.$id;
  76.             $org_file_name 'Block/delivery_guide';
  77.         }
  78.         else{
  79.             $guide_file_name 'Help/School/guide'.$id;
  80.             $org_file_name 'Help/guide';
  81.         }
  82.         $templatePath $this->getParameter('eccube_theme_front_dir');
  83.         $guideFilePath $templatePath.'/'.$guide_file_name.'.twig';
  84.         if (!$fs->exists($guideFilePath)) {
  85.             $fs->copy($templatePath.'/'.$org_file_name.'.twig'$guideFilePath);
  86.         }
  87.         $arr_section_file_name = ['payment_method''product_delivery''incorrect_size''''order_flow'];
  88.         if($page_id != '4')
  89.         {
  90.             $org_file_name1 'Help/guide_'.$arr_section_file_name[$page_id 1];
  91.             $guide_file_name1 'Help/School/guide_'.$arr_section_file_name[$page_id 1].$id;
  92.             $guideFilePath1 $templatePath.'/'.$guide_file_name1.'.twig';
  93.             if (!$fs->exists($guideFilePath1)) {
  94.                 $fs->copy($templatePath.'/'.$org_file_name1.'.twig'$guideFilePath1);
  95.             }
  96.             $guide_file_name $guide_file_name1;
  97.         }
  98.         $guideFilePath $templatePath.'/'.$guide_file_name.'.twig';
  99.         $Page->setFileName($guide_file_name);
  100.         $isUserDataPage false;
  101.         $builder $this->formFactory
  102.             ->createBuilder(ShopGuideEditType::class, $Page);
  103.         $event = new EventArgs(
  104.             [
  105.                 'builder' => $builder,
  106.                 'Page' => $Page,
  107.             ],
  108.             $request
  109.         );
  110.         $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_SCHOOL_SHOP_GUIDE_EDIT_INITIALIZE);
  111.         $form $builder->getForm();
  112.         // 更新時
  113.         $fileName null;
  114.         $source $twig->getLoader()
  115.             ->getSourceContext($guide_file_name.'.twig')
  116.             ->getCode();
  117.         $form->get('tpl_data')->setData($source);
  118.         $form->handleRequest($request);
  119.         if ($form->isSubmitted() && $form->isValid()) {
  120.             $Page $form->getData();
  121.             $pageData $form->get('tpl_data')->getData();
  122.             $pageData StringUtil::convertLineFeed($pageData);
  123.             $fs->dumpFile($guideFilePath$pageData);
  124.             $event = new EventArgs(
  125.                 [
  126.                     'form' => $form,
  127.                     'Page' => $Page,
  128.                     'templatePath' => $templatePath,
  129.                     'filePath' => $guideFilePath,
  130.                 ],
  131.                 $request
  132.             );
  133.             $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_SCHOOL_SHOP_GUIDE_EDIT_COMPLETE);
  134.             $this->addSuccess('admin.common.save_complete''admin');
  135.             // キャッシュの削除
  136.             $cacheUtil->clearTwigCache();
  137.             $cacheUtil->clearDoctrineCache();
  138.             return $this->redirectToRoute('admin_school_shop_guide_edit', ['id' => $id'page_id' => $page_id]);
  139.         }
  140.         $url '';
  141.         $projectDir $this->getParameter('kernel.project_dir');
  142.         $templatePath str_replace($projectDir.'/'''$templatePath);
  143.         return [
  144.             'form' => $form->createView(),
  145.             'page_id' => $Page->getId(),
  146.             'is_user_data_page' => $isUserDataPage,
  147.             'is_confirm_page' => $Page->getEditType() == Page::EDIT_TYPE_DEFAULT_CONFIRM,
  148.             'template_path' => $templatePath,
  149.             'url' => $url,
  150.             'school_id' => $id,
  151.             'page_id' => $page_id,
  152.             'School' => $this->schoolRepository->find($id)
  153.         ];
  154.     }
  155.     /**
  156.      * @Route("/%eccube_admin_route%/school/shop_guide/{id}/restore/{page_id}", requirements={"id" = "\d+"}, requirements={"page_id" = "\d+"},name="admin_school_shop_guide_restore", methods={"GET"})
  157.      *
  158.      */
  159.     public function restore(Request $request$id null$page_id nullEnvironment $twigRouterInterface $routerCacheUtil $cacheUtil)
  160.     {
  161.         $Page $this->pageRepository->newPage();
  162.         $fs = new Filesystem();
  163.         $arr_section_file_name = ['payment_method''product_delivery''incorrect_size''''order_flow'];
  164.         if($page_id == '4'){
  165.             $guide_file_name 'Block/School/delivery_guide'.$id;
  166.             $org_file_name 'Block/delivery_guide';
  167.         }
  168.         else{
  169.             $guide_file_name 'Help/School/guide_'.$arr_section_file_name[$page_id 1].$id;
  170.             $org_file_name 'Help/guide_'.$arr_section_file_name[$page_id 1];
  171.         }
  172.         $templatePath $this->getParameter('eccube_theme_front_dir');
  173.         $guideFilePath $templatePath.'/'.$guide_file_name.'.twig';
  174.         if ($fs->exists($guideFilePath)) {
  175.             $fs->remove($guideFilePath);
  176.             $fs->copy($templatePath.'/'.$org_file_name.'.twig'$guideFilePath);
  177.         }
  178.         $event = new EventArgs(
  179.             [
  180.                 'Page' => $Page,
  181.                 'templatePath' => $templatePath,
  182.                 'filePath' => $guideFilePath,
  183.             ],
  184.             $request
  185.         );
  186.         $this->eventDispatcher->dispatch($eventEccubeEvents::ADMIN_SCHOOL_SHOP_GUIDE_RESTORE_COMPLETE);
  187.         $this->addSuccess('admin.common.save_complete''admin');
  188.         // キャッシュの削除
  189.         $cacheUtil->clearTwigCache();
  190.         $cacheUtil->clearDoctrineCache();
  191.         return $this->redirectToRoute('admin_school_shop_guide_edit', ['id' => $id'page_id' => $page_id]);
  192.     }
  193. }