Failed Conditions
Push — dev/plugin-misc ( f22d99...066a4d )
by Kiyotaka
10:54 queued 03:43
created

PageRepository::getPageByRoute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\Repository;
15
16
use Doctrine\ORM\NoResultException;
17
use Eccube\Common\EccubeConfig;
18
use Eccube\Entity\Page;
19
use Symfony\Bridge\Doctrine\RegistryInterface;
20
use Symfony\Component\DependencyInjection\ContainerInterface;
21
22
/**
23
 * PageRepository
24
 *
25
 * This class was generated by the Doctrine ORM. Add your own custom
26
 * repository methods below.
27
 */
28
class PageRepository extends AbstractRepository
29
{
30
    /**
31
     * @var EccubeConfig
32
     */
33
    protected $eccubeConfig;
34
35
    /**
36
     * @var string
37
     * @path %eccube_theme_user_data_dir% (app/template/user_data)
38
     */
39
    protected $userDataRealDir;
40
41
    /**
42
     * @var string
43
     * @path %eccube_theme_app_dir% (app/template)
44
     */
45
    protected $templateRealDir;
46
47
    /**
48
     * @var string
49
     * @path %eccube_theme_src_dir% (src/Eccube/Resource/template)
50
     */
51
    protected $templateDefaultRealDir;
52
53
    /**
54
     * PageRepository constructor.
55
     *
56
     * @param RegistryInterface $registry
57
     * @param EccubeConfig $eccubeConfig
58
     * @param ContainerInterface $container
59
     */
60
    public function __construct(RegistryInterface $registry, EccubeConfig $eccubeConfig, ContainerInterface $container)
61
    {
62
        parent::__construct($registry, Page::class);
63
        $this->eccubeConfig = $eccubeConfig;
64
        $this->userDataRealDir = $container->getParameter('eccube_theme_user_data_dir');
65
        $this->templateRealDir = $container->getParameter('eccube_theme_app_dir');
66
        $this->templateDefaultRealDir = $container->getParameter('eccube_theme_src_dir');
67
    }
68
69
    /**
70
     * @param $route
71
     * @return Page
72
     */
73
    public function getPageByRoute($route)
74
    {
75
        $qb = $this->createQueryBuilder('p');
76
77
        try {
78
            $Page = $qb
79
                ->select(['p', 'pl', 'l'])
80
                ->leftJoin('p.PageLayouts', 'pl')
81
                ->leftJoin('pl.Layout', 'l')
82
                ->where('p.url = :url')
83
                ->setParameter('url', $route)
84
                ->getQuery()
85
                ->useResultCache(true, $this->getCacheLifetime())
86
                ->getSingleResult();
87
        } catch (\Exception $e) {
88
            return $this->newPage();
89
        }
90
91
        return $Page;
92
    }
93
94
    /**
95
     * @param string $url
96
     *
97
     * @return Page
98
     *
99
     * @throws NoResultException
100
     * @throws \Doctrine\ORM\NonUniqueResultException
101
     */
102
    public function getByUrl($url)
103
    {
104
        $qb = $this->createQueryBuilder('p');
105
        $Page = $qb->select('p')
106
            ->where('p.url = :route')
107
            ->setParameter('route', $url)
108
            ->getQuery()
109
            ->useResultCache(true, $this->getCacheLifetime())
110
            ->getSingleResult();
111
112
        return $Page;
113
    }
114
115
    /**
116
     * @return Page
117
     */
118
    public function newPage()
119
    {
120
        $Page = new \Eccube\Entity\Page();
121
        $Page->setEditType(Page::EDIT_TYPE_USER);
122
123
        return $Page;
124
    }
125
126
    /**
127
     * ページの属性を取得する.
128
     *
129
     * この関数は, dtb_Page の情報を検索する.
130
     *
131
     * @param  string                            $where 追加の検索条件
132
     * @param  string[]                          $parameters 追加の検索パラメーター
133
     *
134
     * @return array                             ページ属性の配列
135
     */
136
    public function getPageList($where = null, $parameters = [])
137
    {
138
        $qb = $this->createQueryBuilder('p')
139
            ->andWhere('p.id <> 0')
140
            ->andWhere('p.MasterPage is null')
141
            ->orderBy('p.id', 'ASC');
142
        if (!is_null($where)) {
143
            $qb->andWhere($where);
144
            foreach ($parameters as $key => $val) {
145
                $qb->setParameter($key, $val);
146
            }
147
        }
148
149
        $Pages = $qb
150
            ->getQuery()
151
            ->getResult();
152
153
        return $Pages;
154
    }
155
}
156