src/Entity/ArticleBlock.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. /**
  7.  * @ORM\Entity(repositoryClass="App\Repository\ArticleBlockRepository")
  8.  *
  9.  * @ORM\HasLifecycleCallbacks()
  10.  *
  11.  * @ORM\Table(indexes={
  12.  *
  13.  *     @ORM\Index(name="article_deleted_idx", columns={"deleted_at"})
  14.  * })
  15.  */
  16. class ArticleBlock
  17. {
  18.     public const ARTICLE_BLOCK_COLUMN 'ARTICLE_BLOCK_COLUMN';
  19.     public const ARTICLE_BLOCK_MEDIA 'ARTICLE_BLOCK_MEDIA';
  20.     public const ARTICLE_BLOCK_EMBED 'ARTICLE_BLOCK_EMBED';
  21.     public const ARTICLE_BLOCK_ROW 'ARTICLE_BLOCK_ROW';
  22.     public const ARTICLE_BLOCK_HTML 'ARTICLE_BLOCK_HTML';
  23.     public const ARTICLE_BLOCK_ARTICLE 'ARTICLE_BLOCK_ARTICLE';
  24.     public function __construct()
  25.     {
  26.         $this->children = new ArrayCollection();
  27.     }
  28.     /**
  29.      * @ORM\Id()
  30.      *
  31.      * @ORM\GeneratedValue()
  32.      *
  33.      * @ORM\Column(type="integer")
  34.      */
  35.     private $id;
  36.     /**
  37.      * @ORM\Column(type="integer", nullable=false)
  38.      */
  39.     private $position 0;
  40.     /**
  41.      * @ORM\Column(type="string", length=180, nullable=false)
  42.      */
  43.     private $block_type self::ARTICLE_BLOCK_HTML;
  44.     /**
  45.      * @ORM\Column(type="text", nullable=true)
  46.      */
  47.     private $data null;
  48.     /**
  49.      * @ORM\ManyToOne(targetEntity="App\Entity\ArticleBlock", inversedBy="children")
  50.      *
  51.      * @ORM\JoinColumn(nullable=true)
  52.      */
  53.     private $parent;
  54.     public function getId(): ?int
  55.     {
  56.         return $this->id;
  57.     }
  58.     public function getType()
  59.     {
  60.         return $this->block_type;
  61.     }
  62.     public function setType($type)
  63.     {
  64.         $this->block_type $type;
  65.         return $this;
  66.     }
  67.     public function getData()
  68.     {
  69.         return $this->data;
  70.     }
  71.     public function setData($data)
  72.     {
  73.         $this->data $data;
  74.         return $this;
  75.     }
  76.     public function getPosition()
  77.     {
  78.         return $this->position;
  79.     }
  80.     public function setPosition($position)
  81.     {
  82.         $this->position $position;
  83.         return $this;
  84.     }
  85.     public function getParent(): ?self
  86.     {
  87.         return $this->parent;
  88.     }
  89.     public function setParent(?self $parent): self
  90.     {
  91.         $this->parent $parent;
  92.         return $this;
  93.     }
  94.     /**
  95.      * @ORM\Column(type="datetime", nullable=false)
  96.      */
  97.     private $created_at;
  98.     /**
  99.      * @ORM\Column(type="datetime", nullable=true)
  100.      */
  101.     private $updated_at null;
  102.     public function getCreatedAt(): \DateTimeInterface
  103.     {
  104.         return $this->created_at;
  105.     }
  106.     public function setCreatedAt(\DateTimeInterface $created_at): self
  107.     {
  108.         $this->created_at $created_at;
  109.         return $this;
  110.     }
  111.     public function getUpdatedAt(): ?\DateTimeInterface
  112.     {
  113.         return $this->updated_at;
  114.     }
  115.     public function setUpdatedAt(?\DateTimeInterface $updated_at): self
  116.     {
  117.         $this->updated_at $updated_at;
  118.         return $this;
  119.     }
  120.     /**
  121.      * @ORM\PrePersist
  122.      */
  123.     public function setCreatedAtValue()
  124.     {
  125.         $this->setCreatedAt(new \DateTime());
  126.     }
  127.     /**
  128.      * @ORM\PreUpdate
  129.      */
  130.     public function setUpdatedAtValue()
  131.     {
  132.         $this->setUpdatedAt(new \DateTime());
  133.     }
  134.     /**
  135.      * @ORM\Column(type="datetime", nullable=true)
  136.      */
  137.     private $deleted_at;
  138.     public function getDeletedAt(): ?\DateTimeInterface
  139.     {
  140.         return $this->deleted_at;
  141.     }
  142.     public function setDeletedAt(?\DateTimeInterface $deleted_at): self
  143.     {
  144.         $this->deleted_at $deleted_at;
  145.         return $this;
  146.     }
  147.     // Target of a LinkedEntity from ArticleBlockController (Controller)
  148.     // Target of a OneToMany from Media (Entity)
  149.     /**
  150.      * @ORM\ManyToOne(targetEntity="App\Entity\Media", inversedBy="article_blocks")
  151.      *
  152.      * @ORM\JoinColumn(nullable=true)
  153.      */
  154.     private $media;
  155.     public function getMedia(): ?Media
  156.     {
  157.         return $this->media;
  158.     }
  159.     public function setMedia(?Media $media): self
  160.     {
  161.         $this->media $media;
  162.         return $this;
  163.     }
  164.     // Target of a OneToMany from Article (Entity)
  165.     /**
  166.      * @ORM\ManyToOne(targetEntity="App\Entity\Article", inversedBy="article_blocks")
  167.      *
  168.      * @ORM\JoinColumn(nullable=true)
  169.      */
  170.     private $article;
  171.     public function getArticle(): ?Article
  172.     {
  173.         return $this->article;
  174.     }
  175.     public function setArticle(?Article $article): self
  176.     {
  177.         $this->article $article;
  178.         return $this;
  179.     }
  180.     /**
  181.      * @ORM\OneToMany(targetEntity="App\Entity\ArticleBlock", mappedBy="parent")
  182.      */
  183.     private $children;
  184.     /**
  185.      * @return Collection|ArticleBlock[]
  186.      */
  187.     public function getChildren(): Collection
  188.     {
  189.         return $this->children;
  190.     }
  191.     public function addChildren(self $article_block): self
  192.     {
  193.         if (!$this->children->contains($article_block)) {
  194.             $this->children[] = $article_block;
  195.             $article_block->setParent($this);
  196.         }
  197.         return $this;
  198.     }
  199.     public function removeChildren(self $article_block): self
  200.     {
  201.         if ($this->children->contains($article_block)) {
  202.             $this->children->removeElement($article_block);
  203.             if ($article_block->getParent() === $this) {
  204.                 $article_block->setParent(null);
  205.             }
  206.         }
  207.         return $this;
  208.     }
  209. }