src/Entity/Game/WordSearch/Word.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Game\WordSearch;
  3. use App\Entity\BaseEntity;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JMS\Serializer\Annotation as Serializer;
  8. /**
  9. * @ORM\Entity(repositoryClass=WordRepository::class)
  10. * @Serializer\ExclusionPolicy("ALL")
  11. */
  12. class Word extends BaseEntity
  13. {
  14. const HORIZONTAL = 0;
  15. const VERTICAL = 1;
  16. const DIAGONAL_LEFT_TO_RIGHT = 2;
  17. const DIAGONAL_RIGHT_TO_LEFT = 3;
  18. /**
  19. * @ORM\Id
  20. * @ORM\GeneratedValue
  21. * @ORM\Column(type="integer")
  22. */
  23. private $id;
  24. /**
  25. * @ORM\Column(type="string", length=255)
  26. * @Serializer\Expose
  27. * @Serializer\Groups({"word_search_list"})
  28. */
  29. private $label;
  30. /**
  31. * @ORM\ManyToMany(targetEntity=Grid::class, mappedBy="words")
  32. */
  33. private $grids;
  34. private $reversed;
  35. private $start;
  36. private $end;
  37. private $orientation;
  38. /**
  39. * @ORM\Column(type="string", length=255, nullable=true)
  40. * @Serializer\Expose
  41. * @Serializer\Groups({"word_search_list"})
  42. */
  43. private $bgColor;
  44. /**
  45. * @ORM\ManyToMany(targetEntity=WordSearchParticipation::class, mappedBy="words")
  46. */
  47. private $wordSearchParticipations;
  48. /**
  49. * @ORM\ManyToMany(targetEntity=WordSearchParticipation::class, mappedBy="wordsFound")
  50. */
  51. private $wordFoundParticipations;
  52. /**
  53. * @ORM\Column(type="integer", nullable=true)
  54. */
  55. private $points;
  56. public function __construct() {
  57. // $this->start = $start;
  58. // $this->end = $end;
  59. // $this->orientation = $orientation;
  60. // $this->label = $label;
  61. // $this->reversed = $reversed;
  62. $this->grids = new ArrayCollection();
  63. $this->wordSearchParticipations = new ArrayCollection();
  64. $this->wordFoundParticipations = new ArrayCollection();
  65. }
  66. public static function init($start, $end, $orientation, $label, $reversed) {
  67. $instance = new self();
  68. $instance->start = $start;
  69. $instance->end = $end;
  70. $instance->orientation = $orientation;
  71. $instance->label = $label;
  72. $instance->reversed = $reversed;
  73. return $instance;
  74. }
  75. public function getId(): ?int
  76. {
  77. return $this->id;
  78. }
  79. public function getOrientation(): ?string
  80. {
  81. return $this->orientation;
  82. }
  83. public function setOrientation(string $_orientation): self
  84. {
  85. $this->orientation = $_orientation;
  86. return $this;
  87. }
  88. public function getLabel(): ?string
  89. {
  90. return $this->label;
  91. }
  92. public function setLabel(string $_label): self
  93. {
  94. $this->label = $_label;
  95. return $this;
  96. }
  97. public function isReversed(): ?bool
  98. {
  99. return $this->reversed;
  100. }
  101. public function setReversed(bool $_reversed): self
  102. {
  103. $this->reversed = $_reversed;
  104. return $this;
  105. }
  106. public function getStart(): ?int
  107. {
  108. return $this->start;
  109. }
  110. public function setStart(int $_start): self
  111. {
  112. $this->start = $_start;
  113. return $this;
  114. }
  115. public function getEnd(): ?int
  116. {
  117. return $this->end;
  118. }
  119. public function setEnd(int $_end): self
  120. {
  121. $this->end = $_end;
  122. return $this;
  123. }
  124. /**
  125. * @return Collection<int, Grid>
  126. */
  127. public function getGrids(): Collection
  128. {
  129. return $this->grids;
  130. }
  131. public function addGrid(Grid $grid): self
  132. {
  133. if (!$this->grids->contains($grid)) {
  134. $this->grids[] = $grid;
  135. $grid->addWord($this);
  136. }
  137. return $this;
  138. }
  139. public function removeGrid(Grid $grid): self
  140. {
  141. if ($this->grids->removeElement($grid)) {
  142. $grid->removeWord($this);
  143. }
  144. return $this;
  145. }
  146. public function getBgColor(): ?string
  147. {
  148. return $this->bgColor;
  149. }
  150. public function setBgColor(?string $bgColor): self
  151. {
  152. $this->bgColor = $bgColor;
  153. return $this;
  154. }
  155. /**
  156. * @return Collection<int, WordSearchParticipation>
  157. */
  158. public function getWordSearchParticipations(): Collection
  159. {
  160. return $this->wordSearchParticipations;
  161. }
  162. public function addWordSearchParticipation(WordSearchParticipation $wordSearchParticipation): self
  163. {
  164. if (!$this->wordSearchParticipations->contains($wordSearchParticipation)) {
  165. $this->wordSearchParticipations[] = $wordSearchParticipation;
  166. $wordSearchParticipation->addWord($this);
  167. }
  168. return $this;
  169. }
  170. public function removeWordSearchParticipation(WordSearchParticipation $wordSearchParticipation): self
  171. {
  172. if ($this->wordSearchParticipations->removeElement($wordSearchParticipation)) {
  173. $wordSearchParticipation->removeWord($this);
  174. }
  175. return $this;
  176. }
  177. /**
  178. * @return Collection<int, WordSearchParticipation>
  179. */
  180. public function getWordFoundParticipations(): Collection
  181. {
  182. return $this->wordFoundParticipations;
  183. }
  184. public function addWordFoundParticipation(WordSearchParticipation $wordFoundParticipation): self
  185. {
  186. if (!$this->wordFoundParticipations->contains($wordFoundParticipation)) {
  187. $this->wordFoundParticipations[] = $wordFoundParticipation;
  188. $wordFoundParticipation->addWordFound($this);
  189. }
  190. return $this;
  191. }
  192. public function removeWordFoundParticipation(WordSearchParticipation $wordFoundParticipation): self
  193. {
  194. if ($this->wordFoundParticipations->removeElement($wordFoundParticipation)) {
  195. $wordFoundParticipation->removeWordFound($this);
  196. }
  197. return $this;
  198. }
  199. public function getPoints(): ?int
  200. {
  201. return $this->points;
  202. }
  203. public function setPoints(?int $points): self
  204. {
  205. $this->points = $points;
  206. return $this;
  207. }
  208. }