src/Eccube/Repository/PageRepository.php line87

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 Eccube\Repository;
  13. use Doctrine\ORM\NoResultException;
  14. use Eccube\Common\EccubeConfig;
  15. use Eccube\Entity\Page;
  16. use Symfony\Bridge\Doctrine\RegistryInterface;
  17. use Symfony\Component\DependencyInjection\ContainerInterface;
  18. /**
  19.  * PageRepository
  20.  *
  21.  * This class was generated by the Doctrine ORM. Add your own custom
  22.  * repository methods below.
  23.  */
  24. class PageRepository extends AbstractRepository
  25. {
  26.     /**
  27.      * @var EccubeConfig
  28.      */
  29.     protected $eccubeConfig;
  30.     /**
  31.      * @var string
  32.      * @path %eccube_theme_user_data_dir% (app/template/user_data)
  33.      */
  34.     protected $userDataRealDir;
  35.     /**
  36.      * @var string
  37.      * @path %eccube_theme_app_dir% (app/template)
  38.      */
  39.     protected $templateRealDir;
  40.     /**
  41.      * @var string
  42.      * @path %eccube_theme_src_dir% (src/Eccube/Resource/template)
  43.      */
  44.     protected $templateDefaultRealDir;
  45.     /**
  46.      * PageRepository constructor.
  47.      *
  48.      * @param RegistryInterface $registry
  49.      * @param EccubeConfig $eccubeConfig
  50.      * @param ContainerInterface $container
  51.      */
  52.     public function __construct(RegistryInterface $registryEccubeConfig $eccubeConfigContainerInterface $container)
  53.     {
  54.         parent::__construct($registryPage::class);
  55.         $this->eccubeConfig $eccubeConfig;
  56.         $this->userDataRealDir $container->getParameter('eccube_theme_user_data_dir');
  57.         $this->templateRealDir $container->getParameter('eccube_theme_app_dir');
  58.         $this->templateDefaultRealDir $container->getParameter('eccube_theme_src_dir');
  59.     }
  60.     /**
  61.      * @param $route
  62.      *
  63.      * @return Page
  64.      */
  65.     public function getPageByRoute($route)
  66.     {
  67.         $qb $this->createQueryBuilder('p');
  68.         try {
  69.             $Page $qb
  70.                 ->select(['p''pl''l'])
  71.                 ->leftJoin('p.PageLayouts''pl')
  72.                 ->leftJoin('pl.Layout''l')
  73.                 ->where('p.url = :url')
  74.                 ->setParameter('url'$route)
  75.                 ->getQuery()
  76.                 ->useResultCache(true$this->getCacheLifetime())
  77.                 ->getSingleResult();
  78.         } catch (\Exception $e) {
  79.             return $this->newPage();
  80.         }
  81.         return $Page;
  82.     }
  83.     /**
  84.      * @param string $url
  85.      *
  86.      * @return Page
  87.      *
  88.      * @throws NoResultException
  89.      * @throws \Doctrine\ORM\NonUniqueResultException
  90.      */
  91.     public function getByUrl($url)
  92.     {
  93.         $qb $this->createQueryBuilder('p');
  94.         $Page $qb->select('p')
  95.             ->where('p.url = :route')
  96.             ->setParameter('route'$url)
  97.             ->getQuery()
  98.             ->useResultCache(true$this->getCacheLifetime())
  99.             ->getSingleResult();
  100.         return $Page;
  101.     }
  102.     /**
  103.      * @return Page
  104.      */
  105.     public function newPage()
  106.     {
  107.         $Page = new \Eccube\Entity\Page();
  108.         $Page->setEditType(Page::EDIT_TYPE_USER);
  109.         return $Page;
  110.     }
  111.     /**
  112.      * ページの属性を取得する.
  113.      *
  114.      * この関数は, dtb_Page の情報を検索する.
  115.      *
  116.      * @param  string                            $where 追加の検索条件
  117.      * @param  string[]                          $parameters 追加の検索パラメーター
  118.      *
  119.      * @return array                             ページ属性の配列
  120.      */
  121.     public function getPageList($where null$parameters = [])
  122.     {
  123.         $qb $this->createQueryBuilder('p')
  124.             ->andWhere('p.id <> 0')
  125.             ->andWhere('p.MasterPage is null')
  126.             ->orderBy('p.id''ASC');
  127.         if (!is_null($where)) {
  128.             $qb->andWhere($where);
  129.             foreach ($parameters as $key => $val) {
  130.                 $qb->setParameter($key$val);
  131.             }
  132.         }
  133.         $Pages $qb
  134.             ->getQuery()
  135.             ->getResult();
  136.         return $Pages;
  137.     }
  138. }