<?php
namespace App\Entity;
use App\Repository\BeatAuthorRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
#[ORM\Entity(repositoryClass: BeatAuthorRepository::class)]
#[Vich\Uploadable]
class BeatAuthor
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $firstname = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $lastname = null;
#[ORM\Column(length: 255)]
private ?string $pseudoname = null;
#[ORM\OneToMany(mappedBy: 'author', targetEntity: Beat::class)]
private Collection $beats;
#[ORM\OneToOne(mappedBy: 'author', cascade: ['persist', 'remove'])]
private ?Client $client = null;
#[Vich\UploadableField(mapping: 'beat_author_image', fileNameProperty: 'imageName', size: 'imageSize')]
public ?File $imageFile = null;
#[ORM\Column(nullable: true)]
private ?string $imageName = null;
#[ORM\Column(nullable: true)]
private ?int $imageSize = null;
#[ORM\Column(nullable: true)]
private ?\DateTime $createdAt = null;
#[ORM\Column(nullable: true)]
private ?\DateTime $updatedAt = null;
#[ORM\ManyToMany(targetEntity: Client::class, inversedBy: 'followedAuthors')]
private Collection $followers;
public function __toArray(): array
{
return [
"id"=>$this->getId(),
"firstname"=>$this->getFirstname(),
"lastname"=>$this->getLastname(),
"pseudoname"=>$this->getPseudoname(),
"beats"=>$this->getBeats(),
"client"=>$this->getClient(),
"imageName"=>$this->getImageName(),
"imageSize"=>$this->getImageSize(),
"createdAt"=>$this->getCreatedAt(),
"updatedAt"=>$this->getUpdatedAt(),
"followers"=>$this->getFollowers(),
];
}
public function __toString()
{
return (string)$this->getPseudoname();
}
public function __construct()
{
$this->beats = new ArrayCollection();
$this->followers = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(?string $firstname): static
{
$this->firstname = $firstname;
return $this;
}
public function getLastname(): ?string
{
return $this->lastname;
}
public function setLastname(?string $lastname): static
{
$this->lastname = $lastname;
return $this;
}
public function getPseudoname(): ?string
{
return $this->pseudoname;
}
public function setPseudoname(string $pseudoname): static
{
$this->pseudoname = $pseudoname;
return $this;
}
/**
* @return Collection<int, Beat>
*/
public function getBeats(): Collection
{
return $this->beats;
}
public function addBeat(Beat $beat): static
{
if (!$this->beats->contains($beat)) {
$this->beats->add($beat);
$beat->setAuthor($this);
}
return $this;
}
public function removeBeat(Beat $beat): static
{
if ($this->beats->removeElement($beat)) {
// set the owning side to null (unless already changed)
if ($beat->getAuthor() === $this) {
$beat->setAuthor(null);
}
}
return $this;
}
public function getClient(): ?Client
{
return $this->client;
}
public function setClient(?Client $client): static
{
// unset the owning side of the relation if necessary
if ($client === null && $this->client !== null) {
$this->client->setAuthor(null);
}
// set the owning side of the relation if necessary
if ($client !== null && $client->getAuthor() !== $this) {
$client->setAuthor($this);
}
$this->client = $client;
return $this;
}
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
if ($this->imageFile instanceof UploadedFile) {
$this->updatedAt = new \DateTime('now');
}
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
public function setImageName(?string $imageName): void
{
$this->imageName = $imageName;
}
public function getImageName(): ?string
{
return $this->imageName;
}
public function setImageSize(?int $imageSize): void
{
$this->imageSize = $imageSize;
}
public function getImageSize(): ?int
{
return $this->imageSize;
}
public function getCreatedAt(): ?\DateTime
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTime $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTime
{
return $this->updatedAt;
}
public function setUpdatedAt(?\DateTime $updatedAt): static
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return Collection<int, Client>
*/
public function getFollowers(): Collection
{
return $this->followers;
}
public function addFollower(Client $follower): static
{
if (!$this->followers->contains($follower)) {
$this->followers->add($follower);
}
return $this;
}
public function removeFollower(Client $follower): static
{
$this->followers->removeElement($follower);
return $this;
}
}