src/Entity/Application/Notification.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Application;
  3. use App\Entity\User;
  4. use App\Repository\Application\NotificationRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use App\Entity\Behaviors\TranslatableTrait;
  9. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  10. use JMS\Serializer\Annotation as Serializer;
  11. /**
  12. * @ORM\Table(name="app_notification")
  13. * @ORM\Entity(repositoryClass=NotificationRepository::class)
  14. * @ORM\EntityListeners({"App\Listener\EntityListener"})
  15. */
  16. class Notification implements TranslatableInterface
  17. {
  18. use TranslatableTrait;
  19. /**
  20. * @ORM\Id
  21. * @ORM\GeneratedValue
  22. * @ORM\Column(type="integer")
  23. */
  24. private $id;
  25. /**
  26. * @ORM\Column(type="datetime")
  27. */
  28. private $sendts;
  29. /**
  30. * @ORM\Column(type="boolean")
  31. */
  32. private $sended = false;
  33. /**
  34. * @ORM\Column(type="datetime")
  35. */
  36. private $createts;
  37. /**
  38. * @Serializer\Groups({"api"})
  39. * @Serializer\SerializedName("type")
  40. * @ORM\Column(type="string")
  41. */
  42. private string $type;
  43. /**
  44. * @ORM\ManyToOne(targetEntity="App\Entity\User")
  45. * @ORM\JoinColumn(nullable=true)
  46. */
  47. private $createUser;
  48. /**
  49. * @ORM\Column(type="datetime", nullable=true)
  50. */
  51. private $editts;
  52. /**
  53. * @ORM\ManyToOne(targetEntity="App\Entity\User")
  54. */
  55. private $editUser;
  56. /**
  57. * @ORM\OneToMany(targetEntity=NotificationSeen::class, mappedBy="notification")
  58. */
  59. private $notificationSeens;
  60. /**
  61. * @Serializer\Groups({"api"})
  62. * @ORM\ManyToOne(targetEntity=Store::class)
  63. * @ORM\JoinColumn(nullable=true)
  64. */
  65. private $store;
  66. /**
  67. * @ORM\Column(type="boolean")
  68. */
  69. private $disabled = false;
  70. /**
  71. * @Serializer\VirtualProperty()
  72. * @Serializer\Groups({"api"})
  73. * @Serializer\Inline()
  74. */
  75. public function getVirtualTranslation()
  76. {
  77. return $this->translate();
  78. }
  79. public function __construct() {
  80. if($this->getSendts() === null){
  81. $this->setSendts(new \DateTime());
  82. }
  83. $this->notificationSeens = new ArrayCollection();
  84. }
  85. public function checkCollections(array $locales): void
  86. {
  87. foreach ( $locales as $locale ) {
  88. $this->addTranslation($this->translate($locale));
  89. }
  90. $this->mergeNewTranslations();
  91. }
  92. public function getId(): ?int
  93. {
  94. return $this->id;
  95. }
  96. public function getSendts(): ?\DateTimeInterface
  97. {
  98. return $this->sendts;
  99. }
  100. public function setSendts(\DateTimeInterface $sendts): self
  101. {
  102. $this->sendts = $sendts;
  103. return $this;
  104. }
  105. public function getCreatets(): ?\DateTimeInterface
  106. {
  107. return $this->createts;
  108. }
  109. public function setCreatets(\DateTimeInterface $createts): self
  110. {
  111. $this->createts = $createts;
  112. return $this;
  113. }
  114. public function getCreateUser(): ?User
  115. {
  116. return $this->createUser;
  117. }
  118. public function setCreateUser(?User $createUser): self
  119. {
  120. $this->createUser = $createUser;
  121. return $this;
  122. }
  123. public function getEditts(): ?\DateTimeInterface
  124. {
  125. return $this->editts;
  126. }
  127. public function setEditts(?\DateTimeInterface $editts): self
  128. {
  129. $this->editts = $editts;
  130. return $this;
  131. }
  132. public function getEditUser(): ?User
  133. {
  134. return $this->editUser;
  135. }
  136. public function setEditUser(?User $editUser): self
  137. {
  138. $this->editUser = $editUser;
  139. return $this;
  140. }
  141. public function __call($method, $arguments)
  142. {
  143. $ret = $this->proxyCurrentLocaleTranslation($method, $arguments);
  144. if(empty($ret)) {
  145. $ret = call_user_func_array( [ $this->translate( \Locale::getDefault() ), $method ], $arguments );
  146. }
  147. return $ret;
  148. }
  149. /**
  150. * @return bool
  151. */
  152. public function isSended(): bool
  153. {
  154. return $this->sended;
  155. }
  156. /**
  157. * @param bool $sended
  158. */
  159. public function setSended(bool $sended): void
  160. {
  161. $this->sended = $sended;
  162. }
  163. /**
  164. * @return Collection|NotificationSeen[]
  165. */
  166. public function getNotificationSeens(): Collection
  167. {
  168. return $this->notificationSeens;
  169. }
  170. public function addNotificationSeen(NotificationSeen $notificationSeen): self
  171. {
  172. if (!$this->notificationSeens->contains($notificationSeen)) {
  173. $this->notificationSeens[] = $notificationSeen;
  174. $notificationSeen->setNotification($this);
  175. }
  176. return $this;
  177. }
  178. public function removeNotificationSeen(NotificationSeen $notificationSeen): self
  179. {
  180. if ($this->notificationSeens->removeElement($notificationSeen)) {
  181. // set the owning side to null (unless already changed)
  182. if ($notificationSeen->getNotification() === $this) {
  183. $notificationSeen->setNotification(null);
  184. }
  185. }
  186. return $this;
  187. }
  188. public function getStore(): ?Store
  189. {
  190. return $this->store;
  191. }
  192. public function setStore(?Store $store): self
  193. {
  194. $this->store = $store;
  195. return $this;
  196. }
  197. public function getType(): string
  198. {
  199. return $this->type;
  200. }
  201. public function setType(string $type): void
  202. {
  203. $this->type = $type;
  204. }
  205. public function isDisabled(): bool
  206. {
  207. return $this->disabled;
  208. }
  209. public function setDisabled(bool $disabled): void
  210. {
  211. $this->disabled = $disabled;
  212. }
  213. }