src/Entity/BeatAuthor.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\BeatAuthorRepository;
  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 Symfony\Component\HttpFoundation\File\File;
  9. use Symfony\Component\HttpFoundation\File\UploadedFile;
  10. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  11. #[ORM\Entity(repositoryClassBeatAuthorRepository::class)]
  12. #[Vich\Uploadable]
  13. class BeatAuthor
  14. {
  15.     #[ORM\Id]
  16.     #[ORM\GeneratedValue]
  17.     #[ORM\Column]
  18.     private ?int $id null;
  19.     #[ORM\Column(length255nullabletrue)]
  20.     private ?string $firstname null;
  21.     #[ORM\Column(length255nullabletrue)]
  22.     private ?string $lastname null;
  23.     #[ORM\Column(length255)]
  24.     private ?string $pseudoname null;
  25.     #[ORM\OneToMany(mappedBy'author'targetEntityBeat::class)]
  26.     private Collection $beats;
  27.     #[ORM\OneToOne(mappedBy'author'cascade: ['persist''remove'])]
  28.     private ?Client $client null;
  29.     #[Vich\UploadableField(mapping'beat_author_image'fileNameProperty'imageName'size'imageSize')]
  30.     public ?File $imageFile null;
  31.     #[ORM\Column(nullabletrue)]
  32.     private ?string $imageName null;
  33.     #[ORM\Column(nullabletrue)]
  34.     private ?int $imageSize null;
  35.     #[ORM\Column(nullabletrue)]
  36.     private ?\DateTime $createdAt null;
  37.     #[ORM\Column(nullabletrue)]
  38.     private ?\DateTime $updatedAt null;
  39.     #[ORM\ManyToMany(targetEntityClient::class, inversedBy'followedAuthors')]
  40.     private Collection $followers;
  41.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  42.     private ?string $bio null;
  43.     public function __toArray(): array
  44.     {
  45.         return [
  46.           "id"=>$this->getId(),
  47.           "firstname"=>$this->getFirstname(),
  48.           "lastname"=>$this->getLastname(),
  49.           "pseudoname"=>$this->getPseudoname(),
  50.           "beats"=>$this->getBeats(),
  51.           "client"=>$this->getClient(),
  52.           "imageName"=>$this->getImageName(),
  53.           "imageSize"=>$this->getImageSize(),
  54.           "createdAt"=>$this->getCreatedAt(),
  55.           "updatedAt"=>$this->getUpdatedAt(),
  56.           "followers"=>$this->getFollowers(),
  57.         ];
  58.     }
  59.     public function __toString()
  60.     {
  61.         return (string)$this->getPseudoname();
  62.     }
  63.     public function __construct()
  64.     {
  65.         $this->beats = new ArrayCollection();
  66.         $this->followers = new ArrayCollection();
  67.     }
  68.     public function getId(): ?int
  69.     {
  70.         return $this->id;
  71.     }
  72.     public function getFirstname(): ?string
  73.     {
  74.         return $this->firstname;
  75.     }
  76.     public function setFirstname(?string $firstname): static
  77.     {
  78.         $this->firstname $firstname;
  79.         return $this;
  80.     }
  81.     public function getLastname(): ?string
  82.     {
  83.         return $this->lastname;
  84.     }
  85.     public function setLastname(?string $lastname): static
  86.     {
  87.         $this->lastname $lastname;
  88.         return $this;
  89.     }
  90.     public function getPseudoname(): ?string
  91.     {
  92.         return $this->pseudoname;
  93.     }
  94.     public function setPseudoname(string $pseudoname): static
  95.     {
  96.         $this->pseudoname $pseudoname;
  97.         return $this;
  98.     }
  99.     /**
  100.      * @return Collection<int, Beat>
  101.      */
  102.     public function getBeats(): Collection
  103.     {
  104.         return $this->beats;
  105.     }
  106.     public function addBeat(Beat $beat): static
  107.     {
  108.         if (!$this->beats->contains($beat)) {
  109.             $this->beats->add($beat);
  110.             $beat->setAuthor($this);
  111.         }
  112.         return $this;
  113.     }
  114.     public function removeBeat(Beat $beat): static
  115.     {
  116.         if ($this->beats->removeElement($beat)) {
  117.             // set the owning side to null (unless already changed)
  118.             if ($beat->getAuthor() === $this) {
  119.                 $beat->setAuthor(null);
  120.             }
  121.         }
  122.         return $this;
  123.     }
  124.     public function getClient(): ?Client
  125.     {
  126.         return $this->client;
  127.     }
  128.     public function setClient(?Client $client): static
  129.     {
  130.         // unset the owning side of the relation if necessary
  131.         if ($client === null && $this->client !== null) {
  132.             $this->client->setAuthor(null);
  133.         }
  134.         // set the owning side of the relation if necessary
  135.         if ($client !== null && $client->getAuthor() !== $this) {
  136.             $client->setAuthor($this);
  137.         }
  138.         $this->client $client;
  139.         return $this;
  140.     }
  141.     public function setImageFile(?File $imageFile null): void
  142.     {
  143.         $this->imageFile $imageFile;
  144.         if ($this->imageFile instanceof UploadedFile) {
  145.             $this->updatedAt = new \DateTime('now');
  146.         }
  147.     }
  148.     public function getImageFile(): ?File
  149.     {
  150.         return $this->imageFile;
  151.     }
  152.     public function setImageName(?string $imageName): void
  153.     {
  154.         $this->imageName $imageName;
  155.     }
  156.     public function getImageName(): ?string
  157.     {
  158.         return $this->imageName;
  159.     }
  160.     public function setImageSize(?int $imageSize): void
  161.     {
  162.         $this->imageSize $imageSize;
  163.     }
  164.     public function getImageSize(): ?int
  165.     {
  166.         return $this->imageSize;
  167.     }
  168.     public function getCreatedAt(): ?\DateTime
  169.     {
  170.         return $this->createdAt;
  171.     }
  172.     public function setCreatedAt(?\DateTime $createdAt): static
  173.     {
  174.         $this->createdAt $createdAt;
  175.         return $this;
  176.     }
  177.     public function getUpdatedAt(): ?\DateTime
  178.     {
  179.         return $this->updatedAt;
  180.     }
  181.     public function setUpdatedAt(?\DateTime $updatedAt): static
  182.     {
  183.         $this->updatedAt $updatedAt;
  184.         return $this;
  185.     }
  186.     /**
  187.      * @return Collection<int, Client>
  188.      */
  189.     public function getFollowers(): Collection
  190.     {
  191.         return $this->followers;
  192.     }
  193.     public function addFollower(Client $follower): static
  194.     {
  195.         if (!$this->followers->contains($follower)) {
  196.             $this->followers->add($follower);
  197.         }
  198.         return $this;
  199.     }
  200.     public function removeFollower(Client $follower): static
  201.     {
  202.         $this->followers->removeElement($follower);
  203.         return $this;
  204.     }
  205.     public function getBio(): ?string
  206.     {
  207.         return $this->bio;
  208.     }
  209.     public function setBio(?string $bio): static
  210.     {
  211.         $this->bio $bio;
  212.         return $this;
  213.     }
  214. }