<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\ClubPresentationRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ClubPresentationRepository::class)]
#[ApiResource]
class ClubPresentation
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'clubPresentations')]
#[ORM\JoinColumn(nullable: false, onDelete: "CASCADE")]
private ?club $club = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $link = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $message = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $title = null;
#[ORM\OneToMany(mappedBy: 'clubPresentation', targetEntity: Photo::class, cascade: ["persist"])]
private Collection $photos;
public function __construct()
{
$this->photos = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getImageUrl(): string
{
$mainPhoto = $this->getMainPhoto();
if ($mainPhoto) {
return $mainPhoto->getImageLarge()->getUrl();
}
return 'https://localbeez.ri7.fr/assets/img/image_placeholder.jpg';
}
public function getMainPhoto()
{
foreach ($this->photos as $p) {
if ($p->isMain()) {
return $p;
}
}
if (sizeof($this->photos) > 0) {
return $this->photos[0];
}
return false;
}
public function getSmallImageUrl(): string
{
$mainPhoto = $this->getMainPhoto();
if ($mainPhoto) {
return $mainPhoto->getImageSmall()->getUrl();
}
return 'https://localbeez.ri7.fr/assets/img/image_placeholder.jpg';
}
public function getMediumImageUrl(): string
{
$mainPhoto = $this->getMainPhoto();
if ($mainPhoto) {
return $mainPhoto->getImageMedium()->getUrl();
}
return 'https://localbeez.ri7.fr/assets/img/image_placeholder.jpg';
}
public function getClub(): ?club
{
return $this->club;
}
public function setClub(?club $club): static
{
$this->club = $club;
return $this;
}
public function getLink(): ?string
{
return $this->link;
}
public function setLink(?string $link): static
{
$this->link = $link;
return $this;
}
public function getMessage(): ?string
{
return $this->message;
}
public function setMessage(?string $message): static
{
$this->message = $message;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): static
{
$this->title = $title;
return $this;
}
/**
* @return Collection<int, Photo>
*/
public function getPhotos(): Collection
{
return $this->photos;
}
public function addPhoto(Photo $photo): static
{
if (!$this->photos->contains($photo)) {
$this->photos->add($photo);
$photo->setClubPresentation($this);
}
return $this;
}
public function removePhoto(Photo $photo): static
{
if ($this->photos->removeElement($photo)) {
// set the owning side to null (unless already changed)
if ($photo->getClubPresentation() === $this) {
$photo->setClubPresentation(null);
}
}
return $this;
}
}