<?php
namespace App\Entity;
use App\Repository\RealisationRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Ignore;
/**
* @ORM\Entity(repositoryClass=RealisationRepository::class)
*/
class Realisation
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $titre;
/**
* @ORM\Column(type="string", length=255)
*/
private $adresse;
/**
* @ORM\Column(type="string", length=255,nullable=true)
*/
private $image;
/**
* @ORM\Column(type="string", length=10000)
*/
private $contenu;
/**
* @ORM\ManyToOne(targetEntity=CategorieRealisation::class, inversedBy="realisations")
* @Ignore()
* @ORM\JoinColumn(nullable=false)
*/
private $type;
/**
* @ORM\OneToMany(targetEntity=Image::class, mappedBy="realisation", orphanRemoval=true, cascade={"persist"})
*/
private $images;
/**
* @ORM\Column(type="string", length=255, nullable="true")
*/
private $altDesc;
public function __construct()
{
$this->images = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitre(): ?string
{
return $this->titre;
}
public function setTitre(string $titre): self
{
$this->titre = $titre;
return $this;
}
public function getAdresse(): ?string
{
return $this->adresse;
}
public function setAdresse(string $adresse): self
{
$this->adresse = $adresse;
return $this;
}
public function getImage(): ?string
{
return $this->image;
}
public function setImage(?string $image): self
{
$this->image = $image;
return $this;
}
public function getContenu(): ?string
{
return $this->contenu;
}
public function setContenu(string $contenu): self
{
$this->contenu = $contenu;
return $this;
}
public function getType(): ?CategorieRealisation
{
return $this->type;
}
public function setType(?CategorieRealisation $type): self
{
$this->type = $type;
return $this;
}
/**
* @return Collection|Image[]
*/
public function getImages(): Collection
{
return $this->images;
}
public function addImage(Image $image): self
{
if (!$this->images->contains($image)) {
$this->images[] = $image;
$image->setRealisation($this);
}
return $this;
}
public function removeImage(Image $image): self
{
if ($this->images->removeElement($image)) {
// set the owning side to null (unless already changed)
if ($image->getRealisation() === $this) {
$image->setRealisation(null);
}
}
return $this;
}
public function getAltDesc(): ?string
{
return $this->altDesc;
}
public function setAltDesc(?string $altDesc): self
{
$this->altDesc = $altDesc;
return $this;
}
public function getAbsoluteImage() : ?string
{
if(!empty($this->image)){
return sprintf("https://%s/images/upload/%s",$_SERVER['HTTP_HOST'],$this->image);
}
return null;
}
public function getCategorie() : ?int
{
return $this->type?->getId();
}
}