<?php
namespace App\Entity;
use App\Repository\TestimonyRepository;
use Cofondateur\SocleTechniqueBundle\Annotation\CrudField;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=TestimonyRepository::class)
*/
class Testimony
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="float")
* @Assert\LessThan(
* value=5.0000000001,
* message="La note doit être inférieur à 5"
* )
* @Assert\GreaterThan(
* value=0,
* message="La note doit être supérieur à 0"
* )
*/
private $rating;
/**
* @ORM\Column(type="string", length=255)
* @CrudField(index=true, label="Prénom")
*/
private $firstname;
/**
* @ORM\Column(type="string", length=255)
* @CrudField(label="Nom")
*/
private $name;
/**
* @ORM\Column(type="text")
* @CrudField(label="Témoignage")
*/
private $testimony;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @CrudField(label="Fonction", index=true)
*/
private $role;
/**
* @ORM\Column(type="boolean", nullable=true)
* @CrudField(index=true, label="Publié")
*/
private $published;
/**
* @ORM\ManyToMany(targetEntity=LandingPage::class, mappedBy="testimonies")
*/
private $landingPages;
/**
* @ORM\ManyToOne(targetEntity=Homepage::class, inversedBy="testimonies")
*/
private $homepage;
/**
* @ORM\Column(type="date")
* @CrudField(label="Date d'ajout")
*/
private $date;
/**
* @ORM\Column(type="string", length=255)
* @CrudField(label="Email")
*/
private $email;
public function __construct()
{
$this->landingPages = new ArrayCollection();
$this->date = new DateTime();
$this->published = false;
}
public function __toString(): string
{
if ($this->getRole() != null) {
return $this->getName() . ' ' . $this->getFirstname() . ' ' . $this->getRole();
} else {
return $this->getName() . ' ' . $this->getFirstname();
}
}
public function getId(): ?int
{
return $this->id;
}
public function getRating(): ?float
{
return $this->rating;
}
public function setRating(float $rating): self
{
$this->rating = $rating;
return $this;
}
public function getFirstname(): ?string
{
return $this->firstname;
}
public function setFirstname(string $firstname): self
{
$this->firstname = $firstname;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getTestimony(): ?string
{
return $this->testimony;
}
public function setTestimony(string $testimony): self
{
$this->testimony = $testimony;
return $this;
}
public function getRole(): ?string
{
return $this->role;
}
public function setRole(?string $role): self
{
$this->role = $role;
return $this;
}
public function isPublished(): ?bool
{
return $this->published;
}
public function setPublished(?bool $published): self
{
$this->published = $published;
return $this;
}
/**
* @return Collection<int, LandingPage>
*/
public function getLandingPages(): Collection
{
return $this->landingPages;
}
public function addLandingPage(LandingPage $landingPage): self
{
if (!$this->landingPages->contains($landingPage)) {
$this->landingPages[] = $landingPage;
$landingPage->addTestimony($this);
}
return $this;
}
public function removeLandingPage(LandingPage $landingPage): self
{
if ($this->landingPages->removeElement($landingPage)) {
$landingPage->removeTestimony($this);
}
return $this;
}
public function getHomepage(): ?Homepage
{
return $this->homepage;
}
public function setHomepage(?Homepage $homepage): self
{
$this->homepage = $homepage;
return $this;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function setDate(\DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
}