NotificationUser.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. declare (strict_types=1);
  3. namespace App\Entity\Core;
  4. use ApiPlatform\Metadata\Post;
  5. use ApiPlatform\Metadata\Get;
  6. use ApiPlatform\Metadata\ApiResource;
  7. use App\Entity\Access\Access;
  8. use App\Repository\Core\NotificationUserRepository;
  9. //use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  10. use Doctrine\ORM\Mapping as ORM;
  11. /**
  12. *
  13. * Les NotificationUser permettent de garder la trace des notifications qui ont été lues par les utilisateurs
  14. */
  15. #[ApiResource(
  16. operations: [
  17. new Get(),
  18. new Post(
  19. securityPostDenormalize: 'object.getAccess().getId() == user.getId()
  20. and object.getNotification().getRecipientAccess().getOrganization().getId() == user.getOrganization().getId()'
  21. )
  22. ]
  23. )]
  24. //#[Auditable]
  25. #[ORM\Entity(repositoryClass: NotificationUserRepository::class)]
  26. class NotificationUser
  27. {
  28. #[ORM\Id]
  29. #[ORM\Column]
  30. #[ORM\GeneratedValue]
  31. private ?int $id = null;
  32. #[ORM\ManyToOne(inversedBy: 'notificationUsers')]
  33. #[ORM\JoinColumn(nullable: false)]
  34. private Notification $notification;
  35. #[ORM\ManyToOne(inversedBy: 'notificationUsers')]
  36. #[ORM\JoinColumn(nullable: false)]
  37. private Access $access;
  38. #[ORM\Column(nullable: false)]
  39. private bool $isRead = true;
  40. public function getId(): ?int
  41. {
  42. return $this->id;
  43. }
  44. public function setNotification(?Notification $notification): self
  45. {
  46. $this->notification = $notification;
  47. return $this;
  48. }
  49. public function getNotification(): Notification
  50. {
  51. return $this->notification;
  52. }
  53. public function setAccess(?Access $access): self
  54. {
  55. $this->access = $access;
  56. return $this;
  57. }
  58. public function getAccess(): Access
  59. {
  60. return $this->access;
  61. }
  62. public function setIsRead(?bool $isRead): self
  63. {
  64. $this->isRead = $isRead;
  65. return $this;
  66. }
  67. public function getIsRead(): ?bool
  68. {
  69. return $this->isRead;
  70. }
  71. }