src/Entity/Notification.php line 9

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\NotificationRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. #[ORM\Entity(repositoryClassNotificationRepository::class)]
  6. class Notification
  7. {
  8.     #[ORM\Id]
  9.     #[ORM\GeneratedValue]
  10.     #[ORM\Column]
  11.     private ?int $id null;
  12.     #[ORM\Column(length255)]
  13.     private ?string $title null;
  14.     #[ORM\Column(length255)]
  15.     private ?string $message null;
  16.     #[ORM\Column(length255)]
  17.     private ?string $type null;
  18.     #[ORM\Column]
  19.     private ?bool $isRead null;
  20.     #[ORM\Column]
  21.     private ?bool $isArchived null;
  22.     #[ORM\Column]
  23.     private ?bool $isDeleted null;
  24.     #[ORM\Column]
  25.     private ?int $priority null;
  26.     #[ORM\Column]
  27.     private ?\DateTimeImmutable $createdAt null;
  28.     #[ORM\Column(nullabletrue)]
  29.     private ?\DateTimeImmutable $readAt null;
  30.     #[ORM\Column(nullabletrue)]
  31.     private ?\DateTimeImmutable $archivedAt null;
  32.     #[ORM\Column(nullabletrue)]
  33.     private ?\DateTimeImmutable $deletedAt null;
  34.     #[ORM\Column(nullabletrue)]
  35.     private ?\DateTimeImmutable $expiresAt null;
  36.     #[ORM\ManyToOne(inversedBy'notifications')]
  37.     private ?User $user null;
  38.     #[ORM\ManyToOne(inversedBy'notifications')]
  39.     private ?Shop $shop null;
  40.     // Types de notifications
  41.     public const TYPE_ORDER 'order';
  42.     public const TYPE_DELIVERY 'delivery';
  43.     public const TYPE_SHOP_FOLLOW 'shop_follow';
  44.     public const TYPE_PRODUCT_REVIEW 'product_review';
  45.     public const TYPE_SHOP_REVIEW 'shop_review';
  46.     public const TYPE_DROPSHIP_SALE 'dropship_sale';
  47.     public const TYPE_SYSTEM 'system';
  48.     public const TYPE_PROMOTION 'promotion';
  49.     // Priorités
  50.     public const PRIORITY_LOW 1;
  51.     public const PRIORITY_MEDIUM 2;
  52.     public const PRIORITY_HIGH 3;
  53.     public const PRIORITY_URGENT 4;
  54.     public function __construct()
  55.     {
  56.         $this->isRead false;
  57.         $this->isArchived false;
  58.         $this->isDeleted false;
  59.         $this->priority self::PRIORITY_MEDIUM;
  60.         $this->createdAt = new \DateTimeImmutable();
  61.     }
  62.     public function getId(): ?int
  63.     {
  64.         return $this->id;
  65.     }
  66.     public function getTitle(): ?string
  67.     {
  68.         return $this->title;
  69.     }
  70.     public function setTitle(string $title): static
  71.     {
  72.         $this->title $title;
  73.         return $this;
  74.     }
  75.     public function getMessage(): ?string
  76.     {
  77.         return $this->message;
  78.     }
  79.     public function setMessage(string $message): static
  80.     {
  81.         $this->message $message;
  82.         return $this;
  83.     }
  84.     public function getType(): ?string
  85.     {
  86.         return $this->type;
  87.     }
  88.     public function setType(string $type): static
  89.     {
  90.         $this->type $type;
  91.         return $this;
  92.     }
  93.     public function isIsRead(): ?bool
  94.     {
  95.         return $this->isRead;
  96.     }
  97.     public function setIsRead(bool $isRead): static
  98.     {
  99.         $this->isRead $isRead;
  100.         return $this;
  101.     }
  102.     public function isIsArchived(): ?bool
  103.     {
  104.         return $this->isArchived;
  105.     }
  106.     public function setIsArchived(bool $isArchived): static
  107.     {
  108.         $this->isArchived $isArchived;
  109.         return $this;
  110.     }
  111.     public function getPriority(): ?int
  112.     {
  113.         return $this->priority;
  114.     }
  115.     public function setPriority(int $priority): static
  116.     {
  117.         $this->priority $priority;
  118.         return $this;
  119.     }
  120.     public function getCreatedAt(): ?\DateTimeImmutable
  121.     {
  122.         return $this->createdAt;
  123.     }
  124.     public function setCreatedAt(\DateTimeImmutable $createdAt): static
  125.     {
  126.         $this->createdAt $createdAt;
  127.         return $this;
  128.     }
  129.     public function getReadAt(): ?\DateTimeImmutable
  130.     {
  131.         return $this->readAt;
  132.     }
  133.     public function setReadAt(?\DateTimeImmutable $readAt): static
  134.     {
  135.         $this->readAt $readAt;
  136.         return $this;
  137.     }
  138.     public function getExpiresAt(): ?\DateTimeImmutable
  139.     {
  140.         return $this->expiresAt;
  141.     }
  142.     public function setExpiresAt(?\DateTimeImmutable $expiresAt): static
  143.     {
  144.         $this->expiresAt $expiresAt;
  145.         return $this;
  146.     }
  147.     public function getUser(): ?User
  148.     {
  149.         return $this->user;
  150.     }
  151.     public function setUser(?User $user): static
  152.     {
  153.         $this->user $user;
  154.         return $this;
  155.     }
  156.     public function getShop(): ?Shop
  157.     {
  158.         return $this->shop;
  159.     }
  160.     public function setShop(?Shop $shop): static
  161.     {
  162.         $this->shop $shop;
  163.         return $this;
  164.     }
  165.     public function markAsRead(): static
  166.     {
  167.         $this->isRead true;
  168.         $this->readAt = new \DateTimeImmutable();
  169.         return $this;
  170.     }
  171.     public function markAsUnread(): static
  172.     {
  173.         $this->isRead false;
  174.         $this->readAt null;
  175.         return $this;
  176.     }
  177.     public function archive(): static
  178.     {
  179.         $this->isArchived true;
  180.         $this->archivedAt = new \DateTimeImmutable();
  181.         return $this;
  182.     }
  183.     public function unarchive(): static
  184.     {
  185.         $this->isArchived false;
  186.         $this->archivedAt null;
  187.         return $this;
  188.     }
  189.     public function softDelete(): static
  190.     {
  191.         $this->isDeleted true;
  192.         $this->deletedAt = new \DateTimeImmutable();
  193.         return $this;
  194.     }
  195.     public function restore(): static
  196.     {
  197.         $this->isDeleted false;
  198.         $this->deletedAt null;
  199.         return $this;
  200.     }
  201.     public function isIsDeleted(): ?bool
  202.     {
  203.         return $this->isDeleted;
  204.     }
  205.     public function setIsDeleted(bool $isDeleted): static
  206.     {
  207.         $this->isDeleted $isDeleted;
  208.         return $this;
  209.     }
  210.     public function getArchivedAt(): ?\DateTimeImmutable
  211.     {
  212.         return $this->archivedAt;
  213.     }
  214.     public function setArchivedAt(?\DateTimeImmutable $archivedAt): static
  215.     {
  216.         $this->archivedAt $archivedAt;
  217.         return $this;
  218.     }
  219.     public function getDeletedAt(): ?\DateTimeImmutable
  220.     {
  221.         return $this->deletedAt;
  222.     }
  223.     public function setDeletedAt(?\DateTimeImmutable $deletedAt): static
  224.     {
  225.         $this->deletedAt $deletedAt;
  226.         return $this;
  227.     }
  228.     public function isExpired(): bool
  229.     {
  230.         return $this->expiresAt && $this->expiresAt < new \DateTimeImmutable();
  231.     }
  232.     public function getTypeIcon(): string
  233.     {
  234.         return match($this->type) {
  235.             self::TYPE_ORDER => 'lnr-shopping-cart',
  236.             self::TYPE_DELIVERY => 'lnr-truck',
  237.             self::TYPE_SHOP_FOLLOW => 'lnr-heart',
  238.             self::TYPE_PRODUCT_REVIEW => 'lnr-star',
  239.             self::TYPE_SHOP_REVIEW => 'lnr-star',
  240.             self::TYPE_DROPSHIP_SALE => 'lnr-link',
  241.             self::TYPE_SYSTEM => 'lnr-cog',
  242.             self::TYPE_PROMOTION => 'lnr-gift',
  243.             default => 'lnr-bell'
  244.         };
  245.     }
  246.     public function getPriorityClass(): string
  247.     {
  248.         return match($this->priority) {
  249.             self::PRIORITY_LOW => 'text-muted',
  250.             self::PRIORITY_MEDIUM => 'text-primary',
  251.             self::PRIORITY_HIGH => 'text-warning',
  252.             self::PRIORITY_URGENT => 'text-danger',
  253.             default => 'text-primary'
  254.         };
  255.     }
  256. }