<?php
namespace App\Entity;
use App\Repository\ActiviteDisponibiliteRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=ActiviteDisponibiliteRepository::class)
*/
class ActiviteDisponibilite
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="activiteDisponibilites")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* @ORM\Column(type="datetime")
*/
private $debut;
/**
* @ORM\Column(type="datetime")
*/
private $fin;
/**
* @ORM\Column(type="datetime")
* @Gedmo\Timestampable(on="create")
*/
private $createdAt;
/**
* @ORM\Column(type="string", length=50)
*/
private $type;
/**
* @ORM\Column(type="string", length=255)
*/
private $ts;
/**
* @ORM\OneToMany(targetEntity=ActiviteDisponibiliteInscription::class, mappedBy="dispo")
*/
private $activiteDisponibiliteInscriptions;
/**
* @ORM\ManyToOne(targetEntity=UserEnseignantLieu::class, inversedBy="activiteDisponibilites")
*/
private $lieu;
/**
* @ORM\ManyToOne(targetEntity=ShopCategorie::class)
* @ORM\JoinColumn(nullable=false)
*/
private $categorie;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $typeVehicule;
public static $typesVehicules = ['MANUEL', 'AUTOMATIQUE'];
/**
* @ORM\Column(type="text", nullable=true)
*/
private $typeTerrain;
public static $typesTerrains = ['ROUTE', 'SIMULATEUR', 'PLATEAU', 'CIRCULATION'];
/**
* @ORM\Column(type="boolean")
*/
private $passerelle = false;
public function __construct()
{
$this->activiteDisponibiliteInscriptions = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getDebut(): ?\DateTimeInterface
{
return $this->debut;
}
public function setDebut(\DateTimeInterface $debut): self
{
$this->debut = $debut;
return $this;
}
public function getFin(): ?\DateTimeInterface
{
return $this->fin;
}
public function setFin(\DateTimeInterface $fin): self
{
$this->fin = $fin;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface {
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self {
$this->createdAt = $createdAt;
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getTs(): ?string
{
return $this->ts;
}
public function setTs(string $ts): self
{
$this->ts = $ts;
return $this;
}
/**
* @return Collection|ActiviteDisponibiliteInscription[]
*/
public function getActiviteDisponibiliteInscriptions(): Collection
{
return $this->activiteDisponibiliteInscriptions;
}
public function addActiviteDisponibiliteInscription(ActiviteDisponibiliteInscription $activiteDisponibiliteInscription): self
{
if (!$this->activiteDisponibiliteInscriptions->contains($activiteDisponibiliteInscription)) {
$this->activiteDisponibiliteInscriptions[] = $activiteDisponibiliteInscription;
$activiteDisponibiliteInscription->setDispo($this);
}
return $this;
}
public function removeActiviteDisponibiliteInscription(ActiviteDisponibiliteInscription $activiteDisponibiliteInscription): self
{
if ($this->activiteDisponibiliteInscriptions->removeElement($activiteDisponibiliteInscription)) {
// set the owning side to null (unless already changed)
if ($activiteDisponibiliteInscription->getDispo() === $this) {
$activiteDisponibiliteInscription->setDispo(null);
}
}
return $this;
}
public function getLieu(): ?UserEnseignantLieu
{
return $this->lieu;
}
public function setLieu(?UserEnseignantLieu $lieu): self
{
$this->lieu = $lieu;
return $this;
}
public function setCategorie(?ShopCategorie $categorie): self
{
$this->categorie = $categorie;
return $this;
}
public function getCategorie(): ?ShopCategorie
{
return $this->categorie;
}
public function getTypeVehicule(): ?string
{
return $this->typeVehicule;
}
public function setTypeVehicule(?string $typeVehicule): self
{
$this->typeVehicule = $typeVehicule;
return $this;
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function testTypeVehicule()
{
if(empty($this->typeVehicule)) return;
if (!in_array($this->typeVehicule, self::$typesVehicules)) {
throw new \UnexpectedValueException('typeVehicule ('.$this->typeVehicule.') expects one of: ' . implode(', ', self::$typesVehicules));
}
}
public function getTypeTerrain(): ?string
{
return $this->typeTerrain;
}
public function setTypeTerrain(?string $typeTerrain): self
{
$this->typeTerrain = $typeTerrain;
return $this;
}
/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function testTypeTerrain()
{
if(empty($this->typeTerrain)) return;
if (!in_array($this->typeTerrain, self::$typesTerrains)) {
throw new \UnexpectedValueException('typeTerrain ('.$this->typeTerrain.') expects one of: ' . implode(', ', self::$typesTerrains));
}
}
public function getPasserelle(): ?bool
{
return $this->passerelle;
}
public function setPasserelle(bool $passerelle): self
{
$this->passerelle = $passerelle;
return $this;
}
public function getHours(): int
{
$start = $this->getDebut()->getTimestamp();
$end = $this->getFin()->getTimestamp();
$interval = $end - $start;
$seconds = $interval;
$hours = $seconds/(60*60);
return $hours;
}
public function getCredits(): int
{
return $this->getHours();
}
}