src/Entity/Block.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\BlockRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Mapping\Annotation as Gedmo;
  9. #[ORM\Entity(repositoryClassBlockRepository::class)]
  10. class Block
  11. {
  12.     const TYPE_HTML "html";
  13.     const TYPE_QUESTION "question";
  14.     const TYPE_AUDIO "audio";
  15.     const TYPE_AUDIO_2 "audio2";
  16.     const TYPE_VIDEO "video";
  17.     const TYPE_LINK "link";
  18.     const TYPE_IMAGE "image";
  19.     const TYPE_TEXT "text";
  20.     
  21.     static public function getTypeOptions()
  22.     {
  23.         return [
  24.             'HTML' => self::TYPE_HTML,
  25.             'Question' => self::TYPE_QUESTION,
  26.             'Audio' => self::TYPE_AUDIO,
  27.             'Audio2' => self::TYPE_AUDIO_2,
  28.             'Video' => self::TYPE_VIDEO,
  29.             'Link' => self::TYPE_LINK,
  30.             'Image' => self::TYPE_IMAGE,
  31.             'Text' => self::TYPE_TEXT
  32.         ];
  33.     }
  34.     
  35.     #[ORM\Id]
  36.     #[ORM\GeneratedValue]
  37.     #[ORM\Column]
  38.     private ?int $id null;
  39.     #[ORM\Column(length255)]
  40.     private ?string $type null;
  41.     #[ORM\Column]
  42.     #[Gedmo\SortablePosition]
  43.     private ?int $position null;
  44.     #[ORM\Column(length255)]
  45.     private ?string $title null;
  46.     #[ORM\Column(typeTypes::TEXT)]
  47.     private ?string $content1 null;
  48.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  49.     private ?string $content2 null;
  50.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  51.     private ?string $content3 null;
  52.     #[ORM\ManyToOne(inversedBy'blocks')]
  53.     #[ORM\JoinColumn(nullablefalse)]
  54.     #[Gedmo\SortableGroup]
  55.     private ?Dialogue $dialogue null;
  56.     #[ORM\OneToMany(mappedBy'block'targetEntityQuestion::class, orphanRemovaltruecascade: ['persist'])]
  57.     private Collection $questions;
  58.     #[ORM\Column(nullabletrue)]
  59.     private ?bool $switch null;
  60.     #[ORM\Column(length255nullabletrue)]
  61.     private ?string $parameter null;
  62.     public function __toString()
  63.     {
  64.         return $this->type " - " $this->title;
  65.     }
  66.     public function __construct()
  67.     {
  68.         $this->questions = new ArrayCollection();
  69.     }
  70.     public function getId(): ?int
  71.     {
  72.         return $this->id;
  73.     }
  74.     public function getType(): ?string
  75.     {
  76.         return $this->type;
  77.     }
  78.     public function setType(string $type): self
  79.     {
  80.         $this->type $type;
  81.         return $this;
  82.     }
  83.    
  84.     public function getPosition(): ?int
  85.     {
  86.         return $this->position;
  87.     }
  88.     public function setPosition(int $position): self
  89.     {
  90.         $this->position $position;
  91.         return $this;
  92.     }
  93.     public function getTitle(): ?string
  94.     {
  95.         return $this->title;
  96.     }
  97.     public function setTitle(string $title): self
  98.     {
  99.         $this->title $title;
  100.         return $this;
  101.     }
  102.     public function getContent1(): string
  103.     {
  104.         return ($this->content1 $this->content1 '');
  105.     }
  106.     public function setContent1(string $content1): self
  107.     {
  108.         $this->content1 $content1;
  109.         return $this;
  110.     }
  111.     public function getContent2(): string
  112.     {
  113.         return ($this->content2 $this->content2 '');
  114.     }
  115.     public function setContent2(?string $content2): self
  116.     {
  117.         $this->content2 $content2;
  118.         return $this;
  119.     }
  120.     public function getContent3(): string
  121.     {
  122.         return ($this->content3 $this->content3 '');
  123.     }
  124.     public function setContent3(?string $content3): self
  125.     {
  126.         $this->content3 $content3;
  127.         return $this;
  128.     }
  129.     public function getDialogue(): ?Dialogue
  130.     {
  131.         return $this->dialogue;
  132.     }
  133.     public function setDialogue(?Dialogue $dialogue): self
  134.     {
  135.         $this->dialogue $dialogue;
  136.         return $this;
  137.     }
  138.     /**
  139.      * @return Collection<int, Question>
  140.      */
  141.     public function getQuestions(): Collection
  142.     {
  143.         return $this->questions;
  144.     }
  145.     public function addQuestion(Question $question): self
  146.     {
  147.         if (!$this->questions->contains($question)) {
  148.             $this->questions->add($question);
  149.             $question->setBlock($this);
  150.         }
  151.         return $this;
  152.     }
  153.     public function removeQuestion(Question $question): self
  154.     {
  155.         if ($this->questions->removeElement($question)) {
  156.             // set the owning side to null (unless already changed)
  157.             if ($question->getBlock() === $this) {
  158.                 $question->setBlock(null);
  159.             }
  160.         }
  161.         return $this;
  162.     }
  163.     public function isSwitch(): ?bool
  164.     {
  165.         return $this->switch;
  166.     }
  167.     public function setSwitch(?bool $switch): self
  168.     {
  169.         $this->switch $switch;
  170.         return $this;
  171.     }
  172.     public function getParameter(): ?string
  173.     {
  174.         return $this->parameter;
  175.     }
  176.     public function setParameter(?string $parameter): self
  177.     {
  178.         $this->parameter $parameter;
  179.         return $this;
  180.     }
  181.     public function clone(): Block
  182.     {
  183.         $new = new Block();
  184.         $new->setContent1($this->content1);
  185.         $new->setContent2($this->content2);
  186.         $new->setContent3($this->content3);
  187.         $new->setPosition(-1);
  188.         $new->setParameter($this->parameter);
  189.         $new->setSwitch($this->switch);
  190.         $new->setTitle($this->title);
  191.         $new->setType($this->type);
  192.         
  193.         return $new;
  194.     }
  195.    
  196. }