|
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\Entity; |
|
15
|
|
|
|
|
16
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
17
|
|
|
|
|
18
|
|
|
if (!class_exists('\Eccube\Entity\Layout')) { |
|
19
|
|
|
/** |
|
20
|
|
|
* Layout |
|
21
|
|
|
* |
|
22
|
|
|
* @ORM\Table(name="dtb_layout") |
|
23
|
|
|
* @ORM\InheritanceType("SINGLE_TABLE") |
|
24
|
|
|
* @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255) |
|
25
|
|
|
* @ORM\HasLifecycleCallbacks() |
|
26
|
|
|
* @ORM\Entity(repositoryClass="Eccube\Repository\LayoutRepository") |
|
27
|
|
|
*/ |
|
28
|
|
|
class Layout extends AbstractEntity |
|
29
|
|
|
{ |
|
30
|
|
|
// 配置ID |
|
31
|
|
|
/** 配置ID: 未使用 */ |
|
32
|
|
|
const TARGET_ID_UNUSED = 0; |
|
33
|
|
|
const TARGET_ID_HEAD = 1; |
|
34
|
|
|
const TARGET_ID_BODY_AFTER = 2; |
|
35
|
|
|
const TARGET_ID_HEADER = 3; |
|
36
|
|
|
const TARGET_ID_CONTENTS_TOP = 4; |
|
37
|
|
|
const TARGET_ID_SIDE_LEFT = 5; |
|
38
|
|
|
const TARGET_ID_MAIN_TOP = 6; |
|
39
|
|
|
const TARGET_ID_MAIN_BOTTOM = 7; |
|
40
|
|
|
const TARGET_ID_SIDE_RIGHT = 8; |
|
41
|
|
|
const TARGET_ID_CONTENTS_BOTTOM = 9; |
|
42
|
|
|
const TARGET_ID_FOOTER = 10; |
|
43
|
|
|
const TARGET_ID_DRAWER = 11; |
|
44
|
|
|
const TARGET_ID_CLOSE_BODY_BEFORE = 12; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* トップページ用レイアウト |
|
48
|
|
|
*/ |
|
49
|
|
|
const DEFAULT_LAYOUT_TOP_PAGE = 1; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* 下層ページ用レイアウト |
|
53
|
|
|
*/ |
|
54
|
|
|
const DEFAULT_LAYOUT_UNDERLAYER_PAGE = 2; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @return string |
|
58
|
|
|
*/ |
|
59
|
|
|
public function __toString() |
|
60
|
|
|
{ |
|
61
|
|
|
return (string) $this->name; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function isDefault() |
|
65
|
|
|
{ |
|
66
|
|
|
return in_array($this->id, [self::DEFAULT_LAYOUT_TOP_PAGE, self::DEFAULT_LAYOUT_UNDERLAYER_PAGE]); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @return Page[] |
|
71
|
|
|
*/ |
|
72
|
|
|
public function getPages() |
|
73
|
|
|
{ |
|
74
|
|
|
$Pages = []; |
|
75
|
|
|
foreach ($this->PageLayouts as $PageLayout) { |
|
76
|
|
|
$Pages[] = $PageLayout->getPage(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return $Pages; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @param integer|null $targetId |
|
84
|
|
|
* |
|
85
|
|
|
* @return Block[] |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getBlocks($targetId = null) |
|
88
|
|
|
{ |
|
89
|
|
|
/** @var BlockPosition[] $TargetBlockPositions */ |
|
90
|
|
|
$TargetBlockPositions = []; |
|
91
|
|
|
// $targetIdのBlockPositionのみ抽出 |
|
92
|
|
|
foreach ($this->BlockPositions as $BlockPosition) { |
|
93
|
|
|
if (is_null($targetId)) { |
|
94
|
|
|
$TargetBlockPositions[] = $BlockPosition; |
|
95
|
|
|
continue; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
if ($BlockPosition->getSection() == $targetId) { |
|
99
|
|
|
$TargetBlockPositions[] = $BlockPosition; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
// blockRow順にsort |
|
104
|
|
|
uasort($TargetBlockPositions, function (BlockPosition $a, BlockPosition $b) { |
|
105
|
|
|
return ($a->getBlockRow() < $b->getBlockRow()) ? -1 : 1; |
|
106
|
|
|
}); |
|
107
|
|
|
|
|
108
|
|
|
// Blockの配列を作成 |
|
109
|
|
|
$TargetBlocks = []; |
|
110
|
|
|
foreach ($TargetBlockPositions as $BlockPosition) { |
|
111
|
|
|
$TargetBlocks[] = $BlockPosition->getBlock(); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
return $TargetBlocks; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
/** |
|
118
|
|
|
* @param integer $targetId |
|
119
|
|
|
* |
|
120
|
|
|
* @return BlockPosition[] |
|
121
|
|
|
*/ |
|
122
|
|
|
public function getBlockPositionsByTargetId($targetId) |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->BlockPositions->filter( |
|
125
|
|
|
function ($BlockPosition) use ($targetId) { |
|
126
|
|
|
return $BlockPosition->getSection() == $targetId; |
|
127
|
|
|
} |
|
128
|
|
|
); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
public function getUnused() |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->getBlocks(self::TARGET_ID_UNUSED); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
public function getHead() |
|
137
|
|
|
{ |
|
138
|
|
|
return $this->getBlocks(self::TARGET_ID_HEAD); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function getBodyAfter() |
|
142
|
|
|
{ |
|
143
|
|
|
return $this->getBlocks(self::TARGET_ID_BODY_AFTER); |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
public function getHeader() |
|
147
|
|
|
{ |
|
148
|
|
|
return $this->getBlocks(self::TARGET_ID_HEADER); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
public function getContentsTop() |
|
152
|
|
|
{ |
|
153
|
|
|
return $this->getBlocks(self::TARGET_ID_CONTENTS_TOP); |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
public function getSideLeft() |
|
157
|
|
|
{ |
|
158
|
|
|
return $this->getBlocks(self::TARGET_ID_SIDE_LEFT); |
|
159
|
|
|
} |
|
160
|
|
|
|
|
161
|
|
|
public function getMainTop() |
|
162
|
|
|
{ |
|
163
|
|
|
return $this->getBlocks(self::TARGET_ID_MAIN_TOP); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
public function getMainBottom() |
|
167
|
|
|
{ |
|
168
|
|
|
return $this->getBlocks(self::TARGET_ID_MAIN_BOTTOM); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
public function getSideRight() |
|
172
|
|
|
{ |
|
173
|
|
|
return $this->getBlocks(self::TARGET_ID_SIDE_RIGHT); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
public function getContentsBottom() |
|
177
|
|
|
{ |
|
178
|
|
|
return $this->getBlocks(self::TARGET_ID_CONTENTS_BOTTOM); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
public function getFooter() |
|
182
|
|
|
{ |
|
183
|
|
|
return $this->getBlocks(self::TARGET_ID_FOOTER); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
public function getDrawer() |
|
187
|
|
|
{ |
|
188
|
|
|
return $this->getBlocks(self::TARGET_ID_DRAWER); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
public function getCloseBodyBefore() |
|
192
|
|
|
{ |
|
193
|
|
|
return $this->getBlocks(self::TARGET_ID_CLOSE_BODY_BEFORE); |
|
194
|
|
|
} |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* Get ColumnNum |
|
198
|
|
|
* |
|
199
|
|
|
* @return integer |
|
200
|
|
|
*/ |
|
201
|
|
|
public function getColumnNum() |
|
202
|
|
|
{ |
|
203
|
|
|
return 1 + ($this->getSideLeft() ? 1 : 0) + ($this->getSideRight() ? 1 : 0); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
// ----------------------- |
|
207
|
|
|
// generated by doctrine |
|
208
|
|
|
// ----------------------- |
|
209
|
|
|
|
|
210
|
|
|
/** |
|
211
|
|
|
* @var integer |
|
212
|
|
|
* |
|
213
|
|
|
* @ORM\Column(name="id", type="integer", options={"unsigned":true}) |
|
214
|
|
|
* @ORM\Id |
|
215
|
|
|
* @ORM\GeneratedValue(strategy="IDENTITY") |
|
216
|
|
|
*/ |
|
217
|
|
|
private $id; |
|
218
|
|
|
|
|
219
|
|
|
/** |
|
220
|
|
|
* @var string |
|
221
|
|
|
* |
|
222
|
|
|
* @ORM\Column(name="layout_name", type="string", length=255, nullable=true) |
|
223
|
|
|
*/ |
|
224
|
|
|
private $name; |
|
225
|
|
|
|
|
226
|
|
|
/** |
|
227
|
|
|
* @var \DateTime |
|
228
|
|
|
* |
|
229
|
|
|
* @ORM\Column(name="create_date", type="datetimetz") |
|
230
|
|
|
*/ |
|
231
|
|
|
private $create_date; |
|
232
|
|
|
|
|
233
|
|
|
/** |
|
234
|
|
|
* @var \DateTime |
|
235
|
|
|
* |
|
236
|
|
|
* @ORM\Column(name="update_date", type="datetimetz") |
|
237
|
|
|
*/ |
|
238
|
|
|
private $update_date; |
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* @var \Doctrine\Common\Collections\Collection |
|
242
|
|
|
* |
|
243
|
|
|
* @ORM\OneToMany(targetEntity="Eccube\Entity\BlockPosition", mappedBy="Layout", cascade={"persist","remove"}) |
|
244
|
|
|
*/ |
|
245
|
|
|
private $BlockPositions; |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* @var \Doctrine\Common\Collections\Collection |
|
249
|
|
|
* |
|
250
|
|
|
* @ORM\OneToMany(targetEntity="Eccube\Entity\PageLayout", mappedBy="Layout", cascade={"persist","remove"}) |
|
251
|
|
|
* @ORM\OrderBy({"sort_no" = "ASC"}) |
|
252
|
|
|
*/ |
|
253
|
|
|
private $PageLayouts; |
|
254
|
|
|
|
|
255
|
|
|
/** |
|
256
|
|
|
* @var \Eccube\Entity\Master\DeviceType |
|
257
|
|
|
* |
|
258
|
|
|
* @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\DeviceType") |
|
259
|
|
|
* @ORM\JoinColumns({ |
|
260
|
|
|
* @ORM\JoinColumn(name="device_type_id", referencedColumnName="id") |
|
261
|
|
|
* }) |
|
262
|
|
|
*/ |
|
263
|
|
|
private $DeviceType; |
|
264
|
|
|
|
|
265
|
|
|
/** |
|
266
|
|
|
* Constructor |
|
267
|
|
|
*/ |
|
268
|
|
|
public function __construct() |
|
269
|
|
|
{ |
|
270
|
|
|
$this->BlockPositions = new \Doctrine\Common\Collections\ArrayCollection(); |
|
271
|
|
|
$this->PageLayouts = new \Doctrine\Common\Collections\ArrayCollection(); |
|
272
|
|
|
} |
|
273
|
|
|
|
|
274
|
|
|
/** |
|
275
|
|
|
* Get id |
|
276
|
|
|
* |
|
277
|
|
|
* @return integer |
|
278
|
|
|
*/ |
|
279
|
|
|
public function getId() |
|
280
|
|
|
{ |
|
281
|
|
|
return $this->id; |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
/** |
|
285
|
|
|
* Set name |
|
286
|
|
|
* |
|
287
|
|
|
* @param string $name |
|
288
|
|
|
* |
|
289
|
|
|
* @return Layout |
|
290
|
|
|
*/ |
|
291
|
|
|
public function setName($name) |
|
292
|
|
|
{ |
|
293
|
|
|
$this->name = $name; |
|
294
|
|
|
|
|
295
|
|
|
return $this; |
|
296
|
|
|
} |
|
297
|
|
|
|
|
298
|
|
|
/** |
|
299
|
|
|
* Get name |
|
300
|
|
|
* |
|
301
|
|
|
* @return string |
|
302
|
|
|
*/ |
|
303
|
|
|
public function getName() |
|
304
|
|
|
{ |
|
305
|
|
|
return $this->name; |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
/** |
|
309
|
|
|
* Set createDate |
|
310
|
|
|
* |
|
311
|
|
|
* @param \DateTime $createDate |
|
312
|
|
|
* |
|
313
|
|
|
* @return Layout |
|
314
|
|
|
*/ |
|
315
|
|
|
public function setCreateDate($createDate) |
|
316
|
|
|
{ |
|
317
|
|
|
$this->create_date = $createDate; |
|
318
|
|
|
|
|
319
|
|
|
return $this; |
|
320
|
|
|
} |
|
321
|
|
|
|
|
322
|
|
|
/** |
|
323
|
|
|
* Get createDate |
|
324
|
|
|
* |
|
325
|
|
|
* @return \DateTime |
|
326
|
|
|
*/ |
|
327
|
|
|
public function getCreateDate() |
|
328
|
|
|
{ |
|
329
|
|
|
return $this->create_date; |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
/** |
|
333
|
|
|
* Set updateDate |
|
334
|
|
|
* |
|
335
|
|
|
* @param \DateTime $updateDate |
|
336
|
|
|
* |
|
337
|
|
|
* @return Layout |
|
338
|
|
|
*/ |
|
339
|
|
|
public function setUpdateDate($updateDate) |
|
340
|
|
|
{ |
|
341
|
|
|
$this->update_date = $updateDate; |
|
342
|
|
|
|
|
343
|
|
|
return $this; |
|
344
|
|
|
} |
|
345
|
|
|
|
|
346
|
|
|
/** |
|
347
|
|
|
* Get updateDate |
|
348
|
|
|
* |
|
349
|
|
|
* @return \DateTime |
|
350
|
|
|
*/ |
|
351
|
|
|
public function getUpdateDate() |
|
352
|
|
|
{ |
|
353
|
|
|
return $this->update_date; |
|
354
|
|
|
} |
|
355
|
|
|
|
|
356
|
|
|
/** |
|
357
|
|
|
* Add blockPosition |
|
358
|
|
|
* |
|
359
|
|
|
* @param \Eccube\Entity\BlockPosition $blockPosition |
|
360
|
|
|
* |
|
361
|
|
|
* @return Layout |
|
362
|
|
|
*/ |
|
363
|
|
|
public function addBlockPosition(\Eccube\Entity\BlockPosition $blockPosition) |
|
364
|
|
|
{ |
|
365
|
|
|
$this->BlockPositions[] = $blockPosition; |
|
366
|
|
|
|
|
367
|
|
|
return $this; |
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
|
/** |
|
371
|
|
|
* Remove blockPosition |
|
372
|
|
|
* |
|
373
|
|
|
* @param \Eccube\Entity\BlockPosition $blockPosition |
|
374
|
|
|
*/ |
|
375
|
|
|
public function removeBlockPosition(\Eccube\Entity\BlockPosition $blockPosition) |
|
376
|
|
|
{ |
|
377
|
|
|
$this->BlockPositions->removeElement($blockPosition); |
|
378
|
|
|
} |
|
379
|
|
|
|
|
380
|
|
|
/** |
|
381
|
|
|
* Get blockPositions |
|
382
|
|
|
* |
|
383
|
|
|
* @return \Doctrine\Common\Collections\Collection |
|
384
|
|
|
*/ |
|
385
|
|
|
public function getBlockPositions() |
|
386
|
|
|
{ |
|
387
|
|
|
return $this->BlockPositions; |
|
388
|
|
|
} |
|
389
|
|
|
|
|
390
|
|
|
/** |
|
391
|
|
|
* Add pageLayoutLayout |
|
392
|
|
|
* |
|
393
|
|
|
* @param \Eccube\Entity\PageLayout $PageLayout |
|
394
|
|
|
* |
|
395
|
|
|
* @return Layout |
|
396
|
|
|
*/ |
|
397
|
|
|
public function addPageLayout(\Eccube\Entity\PageLayout $PageLayout) |
|
398
|
|
|
{ |
|
399
|
|
|
$this->PageLayouts[] = $PageLayout; |
|
400
|
|
|
|
|
401
|
|
|
return $this; |
|
402
|
|
|
} |
|
403
|
|
|
|
|
404
|
|
|
/** |
|
405
|
|
|
* Remove pageLayoutLayout |
|
406
|
|
|
* |
|
407
|
|
|
* @param \Eccube\Entity\PageLayout $PageLayout |
|
408
|
|
|
*/ |
|
409
|
|
|
public function removePageLayout(\Eccube\Entity\PageLayout $PageLayout) |
|
410
|
|
|
{ |
|
411
|
|
|
$this->PageLayouts->removeElement($PageLayout); |
|
412
|
|
|
} |
|
413
|
|
|
|
|
414
|
|
|
/** |
|
415
|
|
|
* Get pageLayoutLayouts |
|
416
|
|
|
* |
|
417
|
|
|
* @return \Doctrine\Common\Collections\Collection |
|
418
|
|
|
*/ |
|
419
|
|
|
public function getPageLayouts() |
|
420
|
|
|
{ |
|
421
|
|
|
return $this->PageLayouts; |
|
422
|
|
|
} |
|
423
|
|
|
|
|
424
|
|
|
/** |
|
425
|
|
|
* Set deviceType |
|
426
|
|
|
* |
|
427
|
|
|
* @param \Eccube\Entity\Master\DeviceType $deviceType |
|
428
|
|
|
* |
|
429
|
|
|
* @return Layout |
|
430
|
|
|
*/ |
|
431
|
|
|
public function setDeviceType(\Eccube\Entity\Master\DeviceType $deviceType = null) |
|
432
|
|
|
{ |
|
433
|
|
|
$this->DeviceType = $deviceType; |
|
434
|
|
|
|
|
435
|
|
|
return $this; |
|
436
|
|
|
} |
|
437
|
|
|
|
|
438
|
|
|
/** |
|
439
|
|
|
* Get deviceType |
|
440
|
|
|
* |
|
441
|
|
|
* @return \Eccube\Entity\Master\DeviceType |
|
442
|
|
|
*/ |
|
443
|
|
|
public function getDeviceType() |
|
444
|
|
|
{ |
|
445
|
|
|
return $this->DeviceType; |
|
446
|
|
|
} |
|
447
|
|
|
|
|
448
|
|
|
/** |
|
449
|
|
|
* Check layout can delete or not |
|
450
|
|
|
* |
|
451
|
|
|
* @return boolean |
|
452
|
|
|
*/ |
|
453
|
|
|
public function isDeletable() |
|
454
|
|
|
{ |
|
455
|
|
|
if (!$this->getPageLayouts()->isEmpty()) { |
|
456
|
|
|
return false; |
|
457
|
|
|
} |
|
458
|
|
|
|
|
459
|
|
|
return true; |
|
460
|
|
|
} |
|
461
|
|
|
} |
|
462
|
|
|
} |
|
463
|
|
|
|