<?php
namespace App\Entity\Game\WordSearch;
use App\Entity\BaseEntity;
use App\Entity\User;
use App\Repository\Game\WordSearch\GridRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use JMS\Serializer\Annotation as Serializer;
/**
* @ORM\Entity(repositoryClass=GridRepository::class)
* @Serializer\ExclusionPolicy("ALL")
* @UniqueEntity(
* fields={"name"},
* errorPath="name",
* message="Un jeu existe avec le même nom"
* )
*/
class Grid extends BaseEntity
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Serializer\Expose
* @Serializer\Groups({"grid_list"})
*/
private $id;
/**
* @ORM\Column(type="integer")
*/
private $size;
/**
* @ORM\Column(type="string", length=255)
* @Serializer\Expose
* @Serializer\Groups({"grid_list"})
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
* @Serializer\Expose
* @Serializer\Groups({"grid_list"})
*/
private $description;
/**
* @Gedmo\Slug(fields={"name"})
* @ORM\Column(length=191)
*/
private $slug;
/**
* @ORM\Column(type="boolean")
*/
private $isPublished = false;
/**
* @ORM\ManyToMany(targetEntity=Word::class, inversedBy="grids", cascade={"remove"})
*/
private $words;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $point = 0;
/**
* @ORM\Column(type="time", nullable=true)
*/
private $time;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $endAt;
/**
* @ORM\OneToMany(targetEntity=WordSearchParticipation::class, mappedBy="grid", cascade={"remove"})
*/
private $wordSearchParticipations;
/**
* @ORM\Column(type="json", nullable=true)
*/
private $layout = [];
public function __construct()
{
$this->words = new ArrayCollection();
$this->wordSearchParticipations = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getSize(): ?int
{
return $this->size;
}
public function setSize(int $size): self
{
$this->size = $size;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
/**
* Get the value of slug
*/
public function getSlug()
{
return $this->slug;
}
/**
* Set the value of slug
*
* @return self
*/
public function setSlug($slug)
{
$this->slug = $slug;
return $this;
}
public function isIsPublished(): ?bool
{
return $this->isPublished;
}
public function setIsPublished(bool $isPublished): self
{
$this->isPublished = $isPublished;
return $this;
}
/**
* @return Collection<int, Word>
*/
public function getWords(): Collection
{
return $this->words;
}
public function addWord(Word $word): self
{
if (!$this->words->contains($word)) {
$this->words[] = $word;
}
return $this;
}
public function removeWord(Word $word): self
{
$this->words->removeElement($word);
return $this;
}
public function getPoint(): ?int
{
return $this->point;
}
public function setPoint(?int $point): self
{
$this->point = $point;
return $this;
}
public function getTime(): ?\DateTimeInterface
{
return $this->time;
}
public function setTime(?\DateTimeInterface $time): self
{
$this->time = $time;
return $this;
}
public function getEndAt(): ?\DateTimeInterface
{
return $this->endAt;
}
public function setEndAt(?\DateTimeInterface $endAt): self
{
$this->endAt = $endAt;
return $this;
}
/**
* @return Collection<int, WordSearchParticipation>
*/
public function getWordSearchParticipations(): Collection
{
return $this->wordSearchParticipations;
}
public function addWordSearchParticipation(WordSearchParticipation $wordSearchParticipation): self
{
if (!$this->wordSearchParticipations->contains($wordSearchParticipation)) {
$this->wordSearchParticipations[] = $wordSearchParticipation;
$wordSearchParticipation->setGrid($this);
}
return $this;
}
public function removeWordSearchParticipation(WordSearchParticipation $wordSearchParticipation): self
{
if ($this->wordSearchParticipations->removeElement($wordSearchParticipation)) {
// set the owning side to null (unless already changed)
if ($wordSearchParticipation->getGrid() === $this) {
$wordSearchParticipation->setGrid(null);
}
}
return $this;
}
public function getLayout(): ?array
{
return $this->layout;
}
public function setLayout(?array $layout): self
{
$this->layout = $layout;
return $this;
}
}