BlockRepository::setApplication()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/*
3
 * This file is part of EC-CUBE
4
 *
5
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
6
 *
7
 * http://www.lockon.co.jp/
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 */
23
24
25
namespace Eccube\Repository;
26
27
use Doctrine\ORM\EntityRepository;
28
use Symfony\Component\Filesystem\Filesystem;
29
30
/**
31
 * BlocRepository
32
 *
33
 * This class was generated by the Doctrine ORM. Add your own custom
34
 * repository methods below.
35
 */
36
class BlockRepository extends EntityRepository
37
{
38
    protected $app;
39
40 14
    public function setApplication($app)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
41
    {
42 14
        $this->app = $app;
43
    }
44
45 5
    public function findOrCreate($block_id, $DeviceType)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
46
    {
47
48 5
        if ($block_id == null) {
49 1
            return $this->newBlock($DeviceType);
50
        } else {
51 5
            return $this->getBlock($block_id, $DeviceType);
52
        }
53
54
    }
55
56 1
    public function newBlock($DeviceType)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
57
    {
58 1
        $Block = new \Eccube\Entity\Block();
59
        $Block
60 1
            ->setDeviceType($DeviceType)
61 1
            ->setLogicFlg(0)
62 1
            ->setDeletableFlg(1);
63
64 1
        return $Block;
65
    }
66
67
    /**
68
     * @deprecated since 3.0.0, to be removed in 3.1
69
     */
70
    private function getNewBlockId($DeviceType)
71
    {
72
73
        $qb = $this->createQueryBuilder('b')
74
            ->select('max(b.id) +1 as block_id')
75
            ->where('b.DeviceType = :DeviceType')
76
            ->setParameter('DeviceType', $DeviceType);
77
        $result = $qb->getQuery()->getSingleResult();
78
79
        return $result['block_id'];
80
81
    }
82
83
    /**
84
     * ブロックの情報を取得.
85
     *
86
     * @param  integer $block_id ブロックID
0 ignored issues
show
introduced by
Expected 26 spaces after parameter type; 1 found
Loading history...
introduced by
Expected 3 spaces after parameter name; 1 found
Loading history...
87
     * @param  \Eccube\Entity\Master\DeviceType $DeviceType
88
     * @return array
89
     */
90 6
    public function getBlock($block_id, $DeviceType)
0 ignored issues
show
introduced by
Declare public methods first, then protected ones and finally private ones
Loading history...
91
    {
92 6
        $Block = $this->findOneBy(array(
93 6
            'id' => $block_id,
94 6
            'DeviceType' => $DeviceType,
95
        ));
96
97 6
        return $Block;
98
    }
99
100
    /**
101
     * ブロック一覧の取得.
102
     *
103
     * @param  \Eccube\Entity\Master\DeviceType $DeviceType
104
     * @return array
105
     */
106 3
    public function getList($DeviceType)
107
    {
108 3
        $qb = $this->createQueryBuilder('b')
109 3
            ->orderBy('b.id', 'DESC')
110 3
            ->where('b.DeviceType = :DeviceType')
111 3
            ->setParameter('DeviceType', $DeviceType);
112
113
        $Blocks = $qb
114 3
            ->getQuery()
115 3
            ->getResult();
116
117 3
        return $Blocks;
118
    }
119
120
    /**
121
     * ページの属性を取得する.
122
     *
123
     * この関数は, dtb_pagelayout の情報を検索する.
124
     * $deviceTypeId は必須. デフォルト値は DEVICE_TYPE_PC.
125
     *
126
     * @access public
127
     * @param  DeviceType $DeviceType 端末種別ID
128
     * @param  string $where 追加の検索条件
0 ignored issues
show
introduced by
Expected 5 spaces after parameter type; 1 found
Loading history...
introduced by
Expected 6 spaces after parameter name; 1 found
Loading history...
129
     * @param  string[] $parameters 追加の検索パラメーター
0 ignored issues
show
introduced by
Expected 3 spaces after parameter type; 1 found
Loading history...
130
     * @return array                             ページ属性の配列
131
     * @deprecated since 3.0.0, to be removed in 3.1
132
     */
133 View Code Duplication
    public function getPageList(DeviceType $DeviceType, $where = null, $parameters = array())
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
134
    {
135
        $qb = $this->createQueryBuilder('l')
136
            ->orderBy('l.id', 'DESC')
137
            ->where('l.DeviceType = :DeviceType')
138
            ->setParameter('DeviceType', $DeviceType)
139
            ->andWhere('l.id <> 0')
140
            ->orderBy('l.id', 'ASC');
141
        if (!is_null($where)) {
142
            $qb->andWhere($where);
143
            foreach ($parameters as $key => $val) {
144
                $qb->setParameter($key, $val);
145
            }
146
        }
147
148
        $PageLayouts = $qb
149
            ->getQuery()
150
            ->getResult();
151
152
        return $PageLayouts;
153
    }
154
155
    /**
156
     * 書き込みパスの取得
157
     * User定義の場合: /html/user_data
158
     * そうでない場合: /app/template/{template_code}
159
     *
160
     * @param  boolean $isUser
161
     * @return string
162
     *
163
     * @deprecated since 3.0.0, to be removed in 3.1
164
     */
165
    public function getWriteTemplatePath($isUser = false)
0 ignored issues
show
Unused Code introduced by
The parameter $isUser is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
166
    {
167
        return $this->app['config']['block_realdir'];
168
    }
169
170
    /**
171
     * 読み込みファイルの取得
172
     *
173
     * 1. block_realdir
174
     *      app/template/{template_code}/block
175
     * 2. block_default_readldir
176
     *      src/Eccube/Resource/template/default/block
177
     *
178
     * @param string $fileName
0 ignored issues
show
introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
179
     * @param  boolean $isUser
180
     *
181
     * @return array
182
     */
183 6
    public function getReadTemplateFile($fileName, $isUser = false)
0 ignored issues
show
Unused Code introduced by
The parameter $isUser is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
184
    {
185
        $readPaths = array(
186 6
            $this->app['config']['block_realdir'],
187 6
            $this->app['config']['block_default_realdir'],
188
        );
189 6 View Code Duplication
        foreach ($readPaths as $readPath) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
190 6
            $filePath = $readPath . '/' . $fileName . '.twig';
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
191 6
            $fs = new Filesystem();
192 6
            if ($fs->exists($filePath)) {
193
                return array(
194 6
                    'file_name' => $fileName,
195 6
                    'tpl_data' => file_get_contents($filePath),
196
                );
197
            }
198
        }
199
    }
200
}
201