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 Eccube\Annotation\Inject; |
28
|
|
|
use Eccube\Annotation\Repository; |
29
|
|
|
use Eccube\Entity\Master\DeviceType; |
30
|
|
|
use Eccube\Entity\Page; |
31
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* PageRepository |
35
|
|
|
* |
36
|
|
|
* This class was generated by the Doctrine ORM. Add your own custom |
37
|
|
|
* repository methods below. |
38
|
|
|
* |
39
|
|
|
* @Repository |
40
|
|
|
*/ |
41
|
|
|
class PageRepository extends AbstractRepository |
42
|
|
|
{ |
43
|
|
|
/** |
44
|
|
|
* @Inject("config") |
45
|
|
|
* @var array |
46
|
|
|
*/ |
47
|
|
|
protected $appConfig; |
48
|
|
|
|
49
|
|
|
public function findUnusedBlocks(DeviceType $DeviceType, $pageId) |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
$em = $this |
52
|
|
|
->getEntityManager(); |
53
|
|
|
$blockRepo = $em->getRepository('Eccube\Entity\Block'); |
54
|
|
|
$ownBlockPositions = $this->getByDeviceTypeAndId($DeviceType, $pageId)->getBlockPositions(); |
55
|
|
|
$ids = array(); |
56
|
|
|
foreach ($ownBlockPositions as $ownBlockPosition) { |
57
|
|
|
$ids[] = $ownBlockPosition->getBlock()->getId(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
# $idsが空配列だと、$ids以外のblockを取得するSQLが生成されないため、存在しないidを入れる |
|
|
|
|
61
|
|
|
if (empty($ids)) { |
62
|
|
|
$ids[] = \Eccube\Entity\Block::UNUSED_BLOCK_ID; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
return $blockRepo->createQueryBuilder('b') |
66
|
|
|
->where('b.id not in (:ids)') |
67
|
|
|
->setParameter(':ids', $ids) |
68
|
|
|
->getQuery() |
69
|
|
|
->getResult(); |
70
|
|
|
} |
71
|
|
|
|
72
|
4 |
|
public function getByDeviceTypeAndId(DeviceType $DeviceType, $pageId) |
|
|
|
|
73
|
|
|
{ |
74
|
4 |
|
$qb = $this->createQueryBuilder('p') |
75
|
4 |
|
->select('p, bp, b') |
76
|
4 |
|
->leftJoin('p.BlockPositions', 'bp', 'WITH', 'p.id = bp.page_id') |
77
|
4 |
|
->leftJoin('bp.Block', 'b') |
78
|
4 |
|
->andWhere('p.DeviceType = :DeviceType AND p.id = :pageId') |
79
|
4 |
|
->addOrderBy('bp.target_id', 'ASC') |
80
|
4 |
|
->addOrderBy('bp.block_row', 'ASC'); |
81
|
|
|
|
82
|
|
|
$ownResult = $qb |
83
|
4 |
|
->getQuery() |
84
|
4 |
|
->setParameters(array( |
85
|
4 |
|
'DeviceType' => $DeviceType, |
86
|
4 |
|
'pageId' => $pageId, |
87
|
|
|
)) |
88
|
4 |
|
->getSingleResult(); |
89
|
|
|
|
90
|
4 |
|
$qb = $this->createQueryBuilder('p') |
91
|
4 |
|
->select('p, bp, b') |
92
|
4 |
|
->leftJoin('p.BlockPositions', 'bp', 'WITH', 'p.id = bp.page_id') |
93
|
4 |
|
->leftJoin('bp.Block', 'b') |
94
|
4 |
|
->andWhere('p.DeviceType = :DeviceType AND bp.anywhere = 1') |
95
|
4 |
|
->addOrderBy('bp.target_id', 'ASC') |
96
|
4 |
|
->addOrderBy('bp.block_row', 'ASC'); |
97
|
|
|
|
98
|
|
|
$anyResults = $qb |
99
|
4 |
|
->getQuery() |
100
|
4 |
|
->setParameters(array( |
101
|
4 |
|
'DeviceType' => $DeviceType, |
102
|
|
|
)) |
103
|
4 |
|
->getResult(); |
104
|
|
|
|
105
|
4 |
|
$OwnBlockPosition = $ownResult->getBlockPositions(); |
106
|
4 |
View Code Duplication |
foreach ($anyResults as $anyResult) { |
107
|
4 |
|
$BlockPositions = $anyResult->getBlockPositions(); |
108
|
4 |
|
foreach ($BlockPositions as $BlockPosition) { |
109
|
4 |
|
if (!$OwnBlockPosition->contains($BlockPosition)) { |
110
|
4 |
|
$ownResult->addBlockPosition($BlockPosition); |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
115
|
4 |
|
return $ownResult; |
116
|
|
|
|
117
|
|
|
} |
118
|
|
|
|
119
|
1 |
|
public function getByUrl(DeviceType $DeviceType, $url) |
|
|
|
|
120
|
|
|
{ |
121
|
1 |
|
$options = $this->appConfig['doctrine_cache']; |
122
|
1 |
|
$lifetime = $options['result_cache']['lifetime']; |
123
|
|
|
|
124
|
1 |
|
$qb = $this->createQueryBuilder('p') |
125
|
1 |
|
->select('p, bp, b') |
126
|
1 |
|
->leftJoin('p.BlockPositions', 'bp', 'WITH', 'p.id = bp.page_id') |
127
|
1 |
|
->leftJoin('bp.Block', 'b') |
128
|
1 |
|
->andWhere('p.DeviceType = :DeviceType AND p.url = :url') |
129
|
1 |
|
->addOrderBy('bp.target_id', 'ASC') |
130
|
1 |
|
->addOrderBy('bp.block_row', 'ASC'); |
131
|
|
|
|
132
|
|
|
$ownResult = $qb |
133
|
1 |
|
->getQuery() |
134
|
1 |
|
->useResultCache(true, $lifetime) |
135
|
1 |
|
->setParameters(array( |
136
|
1 |
|
'DeviceType' => $DeviceType, |
137
|
1 |
|
'url' => $url, |
138
|
|
|
)) |
139
|
1 |
|
->getSingleResult(); |
140
|
|
|
|
141
|
1 |
|
$qb = $this->createQueryBuilder('p') |
142
|
1 |
|
->select('p, bp, b') |
143
|
1 |
|
->leftJoin('p.BlockPositions', 'bp', 'WITH', 'p.id = bp.page_id') |
144
|
1 |
|
->leftJoin('bp.Block', 'b') |
145
|
1 |
|
->andWhere('p.DeviceType = :DeviceType AND bp.anywhere = 1') |
146
|
1 |
|
->addOrderBy('bp.target_id', 'ASC') |
147
|
1 |
|
->addOrderBy('bp.block_row', 'ASC'); |
148
|
|
|
|
149
|
|
|
$anyResults = $qb |
150
|
1 |
|
->getQuery() |
151
|
1 |
|
->useResultCache(true, $lifetime) |
152
|
1 |
|
->setParameters(array( |
153
|
1 |
|
'DeviceType' => $DeviceType, |
154
|
|
|
)) |
155
|
1 |
|
->getResult(); |
156
|
|
|
|
157
|
1 |
|
$OwnBlockPosition = $ownResult->getBlockPositions(); |
158
|
1 |
View Code Duplication |
foreach ($anyResults as $anyResult) { |
159
|
1 |
|
$BlockPositions = $anyResult->getBlockPositions(); |
160
|
1 |
|
foreach ($BlockPositions as $BlockPosition) { |
161
|
1 |
|
if (!$OwnBlockPosition->contains($BlockPosition)) { |
162
|
1 |
|
$ownResult->addBlockPosition($BlockPosition); |
163
|
|
|
} |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
167
|
1 |
|
return $ownResult; |
168
|
|
|
} |
169
|
|
|
|
170
|
34 |
|
public function newPage(DeviceType $DeviceType) |
|
|
|
|
171
|
|
|
{ |
172
|
34 |
|
$Page = new \Eccube\Entity\Page(); |
173
|
|
|
$Page |
174
|
34 |
|
->setDeviceType($DeviceType) |
175
|
34 |
|
->setEditFlg(Page::EDIT_FLG_USER); |
176
|
|
|
|
177
|
34 |
|
return $Page; |
178
|
|
|
} |
179
|
|
|
|
180
|
4 |
|
public function findOrCreate($page_id, DeviceType $DeviceType) |
|
|
|
|
181
|
|
|
{ |
182
|
4 |
|
if (is_null($page_id)) { |
183
|
|
|
$Page = $this |
184
|
1 |
|
->newPage($DeviceType); |
185
|
1 |
|
return $Page; |
|
|
|
|
186
|
|
|
} else { |
187
|
3 |
|
return $this->getByDeviceTypeAndId($DeviceType, $page_id); |
188
|
|
|
} |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* ページの属性を取得する. |
193
|
|
|
* |
194
|
|
|
* この関数は, dtb_Page の情報を検索する. |
195
|
|
|
* $deviceTypeId は必須. デフォルト値は DEVICE_TYPE_PC. |
196
|
|
|
* |
197
|
|
|
* @access public |
198
|
|
|
* @param \Eccube\Entity\Master\DeviceType $DeviceType 端末種別ID |
|
|
|
|
199
|
|
|
* @param string $where 追加の検索条件 |
|
|
|
|
200
|
|
|
* @param string[] $parameters 追加の検索パラメーター |
|
|
|
|
201
|
|
|
* @return array ページ属性の配列 |
202
|
|
|
*/ |
203
|
2 |
View Code Duplication |
public function getPageList(DeviceType $DeviceType, $where = null, $parameters = array()) |
|
|
|
|
204
|
|
|
{ |
205
|
2 |
|
$qb = $this->createQueryBuilder('l') |
206
|
2 |
|
->orderBy('l.id', 'DESC') |
207
|
2 |
|
->where('l.DeviceType = :DeviceType') |
208
|
2 |
|
->setParameter('DeviceType', $DeviceType) |
209
|
2 |
|
->andWhere('l.id <> 0') |
210
|
2 |
|
->orderBy('l.id', 'ASC'); |
211
|
2 |
|
if (!is_null($where)) { |
212
|
|
|
$qb->andWhere($where); |
213
|
|
|
foreach ($parameters as $key => $val) { |
214
|
|
|
$qb->setParameter($key, $val); |
215
|
|
|
} |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
$Pages = $qb |
219
|
2 |
|
->getQuery() |
220
|
2 |
|
->getResult(); |
221
|
|
|
|
222
|
2 |
|
return $Pages; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* 書き込みパスの取得 |
227
|
|
|
* User定義の場合: /html/user_data |
228
|
|
|
* そうでない場合: /app/template/{template_code} |
229
|
|
|
* |
230
|
|
|
* @param boolean $isUser |
231
|
|
|
* @return string |
232
|
|
|
*/ |
233
|
5 |
|
public function getWriteTemplatePath($isUser = false) |
234
|
|
|
{ |
235
|
5 |
|
return ($isUser) ? $this->appConfig['user_data_realdir'] : $this->appConfig['template_realdir']; |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* 読み込みファイルの取得 |
240
|
|
|
* |
241
|
|
|
* 1. template_realdir |
242
|
|
|
* app/template/{template_code} |
243
|
|
|
* 2. template_default_readldir |
244
|
|
|
* src/Eccube/Resource/template/default |
245
|
|
|
* |
246
|
|
|
* @param string $fileName |
|
|
|
|
247
|
|
|
* @param boolean $isUser |
248
|
|
|
* |
249
|
|
|
* @return array |
250
|
|
|
*/ |
251
|
5 |
|
public function getReadTemplateFile($fileName, $isUser = false) |
252
|
|
|
{ |
253
|
5 |
|
if ($isUser) { |
254
|
|
|
$readPaths = array( |
255
|
1 |
|
$this->appConfig['user_data_realdir'], |
256
|
|
|
); |
257
|
|
|
} else { |
258
|
|
|
$readPaths = array( |
259
|
4 |
|
$this->appConfig['template_realdir'], |
260
|
4 |
|
$this->appConfig['template_default_realdir'], |
261
|
|
|
); |
262
|
|
|
} |
263
|
|
|
|
264
|
5 |
View Code Duplication |
foreach ($readPaths as $readPath) { |
265
|
5 |
|
$filePath = $readPath . '/' . $fileName . '.twig'; |
|
|
|
|
266
|
5 |
|
$fs = new Filesystem(); |
267
|
5 |
|
if ($fs->exists($filePath)) { |
268
|
|
|
return array( |
269
|
5 |
|
'file_name' => $fileName, |
270
|
5 |
|
'tpl_data' => file_get_contents($filePath), |
271
|
|
|
); |
272
|
|
|
} |
273
|
|
|
} |
274
|
|
|
} |
275
|
|
|
} |
276
|
|
|
|