src/CoreBundle/Entity/BoxImage.php line 195

Open in your IDE?
  1. <?php
  2. namespace CoreBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. use TheCodingMachine\GraphQLite\Annotations\Field;
  8. use TheCodingMachine\GraphQLite\Annotations\Type;
  9. /**
  10.  * @ORM\Table(name="box_image")
  11.  * @ORM\Entity(repositoryClass="CoreBundle\Repository\BoxImageRepository")
  12.  */
  13. #[Type]
  14. class BoxImage implements \JsonSerializable
  15. {
  16.     /**
  17.      * @var int
  18.      *
  19.      * @ORM\Column(name="id", type="integer")
  20.      * @ORM\Id
  21.      * @ORM\GeneratedValue(strategy="IDENTITY")
  22.      */
  23.     private $id;
  24.     /**
  25.      * @ORM\ManyToOne(targetEntity="Secteur", inversedBy="boxImages")
  26.      * @ORM\JoinColumn(referencedColumnName="id", nullable=false)
  27.      */
  28.     private ?Secteur $secteur;
  29.     /**
  30.      * @ORM\ManyToMany(targetEntity="Secteur", inversedBy="timetables")
  31.      * @ORM\JoinTable(name="box_images_secteurs")
  32.      */
  33.     private Collection $secteurs;
  34.     /**
  35.      * @ORM\Column(type="string", nullable=true)
  36.      * @var string
  37.      * @todo remove
  38.      */
  39.     private $image;
  40.     /**
  41.      * @ORM\Column(type="string", nullable=true)
  42.      * @var string
  43.      * @todo remove
  44.      */
  45.     private $mimetype;
  46.     /**
  47.      * @Gedmo\Timestampable(on="update")
  48.      * @ORM\Column(type="datetime_immutable")
  49.      */
  50.     private ?\DateTimeImmutable $updatedOn;
  51.     /**
  52.      * @Gedmo\Timestampable(on="create")
  53.      * @ORM\Column(type="datetime_immutable")
  54.      */
  55.     private \DateTimeImmutable $createdOn;
  56.     /**
  57.      * @ORM\OneToMany(targetEntity="BoxText", mappedBy="boxImage", cascade={"persist", "remove"}, orphanRemoval=true)
  58.      */
  59.     private $boxTexts;
  60.     /**
  61.      * @ORM\ManyToOne(targetEntity="CommonFile")
  62.      * @ORM\JoinColumn(name="common_file_id", referencedColumnName="id", nullable=false)
  63.      */
  64.     private ?CommonFile $file;
  65.     public function __construct()
  66.     {
  67.         $this->boxTexts = new ArrayCollection();
  68.         $this->secteurs = new ArrayCollection();
  69.     }
  70.     #[Field(outputType"ID")]
  71.     public function getId(): ?int
  72.     {
  73.         return $this->id;
  74.     }
  75.     public function getImage(): ?string
  76.     {
  77.         return $this->image;
  78.     }
  79.     public function setImage(?string $image): self
  80.     {
  81.         $this->image $image;
  82.         return $this;
  83.     }
  84.     public function getMimetype(): ?string
  85.     {
  86.         return $this->mimetype;
  87.     }
  88.     public function setMimetype(?string $mimetype): self
  89.     {
  90.         $this->mimetype $mimetype;
  91.         return $this;
  92.     }
  93.     public function getUpdatedOn(): ?\DateTimeImmutable
  94.     {
  95.         return $this->updatedOn;
  96.     }
  97.     public function setUpdatedOn(\DateTimeImmutable $updatedOn): self
  98.     {
  99.         $this->updatedOn $updatedOn;
  100.         return $this;
  101.     }
  102.     #[Field]
  103.     public function getCreatedOn(): ?\DateTimeImmutable
  104.     {
  105.         return $this->createdOn;
  106.     }
  107.     public function setCreatedOn(\DateTimeImmutable $createdOn): self
  108.     {
  109.         $this->createdOn $createdOn;
  110.         return $this;
  111.     }
  112.     #[Field]
  113.     public function getSecteur(): ?Secteur
  114.     {
  115.         return $this->secteur;
  116.     }
  117.     public function setSecteur(?Secteur $secteur): self
  118.     {
  119.         $this->secteur $secteur;
  120.         return $this;
  121.     }
  122.     /**
  123.      * @return Collection|BoxText[]
  124.      */
  125.     #[Field]
  126.     public function getBoxTexts(): Collection
  127.     {
  128.         return $this->boxTexts;
  129.     }
  130.     public function addBoxText(BoxText $boxText): self
  131.     {
  132.         if (!$this->boxTexts->contains($boxText)) {
  133.             $this->boxTexts[] = $boxText;
  134.             $boxText->setBoxImage($this);
  135.         }
  136.         return $this;
  137.     }
  138.     public function removeBoxText(BoxText $boxText): self
  139.     {
  140.         if ($this->boxTexts->removeElement($boxText)) {
  141.             // set the owning side to null (unless already changed)
  142.             if ($boxText->getBoxImage() === $this) {
  143.                 $boxText->setBoxImage(null);
  144.             }
  145.         }
  146.         return $this;
  147.     }
  148.     #[Field]
  149.     public function getFile(): ?CommonFile
  150.     {
  151.         return $this->file;
  152.     }
  153.     public function setFile(?CommonFile $file): self
  154.     {
  155.         $this->file $file;
  156.         return $this;
  157.     }
  158.     public function jsonSerialize()
  159.     {
  160.         return [
  161.             'id' => $this->id,
  162.             'secteur' => (null !== $this->secteur) ? [
  163.                 'id' => $this->secteur->getId(),
  164.                 'name' => $this->secteur->getName()
  165.             ] : null,
  166.             'image' => $this->image,
  167.             'mimetype' => $this->mimetype,
  168.             'file' => (null !== $this->file) ? [
  169.                 'id' => $this->file->getId(),
  170.                 'filename' => $this->file->getName(),
  171.                 'bucket' => $this->file->getS3Bucket(),
  172.                 'key' => $this->file->getS3Key(),
  173.             ] : null
  174.         ];
  175.     }
  176.     /**
  177.      * @return Collection<int, Secteur>
  178.      */
  179.     public function getSecteurs(): Collection
  180.     {
  181.         return $this->secteurs;
  182.     }
  183.     public function addSecteur(Secteur $secteur): self
  184.     {
  185.         if (!$this->secteurs->contains($secteur)) {
  186.             $this->secteurs->add($secteur);
  187.         }
  188.         return $this;
  189.     }
  190.     public function removeSecteur(Secteur $secteur): self
  191.     {
  192.         $this->secteurs->removeElement($secteur);
  193.         return $this;
  194.     }
  195. }