src/Entity/IdeaBox.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\IdeaBoxRepository;
  4. use App\Traits\DateTrait;
  5. use DateTime;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use JMS\Serializer\Annotation as Serializer;
  10. use JMS\Serializer\Annotation\Expose;
  11. use JMS\Serializer\Annotation\Groups;
  12. use Symfony\Component\HttpFoundation\File\File;
  13. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  14. /**
  15. * @ORM\Entity(repositoryClass=IdeaBoxRepository::class)
  16. *
  17. * @Vich\Uploadable
  18. * @Serializer\ExclusionPolicy("ALL")
  19. */
  20. class IdeaBox
  21. {
  22. use DateTrait;
  23. /**
  24. * @ORM\Id
  25. * @ORM\GeneratedValue
  26. * @ORM\Column(type="integer")
  27. *
  28. * @Expose
  29. * @Groups({
  30. * "idea_box:id",
  31. * "idea_box_stats","idea_box_list", "export_idea_box_datatable"
  32. * })
  33. */
  34. private ?int $id;
  35. /**
  36. * @ORM\OneToMany(targetEntity=IdeaBoxQuestion::class, mappedBy="ideaBox", cascade={"persist", "remove"})
  37. *
  38. * @Expose
  39. * @Groups({
  40. * "idea_box:questions",
  41. * "idea_box_list", "export_idea_box_datatable"
  42. * })
  43. */
  44. private Collection $questions;
  45. /**
  46. * @ORM\Column(type="boolean")
  47. *
  48. * @Expose
  49. * @Groups({
  50. * "idea_box:enabled",
  51. * "idea_box_list"})
  52. */
  53. private bool $enabled;
  54. /**
  55. * @ORM\Column(type="string", length=255, nullable=true)
  56. */
  57. private ?string $image;
  58. // Vich Uploader
  59. /**
  60. * @Vich\UploadableField(mapping="idea_box_image", fileNameProperty="image")
  61. * @var File
  62. */
  63. private $imageFile; // Type non spécifié, veuillez spécifier le type du fichier
  64. /**
  65. * @ORM\Column(type="text", nullable=true)
  66. */
  67. private ?string $textBlock;
  68. /**
  69. * @ORM\OneToMany(targetEntity=IdeaBoxRating::class, mappedBy="ideaBox", cascade={"remove"})
  70. *
  71. * @Expose
  72. * @Groups({
  73. * "idea_box:idea_box_rating",
  74. * "export_idea_box_datatable"
  75. * })
  76. */
  77. private Collection $ideaBoxRatings;
  78. /**
  79. * @ORM\Column(type="string", length=255)
  80. *
  81. * @Expose
  82. * @Groups({
  83. * "idea_box:name",
  84. * "idea_box_list", "idea_box_stats", "export_idea_box_datatable"
  85. * })
  86. */
  87. private ?string $name;
  88. /**
  89. * @ORM\Column(type="boolean")
  90. *
  91. * @Expose
  92. * @Groups({
  93. * "idea_box:enabled_rating",
  94. * "idea_box_list"
  95. * })
  96. */
  97. private bool $enabledRating;
  98. /**
  99. * @ORM\Column(type="boolean")
  100. *
  101. * @Expose
  102. * @Groups({
  103. * "idea_box:enabled_questions",
  104. * "idea_box_list"})
  105. */
  106. private bool $enabledQuestions;
  107. /**
  108. * @ORM\Column(type="integer")
  109. */
  110. private ?int $minRate;
  111. /**
  112. * @ORM\OneToMany(targetEntity=IdeaBoxRecipient::class, mappedBy="ideaBox", cascade={"remove"})
  113. *
  114. * @Expose
  115. * @Groups({
  116. * "idea_box:idea_box_recipients",
  117. * "export_idea_box_datatable"
  118. * })
  119. */
  120. private Collection $ideaBoxRecipients;
  121. public function __construct()
  122. {
  123. $this->questions = new ArrayCollection();
  124. $this->ideaBoxRatings = new ArrayCollection();
  125. $this->ideaBoxRecipients = new ArrayCollection();
  126. }
  127. public function getId(): ?int
  128. {
  129. return $this->id;
  130. }
  131. public function getQuestions()
  132. {
  133. return $this->questions;
  134. }
  135. public function addQuestion(IdeaBoxQuestion $question): IdeaBox
  136. {
  137. if (!$this->questions->contains($question)) {
  138. $this->questions[] = $question;
  139. $question->setIdeaBox($this);
  140. }
  141. return $this;
  142. }
  143. public function removeQuestion(IdeaBoxQuestion $question): IdeaBox
  144. {
  145. if ($this->questions->removeElement($question)) {
  146. // set the owning side to null (unless already changed)
  147. if ($question->getIdeaBox() === $this) {
  148. $question->setIdeaBox(NULL);
  149. }
  150. }
  151. return $this;
  152. }
  153. public function isEnabled(): ?bool
  154. {
  155. return $this->enabled;
  156. }
  157. public function setEnabled(bool $enabled): IdeaBox
  158. {
  159. $this->enabled = $enabled;
  160. return $this;
  161. }
  162. public function getImage(): ?string
  163. {
  164. return $this->image ?? NULL;
  165. }
  166. public function setImage(?string $image): IdeaBox
  167. {
  168. $this->image = $image;
  169. return $this;
  170. }
  171. public function getImageFile()
  172. {
  173. return $this->imageFile;
  174. }
  175. /**
  176. * @param File $imageFile
  177. *
  178. * @return void
  179. */
  180. public function setImageFile(File $imageFile): void
  181. {
  182. $this->imageFile = $imageFile;
  183. if (NULL !== $imageFile) {
  184. // It is required that at least one field changes if you are using doctrine
  185. // otherwise the event listeners won't be called and the file is lost
  186. $this->updatedAt = new DateTime();
  187. }
  188. }
  189. public function getTextBlock(): ?string
  190. {
  191. return $this->textBlock;
  192. }
  193. public function setTextBlock(?string $textBlock): IdeaBox
  194. {
  195. $this->textBlock = $textBlock;
  196. return $this;
  197. }
  198. public function getIdeaBoxRatings()
  199. {
  200. return $this->ideaBoxRatings;
  201. }
  202. public function addIdeaBoxRating(IdeaBoxRating $ideaBoxRating): IdeaBox
  203. {
  204. if (!$this->ideaBoxRatings->contains($ideaBoxRating)) {
  205. $this->ideaBoxRatings[] = $ideaBoxRating;
  206. $ideaBoxRating->setIdeaBox($this);
  207. }
  208. return $this;
  209. }
  210. public function removeIdeaBoxRating(IdeaBoxRating $ideaBoxRating): IdeaBox
  211. {
  212. if ($this->ideaBoxRatings->removeElement($ideaBoxRating)) {
  213. // set the owning side to null (unless already changed)
  214. if ($ideaBoxRating->getIdeaBox() === $this) {
  215. $ideaBoxRating->setIdeaBox(NULL);
  216. }
  217. }
  218. return $this;
  219. }
  220. public function getName(): ?string
  221. {
  222. return $this->name;
  223. }
  224. public function setName(string $name): IdeaBox
  225. {
  226. $this->name = $name;
  227. return $this;
  228. }
  229. public function isEnabledRating(): ?bool
  230. {
  231. return $this->enabledRating;
  232. }
  233. public function setEnabledRating(bool $enabledRating): IdeaBox
  234. {
  235. $this->enabledRating = $enabledRating;
  236. return $this;
  237. }
  238. public function isEnabledQuestions(): ?bool
  239. {
  240. return $this->enabledQuestions;
  241. }
  242. public function setEnabledQuestions(bool $enabledQuestions): IdeaBox
  243. {
  244. $this->enabledQuestions = $enabledQuestions;
  245. return $this;
  246. }
  247. public function getMinRate(): ?int
  248. {
  249. return $this->minRate;
  250. }
  251. public function setMinRate(?int $minRate): IdeaBox
  252. {
  253. $this->minRate = $minRate ?? 0;
  254. return $this;
  255. }
  256. public function getIdeaBoxRecipients()
  257. {
  258. return $this->ideaBoxRecipients;
  259. }
  260. public function addIdeaBoxRecipient(IdeaBoxRecipient $ideaBoxRecipient): IdeaBox
  261. {
  262. if (!$this->ideaBoxRecipients->contains($ideaBoxRecipient)) {
  263. $this->ideaBoxRecipients[] = $ideaBoxRecipient;
  264. $ideaBoxRecipient->setIdeaBox($this);
  265. }
  266. return $this;
  267. }
  268. public function removeIdeaBoxRecipient(IdeaBoxRecipient $ideaBoxRecipient): IdeaBox
  269. {
  270. if ($this->ideaBoxRecipients->removeElement($ideaBoxRecipient)) {
  271. // set the owning side to null (unless already changed)
  272. if ($ideaBoxRecipient->getIdeaBox() === $this) {
  273. $ideaBoxRecipient->setIdeaBox(NULL);
  274. }
  275. }
  276. return $this;
  277. }
  278. /**
  279. * @return int
  280. * @Serializer\VirtualProperty()
  281. * @Serializer\SerializedName("questions_nbr")
  282. *
  283. * @Expose()
  284. * @Groups({"idea_box:questions_nbr", "idea_box_list"})
  285. */
  286. public function getIdeaBoxQuestionNbr(): int
  287. {
  288. return count($this->questions);
  289. }
  290. }