<?php
namespace App\Entity;
use App\Repository\InstrumentRepository;
use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
#[ORM\Entity(repositoryClass: InstrumentRepository::class)]
#[Vich\Uploadable]
class Instrument
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $name = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $picture = null;
#[Vich\UploadableField(mapping: 'instrument', fileNameProperty: 'picture')]
private ?File $imageFile = null;
#[ORM\ManyToOne(inversedBy: 'instruments')]
#[ORM\JoinColumn(nullable: false)]
private ?Category $category = null;
#[ORM\ManyToOne(inversedBy: 'instruments')]
#[ORM\JoinColumn(nullable: false)]
private ?Company $company = null;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $releaseAt = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $description = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $summary = null;
#[ORM\Column(length: 255)]
private ?string $slug = null;
#[ORM\OneToMany(mappedBy: 'instrument', targetEntity: Sound::class)]
private Collection $sounds;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $updatedAt = null;
public function __construct()
{
$this->sounds = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
/**
* @return File|null
*/
public function getImageFile(): ?File
{
return $this->imageFile;
}
/**
* @param File|null $imageFile
*/
public function setImageFile(?File $imageFile): void
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new DateTimeImmutable();
}
}
public function getPicture(): ?string
{
return $this->picture;
}
public function setPicture(?string $picture): self
{
$this->picture = $picture;
return $this;
}
public function getCategory(): ?Category
{
return $this->category;
}
public function setCategory(?Category $category): self
{
$this->category = $category;
return $this;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
public function getReleaseAt(): ?\DateTimeInterface
{
return $this->releaseAt;
}
public function setReleaseAt(?\DateTimeInterface $releaseAt): self
{
$this->releaseAt = $releaseAt;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getSummary(): ?string
{
return $this->summary;
}
public function setSummary(?string $summary): self
{
$this->summary = $summary;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
/**
* @return Collection<int, Sound>
*/
public function getSounds(): Collection
{
return $this->sounds;
}
public function addSound(Sound $sound): self
{
if (!$this->sounds->contains($sound)) {
$this->sounds->add($sound);
$sound->setInstrument($this);
}
return $this;
}
public function removeSound(Sound $sound): self
{
if ($this->sounds->removeElement($sound)) {
// set the owning side to null (unless already changed)
if ($sound->getInstrument() === $this) {
$sound->setInstrument(null);
}
}
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTimeImmutable $updatedAt): static
{
$this->updatedAt = $updatedAt;
return $this;
}
}