| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- <?php
- declare(strict_types=1);
- namespace App\Entity\Core;
- use ApiPlatform\Metadata\ApiResource;
- use App\Entity\Access\Access;
- use App\Entity\Organization\Organization;
- // use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
- use App\Enum\Core\NotificationTypeEnum;
- use Doctrine\Common\Collections\ArrayCollection;
- use Doctrine\Common\Collections\Collection;
- use Doctrine\ORM\Mapping as ORM;
- use JetBrains\PhpStorm\Pure;
- use Symfony\Component\Serializer\Annotation\Context;
- use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
- /**
- * @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(operations: [])]
- // #[Auditable]
- #[ORM\Entity]
- #[ORM\Table(name: 'Information')]
- #[ORM\InheritanceType('SINGLE_TABLE')]
- #[ORM\DiscriminatorColumn(name: 'discr', type: 'string')]
- #[ORM\DiscriminatorMap([
- 'notification' => 'Notification',
- 'tips' => 'Tips',
- ])]
- class AbstractInformation
- {
- #[ORM\Id]
- #[ORM\Column]
- #[ORM\GeneratedValue]
- protected ?int $id = null;
- #[ORM\ManyToOne(inversedBy: 'notifications')]
- #[ORM\JoinColumn(nullable: false)]
- protected ?Access $recipientAccess;
- #[ORM\ManyToOne(inversedBy: 'notifications')]
- #[ORM\JoinColumn(nullable: false)]
- protected ?Organization $recipientOrganization;
- #[ORM\Column(length: 40, nullable: true)]
- protected ?string $name = null;
- #[ORM\Column(type: 'datetime', nullable: true)]
- protected ?\DateTimeInterface $createDate;
- #[ORM\Column(type: 'datetime', nullable: true)]
- protected ?\DateTimeInterface $updateDate;
- #[ORM\Column(type: 'json', length: 4294967295, nullable: true)]
- protected mixed $message = [];
- #[ORM\Column(length: 50, nullable: true, enumType: NotificationTypeEnum::class)]
- protected ?NotificationTypeEnum $type = null;
- #[ORM\Column(length: 255, nullable: true)]
- protected ?string $link = null;
- #[ORM\Column(type: 'date', nullable: true)]
- #[Context(normalizationContext: [DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
- protected ?\DateTimeInterface $availabilityDate = null;
- #[ORM\OneToMany(mappedBy: 'notification', targetEntity: NotificationUser::class, cascade: ['persist'], orphanRemoval: true)]
- protected 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 getRecipientOrganization(): ?Organization
- {
- return $this->recipientOrganization;
- }
- public function setRecipientOrganization(?Organization $recipientOrganization): self
- {
- $this->recipientOrganization = $recipientOrganization;
- return $this;
- }
- public function getCreateDate(): ?\DateTimeInterface
- {
- return $this->createDate;
- }
- public function setCreateDate(?\DateTimeInterface $createDate): self
- {
- $this->createDate = $createDate;
- return $this;
- }
- public function getUpdateDate(): ?\DateTimeInterface
- {
- return $this->updateDate;
- }
- public function setUpdateDate(?\DateTimeInterface $updateDate): self
- {
- $this->updateDate = $updateDate;
- return $this;
- }
- public function setMessage(mixed $message): self
- {
- $this->message = $message;
- return $this;
- }
- public function getMessage(): mixed
- {
- if (!is_array($this->message)) {
- return ['about' => $this->message];
- }
- return $this->message;
- }
- public function setType(?NotificationTypeEnum $type): self
- {
- $this->type = $type;
- return $this;
- }
- public function getType(): ?NotificationTypeEnum
- {
- return $this->type;
- }
- public function setLink(?string $link): self
- {
- $this->link = $link;
- return $this;
- }
- public function getLink(): ?string
- {
- return $this->link;
- }
- public function getAvailabilityDate(): ?\DateTimeInterface
- {
- return $this->availabilityDate;
- }
- 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;
- }
- }
|