src/Entity/Notification.php line 49

Open in your IDE?
  1. <?php
  2. // @deprecated
  3. declare(strict_types=1);
  4. namespace App\Entity;
  5. use ApiPlatform\Core\Annotation\ApiProperty;
  6. use ApiPlatform\Core\Annotation\ApiResource;
  7. use App\Trait\TimestampableEntity;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. use Ramsey\Uuid\Uuid;
  12. use Ramsey\Uuid\UuidInterface;
  13. /**
  14.  * The most generic type of item.
  15.  *
  16.  * @see https://schema.org/Thing
  17.  *
  18.  * @author Jordi Fernandes Alves <jfadev@gmail.com>
  19.  */
  20. #[ORM\Entity]
  21. #[ApiResource(
  22.     iri'Notification',
  23.     itemOperations: [
  24.         'get' => ['normalization_context' => ['groups' => 'notification:item:get''enable_max_depth' => true]],
  25.         'put' => [
  26.             'normalization_context' => ['groups' => 'notification:item:put''enable_max_depth' => true],
  27.             'denormalization_context' => ['groups' => 'notification:item:put''enable_max_depth' => true],
  28.         ],
  29.         'delete' => [],
  30.     ],
  31.     collectionOperations: [
  32.         'get' => [
  33.             'normalization_context' => [
  34.                 'groups' => ['notification:collection:get''createdAt'],
  35.                 'enable_max_depth' => true,
  36.             ],
  37.         ],
  38.         'post' => [
  39.             'normalization_context' => ['groups' => 'notification:collection:post''enable_max_depth' => true],
  40.             'denormalization_context' => ['groups' => 'notification:collection:post''enable_max_depth' => true],
  41.         ],
  42.     ],
  43. )]
  44. class Notification
  45. {
  46.     use TimestampableEntity;
  47.     
  48.     #[ORM\Id]
  49.     #[ORM\GeneratedValue(strategy'NONE')]
  50.     #[ORM\Column(type'uuid'uniquetrue)]
  51.     #[ApiProperty(iri'https://schema.org/identifier')]
  52.     #[Groups(['notification:item:get''notification:collection:get'])]
  53.     private ?UuidInterface $id null;
  54.     /**
  55.      * @var string|null
  56.      *
  57.      * @see _:message
  58.      */
  59.     #[ORM\Column(type'string'nullablefalse)]
  60.     #[ApiProperty(iri'https://schema.org/message')]
  61.     #[Groups(['notification:item:get''notification:item:put''notification:collection:post'])]
  62.     #[Assert\NotBlank// Asegura que no esté vacío
  63.     private ?string $message null;
  64.     // /**
  65.     //  * @var \DateTimeInterface|null
  66.     //  *
  67.     //  * @see _:createdAt
  68.     //  */
  69.     // #[ORM\Column(type: 'datetime', nullable: false)]
  70.     // #[ApiProperty(iri: 'https://schema.org/createdAt')]
  71.     // #[Groups(['notification:item:get', 'notification:item:put', 'notification:collection:post'])]
  72.     // #[Assert\NotNull] // Asegura que no sea nulo
  73.     // private ?\DateTimeInterface $createdAt = null;
  74.     /**
  75.      * @var bool|null
  76.      *
  77.      * @see _:isRead
  78.      */
  79.     #[ORM\Column(type'boolean'nullablefalse)]
  80.     #[ApiProperty(iri'https://schema.org/isRead')]
  81.     #[Groups(['notification:item:get''notification:item:put''notification:collection:post'])]
  82.     #[Assert\NotNull// Asegura que no sea nulo
  83.     private ?bool $isRead null;
  84.     /**
  85.      * @var User|null
  86.      *
  87.      * @see _:recipient
  88.      */
  89.     #[ORM\ManyToOne(targetEntity'App\Entity\User')]
  90.     #[ORM\JoinColumn(nullablefalse)]
  91.     #[Groups(['notification:item:get''notification:item:put''notification:collection:post'])]
  92.     private ?User $recipient null;
  93.     /** @see _:relatedContract */
  94.     #[ORM\OneToOne(targetEntity'App\Entity\Contract')]
  95.     #[Groups(['notification:item:get''notification:item:put''notification:collection:post'])]
  96.     private ?Contract $relatedContract null;
  97.     public function __construct()
  98.     {
  99.         $this->id Uuid::uuid4();
  100.     }
  101.     public function getId(): ?UuidInterface
  102.     {
  103.         return $this->id;
  104.     }
  105.     public function setMessage(?string $message): void
  106.     {
  107.         $this->message $message;
  108.     }
  109.     public function getMessage(): ?string
  110.     {
  111.         return $this->message;
  112.     }
  113.     // public function setCreatedAt(?\DateTimeInterface $createdAt): void
  114.     // {
  115.     //     $this->createdAt = $createdAt;
  116.     // }
  117.     // public function getCreatedAt(): ?\DateTimeInterface
  118.     // {
  119.     //     return $this->createdAt;
  120.     // }
  121.     public function setIsRead(?bool $isRead): void
  122.     {
  123.         $this->isRead $isRead;
  124.     }
  125.     public function getIsRead(): ?bool
  126.     {
  127.         return $this->isRead;
  128.     }
  129.     public function setRecipient(?User $recipient): void
  130.     {
  131.         $this->recipient $recipient;
  132.     }
  133.     public function getRecipient(): ?User
  134.     {
  135.         return $this->recipient;
  136.     }
  137.     public function setRelatedContract(?Contract $relatedContract): void
  138.     {
  139.         $this->relatedContract $relatedContract;
  140.     }
  141.     public function getRelatedContract(): ?Contract
  142.     {
  143.         return $this->relatedContract;
  144.     }
  145. }