<?php
namespace CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use TheCodingMachine\GraphQLite\Annotations\Field;
use TheCodingMachine\GraphQLite\Annotations\Type;
/**
* @ORM\Table(name="box_image")
* @ORM\Entity(repositoryClass="CoreBundle\Repository\BoxImageRepository")
*/
#[Type]
class BoxImage implements \JsonSerializable
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="Secteur", inversedBy="boxImages")
* @ORM\JoinColumn(referencedColumnName="id", nullable=false)
*/
private ?Secteur $secteur;
/**
* @ORM\ManyToMany(targetEntity="Secteur", inversedBy="timetables")
* @ORM\JoinTable(name="box_images_secteurs")
*/
private Collection $secteurs;
/**
* @ORM\Column(type="string", nullable=true)
* @var string
* @todo remove
*/
private $image;
/**
* @ORM\Column(type="string", nullable=true)
* @var string
* @todo remove
*/
private $mimetype;
/**
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime_immutable")
*/
private ?\DateTimeImmutable $updatedOn;
/**
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime_immutable")
*/
private \DateTimeImmutable $createdOn;
/**
* @ORM\OneToMany(targetEntity="BoxText", mappedBy="boxImage", cascade={"persist", "remove"}, orphanRemoval=true)
*/
private $boxTexts;
/**
* @ORM\ManyToOne(targetEntity="CommonFile")
* @ORM\JoinColumn(name="common_file_id", referencedColumnName="id", nullable=false)
*/
private ?CommonFile $file;
public function __construct()
{
$this->boxTexts = new ArrayCollection();
$this->secteurs = new ArrayCollection();
}
#[Field(outputType: "ID")]
public function getId(): ?int
{
return $this->id;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getMimetype(): ?string
{
return $this->mimetype;
}
public function setMimetype(?string $mimetype): self
{
$this->mimetype = $mimetype;
return $this;
}
public function getUpdatedOn(): ?\DateTimeImmutable
{
return $this->updatedOn;
}
public function setUpdatedOn(\DateTimeImmutable $updatedOn): self
{
$this->updatedOn = $updatedOn;
return $this;
}
#[Field]
public function getCreatedOn(): ?\DateTimeImmutable
{
return $this->createdOn;
}
public function setCreatedOn(\DateTimeImmutable $createdOn): self
{
$this->createdOn = $createdOn;
return $this;
}
#[Field]
public function getSecteur(): ?Secteur
{
return $this->secteur;
}
public function setSecteur(?Secteur $secteur): self
{
$this->secteur = $secteur;
return $this;
}
/**
* @return Collection|BoxText[]
*/
#[Field]
public function getBoxTexts(): Collection
{
return $this->boxTexts;
}
public function addBoxText(BoxText $boxText): self
{
if (!$this->boxTexts->contains($boxText)) {
$this->boxTexts[] = $boxText;
$boxText->setBoxImage($this);
}
return $this;
}
public function removeBoxText(BoxText $boxText): self
{
if ($this->boxTexts->removeElement($boxText)) {
// set the owning side to null (unless already changed)
if ($boxText->getBoxImage() === $this) {
$boxText->setBoxImage(null);
}
}
return $this;
}
#[Field]
public function getFile(): ?CommonFile
{
return $this->file;
}
public function setFile(?CommonFile $file): self
{
$this->file = $file;
return $this;
}
public function jsonSerialize()
{
return [
'id' => $this->id,
'secteur' => (null !== $this->secteur) ? [
'id' => $this->secteur->getId(),
'name' => $this->secteur->getName()
] : null,
'image' => $this->image,
'mimetype' => $this->mimetype,
'file' => (null !== $this->file) ? [
'id' => $this->file->getId(),
'filename' => $this->file->getName(),
'bucket' => $this->file->getS3Bucket(),
'key' => $this->file->getS3Key(),
] : null
];
}
/**
* @return Collection<int, Secteur>
*/
public function getSecteurs(): Collection
{
return $this->secteurs;
}
public function addSecteur(Secteur $secteur): self
{
if (!$this->secteurs->contains($secteur)) {
$this->secteurs->add($secteur);
}
return $this;
}
public function removeSecteur(Secteur $secteur): self
{
$this->secteurs->removeElement($secteur);
return $this;
}
}