Failed Conditions
Pull Request — 4.0 (#3691)
by Kentaro
06:03
created

Page::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
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\Entity;
15
16
use Doctrine\ORM\Mapping as ORM;
17
18 1
if (!class_exists('\Eccube\Entity\Page')) {
19
    /**
20
     * Page
21
     *
22
     * @ORM\Table(name="dtb_page", indexes={@ORM\Index(name="dtb_page_url_idx", columns={"url"})})
23
     * @ORM\InheritanceType("SINGLE_TABLE")
24
     * @ORM\DiscriminatorColumn(name="discriminator_type", type="string", length=255)
25
     * @ORM\HasLifecycleCallbacks()
26
     * @ORM\Entity(repositoryClass="Eccube\Repository\PageRepository")
27
     */
28
    class Page extends \Eccube\Entity\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
        const EDIT_TYPE_USER = 0;
48
        const EDIT_TYPE_PREVIEW = 1;
49
        const EDIT_TYPE_DEFAULT = 2;
50
51 147
        // 特定商取引法ページID
52
        const TRADELAW_PAGE_ID = 21;
53 147
54 147
        // ご利用規約ページID
55 116
        const AGREEMENT_PAGE_ID = 19;
56
57
        public function getLayouts()
58 147
        {
59
            $Layouts = [];
60
            foreach ($this->PageLayouts as $PageLayout) {
61
                $Layouts[] = $PageLayout->getLayout();
62
            }
63
64
            return $Layouts;
65
        }
66 113
67
        /**
68 113
         * Get ColumnNum
69
         *
70
         * @return integer
71
         */
72
        public function getColumnNum()
73
        {
74
            return 1 + ($this->getSideLeft() ? 1 : 0) + ($this->getSideRight() ? 1 : 0);
75
        }
76
77
        public function getTheme()
78
        {
79
            $hasLeft = $this->getSideLeft() ? true : false;
80
            $hasRight = $this->getSideRight() ? true : false;
81
82
            $theme = 'theme_main_only';
83
            if ($hasLeft && $hasRight) {
84
                $theme = 'theme_side_both';
85
            } elseif ($hasLeft) {
86
                $theme = 'theme_side_left';
87
            } elseif ($hasRight) {
88
                $theme = 'theme_side_right';
89
            }
90
91
            return $theme;
92
        }
93
94
        /**
95
         * Get BlockPositionByTargetId
96
         *
97
         * @param integer $target_id
98
         *
99
         * @return array
100
         */
101
        public function getBlocksPositionByTargetId($target_id)
102
        {
103
            $BlockPositions = [];
104
            foreach ($this->getBlockPositions() as $BlockPosition) {
105
                if ($BlockPosition->getSection() === $target_id) {
106
                    $BlockPositions[] = $BlockPosition;
107
                }
108
            }
109
110
            return $BlockPositions;
111
        }
112
113
        /**
114
         * @deprecated
115
         *
116
         * @return BlockPosition
117
         */
118
        public function getUnusedPosition()
119
        {
120
            return $this->getBlocksPositionByTargetId(self::TARGET_ID_UNUSED);
121
        }
122
123
        /**
124
         * @deprecated
125
         *
126
         * @return BlockPosition
127
         */
128
        public function getHeadPosition()
129
        {
130
            return $this->getBlocksPositionByTargetId(self::TARGET_ID_HEAD);
131
        }
132
133
        /**
134
         * @deprecated
135
         *
136
         * @return BlockPosition
137
         */
138
        public function getHeaderPosition()
139
        {
140
            return $this->getBlocksPositionByTargetId(self::TARGET_ID_HEADER);
141
        }
142
143
        /**
144
         * @deprecated
145
         *
146
         * @return BlockPosition
147
         */
148
        public function getContentsTopPosition()
149
        {
150
            return $this->getBlocksPositionByTargetId(self::TARGET_ID_CONTENTS_TOP);
151
        }
152
153
        /**
154
         * @deprecated
155
         *
156
         * @return BlockPosition
157
         */
158
        public function getSideLeftPosition()
159
        {
160
            return $this->getBlocksPositionByTargetId(self::TARGET_ID_SIDE_LEFT);
161
        }
162
163
        /**
164
         * @deprecated
165
         *
166
         * @return BlockPosition
167
         */
168
        public function getMainTopPosition()
169
        {
170
            return $this->getBlocksPositionByTargetId(self::TARGET_ID_MAIN_TOP);
171
        }
172
173
        /**
174
         * @deprecated
175
         *
176
         * @return BlockPosition
177
         */
178
        public function getMainBottomPosition()
179
        {
180
            return $this->getBlocksPositionByTargetId(self::TARGET_ID_MAIN_BOTTOM);
181
        }
182
183
        /**
184
         * @deprecated
185
         *
186
         * @return BlockPosition
187
         */
188
        public function getSideRightPosition()
189
        {
190
            return $this->getBlocksPositionByTargetId(self::TARGET_ID_SIDE_RIGHT);
191
        }
192
193
        /**
194
         * @deprecated
195
         *
196
         * @return BlockPosition
197
         */
198
        public function getContentsBottomPosition()
199
        {
200
            return $this->getBlocksPositionByTargetId(self::TARGET_ID_CONTENTS_BOTTOM);
201
        }
202
203
        public function getFooterPosition()
204
        {
205
            return $this->getBlocksPositionByTargetId(self::TARGET_ID_FOOTER);
206
        }
207
208
        /**
209
         * @deprecated
210
         *
211
         * Get BlocsByTargetId
212
         *
213
         * @param integer $target_id
214
         *
215
         * @return \Eccube\Entity\Block[]
216
         */
217
        public function getBlocksByTargetId($target_id)
218
        {
219
            $Blocks = [];
220
            foreach ($this->getBlockPositions() as $BlockPositions) {
221
                if ($BlockPositions->getTargetId() === $target_id) {
222
                    $Blocks[] = $BlockPositions->getBlock();
223
                }
224
            }
225
226
            return $Blocks;
227
        }
228 113
229
        public function getUnused()
230 113
        {
231
            return $this->getBlocksByTargetId(self::TARGET_ID_UNUSED);
0 ignored issues
show
Deprecated Code introduced by
The method Eccube\Entity\Page::getBlocksByTargetId() has been deprecated with message: Get BlocsByTargetId

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
232 113
        }
233
234
        public function getHead()
235 113
        {
236
            $Layout = current($this->getLayouts());
237 113
238
            return $Layout ? $Layout->getBlocks(self::TARGET_ID_HEAD) : [];
239 113
        }
240
241
        public function getBodyAfter()
242 113
        {
243
            $Layout = current($this->getLayouts());
244 113
245
            return $Layout ? $Layout->getBlocks(self::TARGET_ID_BODY_AFTER) : [];
246 113
        }
247
248
        public function getHeader()
249 113
        {
250
            $Layout = current($this->getLayouts());
251 113
252
            return $Layout ? $Layout->getBlocks(self::TARGET_ID_HEADER) : [];
253 113
        }
254
255
        public function getContentsTop()
256 113
        {
257
            $Layout = current($this->getLayouts());
258 113
259
            return $Layout ? $Layout->getBlocks(self::TARGET_ID_CONTENTS_TOP) : [];
260 113
        }
261
262
        public function getSideLeft()
263 113
        {
264
            $Layout = current($this->getLayouts());
265 113
266
            return $Layout ? $Layout->getBlocks(self::TARGET_ID_SIDE_LEFT) : [];
267 113
        }
268
269
        public function getMainTop()
270 113
        {
271
            $Layout = current($this->getLayouts());
272 113
273
            return $Layout ? $Layout->getBlocks(self::TARGET_ID_MAIN_TOP) : [];
274 113
        }
275
276
        public function getMainBottom()
277 113
        {
278
            $Layout = current($this->getLayouts());
279 113
280
            return $Layout ? $Layout->getBlocks(self::TARGET_ID_MAIN_BOTTOM) : [];
281 113
        }
282
283
        public function getSideRight()
284 113
        {
285
            $Layout = current($this->getLayouts());
286 113
287
            return $Layout ? $Layout->getBlocks(self::TARGET_ID_SIDE_RIGHT) : [];
288 113
        }
289
290
        public function getContentsBottom()
291 113
        {
292
            $Layout = current($this->getLayouts());
293 113
294
            return $Layout ? $Layout->getBlocks(self::TARGET_ID_CONTENTS_BOTTOM) : [];
295 113
        }
296
297
        public function getFooter()
298 113
        {
299
            $Layout = current($this->getLayouts());
300 113
301
            return $Layout ? $Layout->getBlocks(self::TARGET_ID_FOOTER) : [];
302 113
        }
303
304
        public function getDrawer()
305 113
        {
306
            $Layout = current($this->getLayouts());
307 113
308
            return $Layout ? $Layout->getBlocks(self::TARGET_ID_DRAWER) : [];
309 113
        }
310
311
        public function getCloseBodyBefore()
312
        {
313
            $Layout = current($this->getLayouts());
314
315
            return $Layout ? $Layout->getBlocks(self::TARGET_ID_CLOSE_BODY_BEFORE) : [];
316
        }
317
318
        /**
319
         * @var int
320
         *
321
         * @ORM\Column(name="id", type="integer", options={"unsigned":true})
322
         * @ORM\Id
323
         * @ORM\GeneratedValue(strategy="IDENTITY")
324
         */
325
        private $id;
326
327
        /**
328
         * @var string|null
329
         *
330
         * @ORM\Column(name="page_name", type="string", length=255, nullable=true)
331
         */
332
        private $name;
333
334
        /**
335
         * @var string
336
         *
337
         * @ORM\Column(name="url", type="string", length=255)
338
         */
339
        private $url;
340
341
        /**
342
         * @var string|null
343
         *
344
         * @ORM\Column(name="file_name", type="string", length=255, nullable=true)
345
         */
346
        private $file_name;
347
348
        /**
349
         * @var int
350
         *
351
         * @ORM\Column(name="edit_type", type="smallint", options={"unsigned":true,"default":1})
352
         */
353
        private $edit_type = 1;
354
355
        /**
356
         * @var string|null
357
         *
358
         * @ORM\Column(name="author", type="string", length=255, nullable=true)
359
         */
360
        private $author;
361
362
        /**
363
         * @var string|null
364
         *
365
         * @ORM\Column(name="description", type="string", length=255, nullable=true)
366
         */
367
        private $description;
368
369
        /**
370
         * @var string|null
371
         *
372
         * @ORM\Column(name="keyword", type="string", length=255, nullable=true)
373
         */
374
        private $keyword;
375
376
        /**
377
         * @var \DateTime
378
         *
379
         * @ORM\Column(name="create_date", type="datetimetz")
380
         */
381
        private $create_date;
382
383
        /**
384
         * @var \DateTime
385
         *
386
         * @ORM\Column(name="update_date", type="datetimetz")
387
         */
388
        private $update_date;
389
390
        /**
391
         * @var string|null
392
         *
393
         * @ORM\Column(name="meta_robots", type="string", length=255, nullable=true)
394
         */
395
        private $meta_robots;
396
397
        /**
398
         * @var string|null
399
         *
400
         * @ORM\Column(name="meta_tags", type="string", length=4000, nullable=true)
401
         */
402
        private $meta_tags;
403
404
        /**
405
         * @var \Doctrine\Common\Collections\Collection
406
         *
407
         * @ORM\OneToMany(targetEntity="Eccube\Entity\BlockPosition", mappedBy="Page", cascade={"persist","remove"})
408
         *
409
         * @deprecated
410
         */
411
        private $BlockPositions;
412
413
        /**
414
         * @var \Doctrine\Common\Collections\Collection
415
         *
416
         * @ORM\OneToMany(targetEntity="Eccube\Entity\PageLayout", mappedBy="Page", cascade={"persist","remove"})
417
         */
418
        private $PageLayouts;
419
420
        /**
421
         * @var \Eccube\Entity\Master\DeviceType
422
         *
423
         * @ORM\ManyToOne(targetEntity="Eccube\Entity\Master\DeviceType")
424
         * @ORM\JoinColumns({
425
         *   @ORM\JoinColumn(name="device_type_id", referencedColumnName="id")
426
         * })
427
         */
428
        private $DeviceType;
429
430
        /**
431
         * @var \Eccube\Entity\Page
432
         *
433
         * @ORM\ManyToOne(targetEntity="Eccube\Entity\Page")
434
         * @ORM\JoinColumns({
435
         *   @ORM\JoinColumn(name="master_page_id", referencedColumnName="id")
436
         * })
437
         */
438
        private $MasterPage;
439
440
        /**
441
         * Constructor
442
         */
443
        public function __construct()
444 127
        {
445
            $this->BlockPositions = new \Doctrine\Common\Collections\ArrayCollection();
0 ignored issues
show
Deprecated Code introduced by
The property Eccube\Entity\Page::$BlockPositions has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
446 127
            $this->PageLayouts = new \Doctrine\Common\Collections\ArrayCollection();
447 127
        }
448
449
        /**
450
         * Set id
451
         *
452
         * @return Page
453
         */
454
        public function setId($id)
455
        {
456
            $this->id = $id;
457
458
            return $this;
459
        }
460
461
        /**
462
         * Get id
463
         *
464
         * @return integer
465
         */
466
        public function getId()
467 41
        {
468
            return $this->id;
469 41
        }
470
471
        /**
472
         * Set name.
473
         *
474
         * @param string|null $name
475
         *
476
         * @return Page
477
         */
478
        public function setName($name = null)
479 34
        {
480
            $this->name = $name;
481 34
482
            return $this;
483 34
        }
484
485
        /**
486
         * Get name.
487
         *
488
         * @return string|null
489
         */
490
        public function getName()
491 186
        {
492
            return $this->name;
493 186
        }
494
495
        /**
496
         * Set url.
497
         *
498
         * @param string $url
499
         *
500
         * @return Page
501
         */
502
        public function setUrl($url)
503 37
        {
504
            $this->url = $url;
505 37
506
            return $this;
507 37
        }
508
509
        /**
510
         * Get url.
511
         *
512
         * @return string
513
         */
514
        public function getUrl()
515 36
        {
516
            return $this->url;
517 36
        }
518
519
        /**
520
         * Set fileName.
521
         *
522
         * @param string|null $fileName
523
         *
524
         * @return Page
525
         */
526
        public function setFileName($fileName = null)
527 35
        {
528
            $this->file_name = $fileName;
529 35
530
            return $this;
531 35
        }
532
533
        /**
534
         * Get fileName.
535
         *
536
         * @return string|null
537
         */
538
        public function getFileName()
539 36
        {
540
            return $this->file_name;
541 36
        }
542
543
        /**
544
         * Set editType.
545
         *
546
         * @param int $editType
547
         *
548
         * @return Page
549
         */
550
        public function setEditType($editType)
551 126
        {
552
            $this->edit_type = $editType;
553 126
554
            return $this;
555 126
        }
556
557
        /**
558
         * Get editType.
559
         *
560
         * @return int
561
         */
562
        public function getEditType()
563 5
        {
564
            return $this->edit_type;
565 5
        }
566
567
        /**
568
         * Set author.
569
         *
570
         * @param string|null $author
571
         *
572
         * @return Page
573
         */
574
        public function setAuthor($author = null)
575 31
        {
576
            $this->author = $author;
577 31
578
            return $this;
579 31
        }
580
581
        /**
582
         * Get author.
583
         *
584
         * @return string|null
585
         */
586
        public function getAuthor()
587 147
        {
588
            return $this->author;
589 147
        }
590
591
        /**
592
         * Set description.
593
         *
594
         * @param string|null $description
595
         *
596
         * @return Page
597
         */
598
        public function setDescription($description = null)
599 31
        {
600
            $this->description = $description;
601 31
602
            return $this;
603 31
        }
604
605
        /**
606
         * Get description.
607
         *
608
         * @return string|null
609
         */
610
        public function getDescription()
611 147
        {
612
            return $this->description;
613 147
        }
614
615
        /**
616
         * Set keyword.
617
         *
618
         * @param string|null $keyword
619
         *
620
         * @return Page
621
         */
622
        public function setKeyword($keyword = null)
623 31
        {
624
            $this->keyword = $keyword;
625 31
626
            return $this;
627 31
        }
628
629
        /**
630
         * Get keyword.
631
         *
632
         * @return string|null
633
         */
634
        public function getKeyword()
635 147
        {
636
            return $this->keyword;
637 147
        }
638
639
        /**
640
         * Set createDate.
641
         *
642
         * @param \DateTime $createDate
643
         *
644
         * @return Page
645
         */
646
        public function setCreateDate($createDate)
647
        {
648
            $this->create_date = $createDate;
649
650
            return $this;
651
        }
652
653
        /**
654
         * Get createDate.
655
         *
656
         * @return \DateTime
657
         */
658
        public function getCreateDate()
659
        {
660
            return $this->create_date;
661
        }
662
663
        /**
664
         * Set updateDate.
665
         *
666
         * @param \DateTime $updateDate
667
         *
668
         * @return Page
669
         */
670
        public function setUpdateDate($updateDate)
671 36
        {
672
            $this->update_date = $updateDate;
673 36
674
            return $this;
675 36
        }
676
677
        /**
678
         * Get updateDate.
679
         *
680
         * @return \DateTime
681
         */
682
        public function getUpdateDate()
683
        {
684
            return $this->update_date;
685
        }
686
687
        /**
688
         * Set metaRobots.
689
         *
690
         * @param string|null $metaRobots
691
         *
692
         * @return Page
693
         */
694
        public function setMetaRobots($metaRobots = null)
695 37
        {
696
            $this->meta_robots = $metaRobots;
697 37
698
            return $this;
699 37
        }
700
701
        /**
702
         * Get metaRobots.
703
         *
704
         * @return string|null
705
         */
706
        public function getMetaRobots()
707
        {
708
            return $this->meta_robots;
709
        }
710
711
        /**
712
         * Set meta_tags
713
         *
714
         * @param string $metaTags
715
         *
716
         * @return Page
717
         */
718
        public function setMetaTags($metaTags)
719 31
        {
720
            $this->meta_tags = $metaTags;
721 31
722
            return $this;
723 31
        }
724
725
        /**
726
         * Get meta_tags
727
         *
728
         * @return string
729
         */
730
        public function getMetaTags()
731 147
        {
732
            return $this->meta_tags;
733 147
        }
734
735
        /**
736
         * Add blockPosition.
737
         *
738
         * @param \Eccube\Entity\BlockPosition $blockPosition
739
         *
740
         * @return Page
741
         */
742
        public function addBlockPosition(\Eccube\Entity\BlockPosition $blockPosition)
743 31
        {
744
            $this->BlockPositions[] = $blockPosition;
0 ignored issues
show
Deprecated Code introduced by
The property Eccube\Entity\Page::$BlockPositions has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
745 31
746
            return $this;
747 31
        }
748
749
        /**
750
         * Remove blockPosition.
751
         *
752
         * @param \Eccube\Entity\BlockPosition $blockPosition
753
         *
754
         * @return boolean TRUE if this collection contained the specified element, FALSE otherwise.
755 34
         */
756
        public function removeBlockPosition(\Eccube\Entity\BlockPosition $blockPosition)
757 34
        {
758
            return $this->BlockPositions->removeElement($blockPosition);
0 ignored issues
show
Deprecated Code introduced by
The property Eccube\Entity\Page::$BlockPositions has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
759
        }
760
761
        /**
762
         * Get pageLayoutLayout.
763
         *
764
         * @return \Doctrine\Common\Collections\Collection
765
         */
766
        public function getPageLayouts()
767
        {
768
            return $this->PageLayouts;
769
        }
770
771
        /**
772
         * Add pageLayoutLayout
773
         *
774
         * @param \Eccube\Entity\PageLayout $PageLayout
775
         *
776
         * @return Page
777
         */
778
        public function addPageLayout(\Eccube\Entity\PageLayout $PageLayout)
779
        {
780
            $this->PageLayouts[] = $PageLayout;
781
782
            return $this;
783
        }
784
785
        /**
786
         * Remove pageLayoutLayout
787
         *
788
         * @param \Eccube\Entity\PageLayout $PageLayout
789
         */
790
        public function removePageLayout(\Eccube\Entity\PageLayout $PageLayout)
791 2
        {
792
            $this->PageLayouts->removeElement($PageLayout);
793 2
        }
794
795
        /**
796
         * Get blockPositions.
797
         *
798
         * @return \Doctrine\Common\Collections\Collection
799
         */
800
        public function getBlockPositions()
801
        {
802
            return $this->BlockPositions;
0 ignored issues
show
Deprecated Code introduced by
The property Eccube\Entity\Page::$BlockPositions has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
803
        }
804
805
        /**
806
         * Set deviceType.
807
         *
808
         * @param \Eccube\Entity\Master\DeviceType|null $deviceType
809
         *
810
         * @return Page
811
         */
812
        public function setDeviceType(\Eccube\Entity\Master\DeviceType $deviceType = null)
813
        {
814
            $this->DeviceType = $deviceType;
815 1
816
            return $this;
817 1
        }
818
819
        /**
820
         * Get deviceType.
821
         *
822
         * @return \Eccube\Entity\Master\DeviceType|null
823
         */
824
        public function getDeviceType()
825 6
        {
826
            return $this->DeviceType;
827 6
        }
828
829
        /**
830
         * Set MasterPage.
831
         *
832
         * @param \Eccube\Entity\Page|null $page
833
         *
834
         * @return Page
835
         */
836
        public function setMasterPage(\Eccube\Entity\Page $page = null)
837 127
        {
838
            $this->MasterPage = $page;
839 127
840
            return $this;
841 127
        }
842
843
        /**
844
         * Get MasterPage.
845
         *
846
         * @return \Eccube\Entity\Page|null
847
         */
848
        public function getMasterPage()
849 34
        {
850
            return $this->MasterPage;
851 34
        }
852
853
        /**
854
         * @param $layoutId
855
         *
856
         * @return null|int
857
         */
858
        public function getSortNo($layoutId)
859
        {
860
            $pageLayouts = $this->getPageLayouts();
861
862
            /** @var PageLayout $pageLayout */
863
            foreach ($pageLayouts as $pageLayout) {
864
                if ($pageLayout->getLayoutId() == $layoutId) {
865
                    return $pageLayout->getSortNo();
866
                }
867
            }
868
869
            return null;
870
        }
871
    }
872
}
873