<?php
namespace App\Entity;
use App\Repository\SerieBilletRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\OneToMany;
#[ORM\Entity(repositoryClass: SerieBilletRepository::class)]
class SerieBillet
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(type: Types::DATE_MUTABLE, nullable: true)]
private ?\DateTimeInterface $dateAchat = null;
#[ORM\ManyToOne]
#[ORM\OrderBy(["nom" => "ASC"])]
private ?Cour $cour = null;
#[ORM\ManyToOne]
#[ORM\OrderBy(["nom" => "ASC"])]
private ?Category $category = null;
#[ORM\Column(type: "integer", nullable: true)]
private ?int $nbr = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $escalier = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $rang = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $place = null;
#[ORM\ManyToOne(targetEntity: Acheteur::class, cascade: ['persist', 'remove'], inversedBy: 'serieBillets')]
#[ORM\OrderBy(["prenom" => "ASC"])]
private ?Acheteur $acheteur = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $note = null;
#[ORM\Column(nullable: true)]
private ?float $tarif = null;
#[ORM\Column]
private ?bool $papier = null;
#[ORM\Column(nullable: true)]
private ?float $commision = null;
#[ORM\Column(nullable: true)]
private ?bool $active = null;
#[ORM\ManyToOne(inversedBy: 'serieBillets')]
#[ORM\OrderBy(["nom" => "ASC"])]
private ?Tribune $tribune = null;
#[ORM\ManyToOne(targetEntity: Session::class, inversedBy: 'serieBillets')]
private $session;
#[OneToMany(mappedBy: 'serieBillet', targetEntity: Billet::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
private Collection $billets;
public function __construct()
{
$this->dateAchat = new \DateTime('now');
$this->billets = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getDateAchat(): ?\DateTimeInterface
{
return $this->dateAchat;
}
public function setDateAchat(?\DateTimeInterface $dateAchat): self
{
$this->dateAchat = $dateAchat;
return $this;
}
public function getCour(): ?Cour
{
return $this->cour;
}
public function setCour(?Cour $cour): self
{
$this->cour = $cour;
return $this;
}
public function getCategory(): ?Category
{
return $this->category;
}
public function setCategory(?Category $category): self
{
$this->category = $category;
return $this;
}
public function getNbr(): ?int
{
return $this->nbr;
}
public function setNbr(?int $nbr): self
{
$this->nbr = $nbr;
return $this;
}
public function getEscalier(): ?string
{
return $this->escalier;
}
public function setEscalier(?string $escalier): self
{
$this->escalier = $escalier;
return $this;
}
public function getRang(): ?string
{
return $this->rang;
}
public function setRang(?string $rang): self
{
$this->rang = $rang;
return $this;
}
public function getPlace(): ?string
{
return $this->place;
}
public function setPlace(?string $place): self
{
$this->place = $place;
return $this;
}
public function getAcheteur(): ?Acheteur
{
return $this->acheteur;
}
public function setAcheteur(?Acheteur $acheteur): self
{
$this->acheteur = $acheteur;
return $this;
}
public function getNote(): ?string
{
return $this->note;
}
public function setNote(?string $note): self
{
$this->note = $note;
return $this;
}
public function getTarif(): ?float
{
return $this->tarif;
}
public function setTarif(?float $tarif): self
{
$this->tarif = $tarif;
return $this;
}
public function isPapier(): ?bool
{
return $this->papier;
}
public function setPapier(bool $papier): self
{
$this->papier = $papier;
return $this;
}
public function getCommision(): ?float
{
return $this->commision;
}
public function setCommision(?float $commision): self
{
$this->commision = $commision;
return $this;
}
public function isActive(): ?bool
{
return $this->active;
}
public function setActive(?bool $active): self
{
$this->active = $active;
return $this;
}
public function getTribune(): ?Tribune
{
return $this->tribune;
}
public function setTribune(?Tribune $tribune): self
{
$this->tribune = $tribune;
return $this;
}
public function getSession(): ?Session
{
return $this->session;
}
public function setSession(?Session $session): self
{
$this->session = $session;
return $this;
}
public function __toString(): string
{
$acheteurName = $this->acheteur ? $this->acheteur->getNom().' '.$this->acheteur->getPrenom() : '';
$sessionDesc = $this->session ? $this->session->getDescription() : '';
return $acheteurName. ' - '.$sessionDesc;
}
/**
* @return Collection<int, Billet>
*/
public function getBillets(): Collection
{
return $this->billets;
}
public function addBillet(Billet $billet): self
{
if (!$this->billets->contains($billet)) {
$this->billets->add($billet);
$billet->setSerieBillet($this);
}
return $this;
}
public function removeBillet(Billet $billet): self
{
if ($this->billets->removeElement($billet)) {
// set the owning side to null (unless already changed)
if ($billet->getSerieBillet() === $this) {
$billet->setSerieBillet(null);
}
}
return $this;
}
public function getLocalizedDate(): string
{
setlocale(LC_ALL, 'fr_FR.utf8');
return strftime('%A %d %B %Y', ($this->dateAchat) ? $this->dateAchat->getTimestamp() : time());
}
public function getEscalierNumber(): ?int
{
return (is_null($this->getEscalier())) ? null : intval(substr($this->getEscalier(), 2, 3));
}
public function getRangNumber(): ?int
{
return (is_null($this->getRang())) ? null : intval(substr($this->getRang(), 2, 3));
}
public function getPlaceNumber(): ?int
{
return (is_null($this->getPlace())) ? null : intval(substr($this->getPlace(), 2, 3));
}
}