src/Entity/Activity.php line 25

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ActivityRepository;
  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=ActivityRepository::class)
  16. *
  17. * @ORM\HasLifecycleCallbacks
  18. *
  19. * @Serializer\ExclusionPolicy("ALL")
  20. * @Vich\Uploadable
  21. */
  22. class Activity
  23. {
  24. /**
  25. * @ORM\Id
  26. * @ORM\GeneratedValue
  27. * @ORM\Column(type="integer")
  28. *
  29. * @Expose
  30. * @Groups({"activity"})
  31. */
  32. private $id;
  33. /**
  34. * @ORM\Column(type="string", length=255)
  35. *
  36. * @Expose
  37. * @Groups({"activity"})
  38. */
  39. private $name;
  40. /**
  41. * @ORM\Column(type="string", length=255, nullable=true)
  42. *
  43. * @Expose
  44. * @Groups({"activity"})
  45. */
  46. private $path;
  47. // Vich Uploader
  48. /**
  49. * @Vich\UploadableField(mapping="activity_images", fileNameProperty="path")
  50. * @var File
  51. */
  52. private $imageFile;
  53. /**
  54. * @ORM\Column(type="boolean", nullable=true)
  55. *
  56. * @Expose
  57. * @Groups({"activity"})
  58. */
  59. private $mainActivity;
  60. /**
  61. * @ORM\OneToMany(targetEntity=Devis::class, mappedBy="mainActivity")
  62. * @ORM\JoinColumn(nullable=true)
  63. *
  64. */
  65. private $mainDevis;
  66. /**
  67. * @ORM\OneToMany(targetEntity=Devis::class, mappedBy="secondaryActivity")
  68. * @ORM\JoinColumn(nullable=true)
  69. */
  70. private $secondaryDevis;
  71. /**
  72. * @ORM\Column(type="boolean", nullable=true)
  73. *
  74. * @Expose
  75. * @Groups({"activity"})
  76. */
  77. private $enabled;
  78. /**
  79. * @ORM\Column(type="string", length=255, nullable=true)
  80. */
  81. private $slug;
  82. use DateTrait;
  83. public function __construct()
  84. {
  85. $this->mainDevis = new ArrayCollection();
  86. $this->secondaryDevis = new ArrayCollection();
  87. }
  88. public function getImageFile()
  89. {
  90. return $this->imageFile;
  91. }
  92. /**
  93. * @param File $imageFile
  94. *
  95. * @return $this
  96. */
  97. public function setImageFile(File $imageFile): Activity
  98. {
  99. $this->imageFile = $imageFile;
  100. if (NULL !== $imageFile) {
  101. // It is required that at least one field changes if you are using doctrine
  102. // otherwise the event listeners won't be called and the file is lost
  103. $this->updatedAt = new DateTime();
  104. }
  105. return $this;
  106. }
  107. public function getId(): ?int
  108. {
  109. return $this->id;
  110. }
  111. public function getName(): ?string
  112. {
  113. return $this->name;
  114. }
  115. public function setName(string $name): self
  116. {
  117. $this->name = $name;
  118. return $this;
  119. }
  120. public function getPath(): ?string
  121. {
  122. return $this->path;
  123. }
  124. public function setPath(string $path): self
  125. {
  126. $this->path = $path;
  127. return $this;
  128. }
  129. /**
  130. * @return Collection|Devis[]
  131. */
  132. public function getMainDevis(): Collection
  133. {
  134. return $this->mainDevis;
  135. }
  136. public function addMainDevi(Devis $mainDevi): self
  137. {
  138. if (!$this->mainDevis->contains($mainDevi)) {
  139. $this->mainDevis[] = $mainDevi;
  140. $mainDevi->setMainActivity($this);
  141. }
  142. return $this;
  143. }
  144. public function removeMainDevi(Devis $mainDevi): self
  145. {
  146. if ($this->mainDevis->removeElement($mainDevi)) {
  147. // set the owning side to null (unless already changed)
  148. if ($mainDevi->getMainActivity() === $this) {
  149. $mainDevi->setMainActivity(NULL);
  150. }
  151. }
  152. return $this;
  153. }
  154. public function getMainActivity(): ?bool
  155. {
  156. return $this->mainActivity;
  157. }
  158. public function setMainActivity(?bool $mainActivity): self
  159. {
  160. $this->mainActivity = $mainActivity;
  161. return $this;
  162. }
  163. /**
  164. * @return Collection|Devis[]
  165. */
  166. public function getSecondaryDevis(): Collection
  167. {
  168. return $this->secondaryDevis;
  169. }
  170. public function addSecondaryDevi(Devis $secondaryDevi): self
  171. {
  172. if (!$this->secondaryDevis->contains($secondaryDevi)) {
  173. $this->secondaryDevis[] = $secondaryDevi;
  174. $secondaryDevi->setSecondaryActivity($this);
  175. }
  176. return $this;
  177. }
  178. public function removeSecondaryDevi(Devis $secondaryDevi): self
  179. {
  180. if ($this->secondaryDevis->removeElement($secondaryDevi)) {
  181. // set the owning side to null (unless already changed)
  182. if ($secondaryDevi->getSecondaryActivity() === $this) {
  183. $secondaryDevi->setSecondaryActivity(NULL);
  184. }
  185. }
  186. return $this;
  187. }
  188. public function getEnabled(): ?bool
  189. {
  190. return $this->enabled;
  191. }
  192. public function setEnabled(?bool $enabled): self
  193. {
  194. $this->enabled = $enabled;
  195. return $this;
  196. }
  197. public function getSlug(): ?string
  198. {
  199. return $this->slug;
  200. }
  201. public function setSlug(?string $slug): self
  202. {
  203. $this->slug = $slug;
  204. return $this;
  205. }
  206. }