src/Eccube/Entity/Layout.php line 28

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