This commit is contained in:
2024-07-03 12:32:09 +02:00
parent 096d35d5cf
commit a2f2520617
16 changed files with 270 additions and 11 deletions

View File

@@ -6,8 +6,11 @@ use App\Repository\ConferenceRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\String\Slugger\SluggerInterface;
#[ORM\Entity(repositoryClass: ConferenceRepository::class)]
#[UniqueEntity('slug')]
class Conference
{
#[ORM\Id]
@@ -30,6 +33,9 @@ class Conference
#[ORM\OneToMany(targetEntity: Comment::class, mappedBy: 'conference', orphanRemoval: true)]
private Collection $comments;
#[ORM\Column(length: 255, unique: true)]
private ?string $slug = null;
public function __construct()
{
$this->comments = new ArrayCollection();
@@ -44,6 +50,13 @@ class Conference
return $this->id;
}
public function computeSlug(SluggerInterface $slugger)
{
if (!$this->slug || '-' === $this->slug) {
$this->slug = (string) $slugger->slug((string) $this)->lower();
}
}
public function getCity(): ?string
{
return $this->city;
@@ -109,4 +122,16 @@ class Conference
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): static
{
$this->slug = $slug;
return $this;
}
}