| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?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;
- }
- }
|