|
|
@@ -0,0 +1,171 @@
|
|
|
+<?php
|
|
|
+declare(strict_types=1);
|
|
|
+
|
|
|
+
|
|
|
+namespace App\Entity\Core;
|
|
|
+
|
|
|
+use ApiPlatform\Core\Annotation\ApiResource;
|
|
|
+use App\Entity\Access\Access;
|
|
|
+use App\Repository\Core\NotificationRepository;
|
|
|
+use Doctrine\Common\Collections\ArrayCollection;
|
|
|
+use Doctrine\Common\Collections\Collection;
|
|
|
+use Doctrine\ORM\Mapping as ORM;
|
|
|
+use JetBrains\PhpStorm\Pure;
|
|
|
+use Symfony\Component\Validator\Constraints as Assert;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @todo : A la suite de la migration, il faut supprimer le nom de la table pour avoir une table Notification, et supprimer l'attribut discr.
|
|
|
+ *
|
|
|
+ * Classe Notification. qui permet de gérer les notifications aux utilisateurs.
|
|
|
+ */
|
|
|
+#[ApiResource(
|
|
|
+ collectionOperations:[
|
|
|
+ 'get' => [
|
|
|
+ 'pagination_client_items_per_page' => true,
|
|
|
+ 'pagination_maximum_items_per_page' => 20,
|
|
|
+ 'order' => [
|
|
|
+ 'id' => 'DESC'
|
|
|
+ ]
|
|
|
+ ]
|
|
|
+ ],
|
|
|
+ itemOperations: [
|
|
|
+ 'get'
|
|
|
+ ]
|
|
|
+)]
|
|
|
+#[ORM\Entity(repositoryClass:NotificationRepository::class)]
|
|
|
+#[ORM\Table(name: 'Information')]
|
|
|
+class Notification
|
|
|
+{
|
|
|
+ #[ORM\Id]
|
|
|
+ #[ORM\Column]
|
|
|
+ #[ORM\GeneratedValue]
|
|
|
+ private ?int $id = null;
|
|
|
+
|
|
|
+ #[ORM\Column(length: 255, nullable: false)]
|
|
|
+ private string $discr = 'notification';
|
|
|
+
|
|
|
+ #[ORM\ManyToOne(inversedBy: 'notifications')]
|
|
|
+ #[ORM\JoinColumn(nullable: false)]
|
|
|
+ private ?Access $recipientAccess;
|
|
|
+
|
|
|
+ #[ORM\Column(length: 40, nullable: true)]
|
|
|
+ private ?string $name = null;
|
|
|
+
|
|
|
+ #[ORM\Column(type: 'json', length: 4294967295, nullable: true)]
|
|
|
+ private ?array $message = [];
|
|
|
+
|
|
|
+ #[ORM\Column(nullable: true)]
|
|
|
+ #[Assert\Choice(callback: ['\App\Enum\Core\NotificationTypeEnum', 'toArray'], message: 'invalid-type')]
|
|
|
+ private ?string $type = null;
|
|
|
+
|
|
|
+ #[ORM\Column(length: 255, nullable: true)]
|
|
|
+ private ?string $link = null;
|
|
|
+
|
|
|
+ #[ORM\Column(type: 'date', nullable: true)]
|
|
|
+ private ?\DateTimeInterface $availabilityDate = null;
|
|
|
+
|
|
|
+ #[ORM\OneToMany(mappedBy: 'notification', targetEntity: NotificationUser::class, cascade: ['persist'], orphanRemoval: true)]
|
|
|
+ private Collection $notificationUsers;
|
|
|
+
|
|
|
+ #[Pure] public function __construct()
|
|
|
+ {
|
|
|
+ $this->notificationUsers = new ArrayCollection();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getId(): ?int
|
|
|
+ {
|
|
|
+ return $this->id;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setName(?string $name): self
|
|
|
+ {
|
|
|
+ $this->name = $name;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getName(): ?string
|
|
|
+ {
|
|
|
+ return $this->name;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setRecipientAccess(?Access $recipientAccess): self
|
|
|
+ {
|
|
|
+ $this->recipientAccess = $recipientAccess;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getRecipientAccess(): ?Access
|
|
|
+ {
|
|
|
+ return $this->recipientAccess;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setMessage(?array $message): self
|
|
|
+ {
|
|
|
+ $this->message = $message;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getMessage(): ?array
|
|
|
+ {
|
|
|
+ return $this->message;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setType(?string $type): self
|
|
|
+ {
|
|
|
+ $this->type = $type;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getType(): ?string
|
|
|
+ {
|
|
|
+ return $this->type;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setLink(?string $link): self
|
|
|
+ {
|
|
|
+ $this->link = $link;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getLink(): ?string
|
|
|
+ {
|
|
|
+ return $this->link;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getAvailabilityDate(): ?string {
|
|
|
+ return $this->availabilityDate?->format('Y-m-d');
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setAvailabilityDate(?\DateTime $availabilityDate = null): self {
|
|
|
+ if($availabilityDate == null) $availabilityDate = new \DateTime();
|
|
|
+ $this->availabilityDate = $availabilityDate;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getNotificationUsers(): Collection
|
|
|
+ {
|
|
|
+ return $this->notificationUsers;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function addNotificationUser(NotificationUser $notificationUsers): self
|
|
|
+ {
|
|
|
+ if (!$this->notificationUsers->contains($notificationUsers)) {
|
|
|
+ $this->notificationUsers[] = $notificationUsers;
|
|
|
+ $notificationUsers->setNotification($this);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function removeNotificationUser(NotificationUser $notificationUsers): self
|
|
|
+ {
|
|
|
+ if ($this->notificationUsers->removeElement($notificationUsers)) {
|
|
|
+ // set the owning side to null (unless already changed)
|
|
|
+ if ($notificationUsers->getNotification() === $this) {
|
|
|
+ $notificationUsers->setNotification(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+}
|