src/Entity/Newsletter.php line 42

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiProperty;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use App\Entity\User\User;
  6. use App\Repository\NewsletterRepository;
  7. use App\Controller\NewsletterController;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Timestampable\Traits\TimestampableEntity;
  10. use Ramsey\Uuid\Doctrine\UuidGenerator;
  11. use Symfony\Component\Serializer\Annotation\Groups;
  12. use Symfony\Component\Serializer\Annotation\SerializedName;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. /**
  15.  * @ORM\Entity(repositoryClass=NewsletterRepository::class)
  16.  * @ApiResource(
  17.  *     attributes={
  18.  *          "normalization_context"={"groups"={
  19.  *              "Newsletter:output",
  20.  *              "Newsletter:io"
  21.  *          }},
  22.  *          "denormalization_context"={"groups"={
  23.  *              "Newsletter:input",
  24.  *              "Newsletter:io"
  25.  *          }}
  26.  *      },
  27.  *     collectionOperations={
  28.  *          "get"={
  29.  *              "access_control"="is_granted('ROLE_USER')",
  30.  *          },
  31.  *          "post"={
  32.  *              "validation_groups"={"Default", "Create"}
  33.  *          },
  34.  *     },
  35.  *     itemOperations={
  36.  *     }
  37.  * )
  38.  */
  39. class Newsletter
  40. {
  41.     public const LABEL_NEWSLETTER 'newsletter';
  42.     /**
  43.      * Hook timestampable behavior
  44.      * updates createdAt, updatedAt fields
  45.      */
  46.     use TimestampableEntity;
  47.     /**
  48.      * @ORM\Id
  49.      * @ORM\Column(type="uuid", unique=true)
  50.      * @ORM\GeneratedValue(strategy="CUSTOM")
  51.      * @ORM\CustomIdGenerator(class=UuidGenerator::class)
  52.      * @SerializedName("id")
  53.      * @ApiProperty(identifier=true)
  54.      * @Assert\Uuid()
  55.      * @Groups({
  56.      *     "Newsletter:output",
  57.      * })
  58.      */
  59.     private string $id;
  60.     /**
  61.      * @ORM\Column(type="string", length=180, nullable=true)
  62.      * @SerializedName("email")
  63.      * @Assert\NotBlank()
  64.      * @Assert\Email(normalizer="trim")
  65.      * @Groups({
  66.      *     "Newsletter:io",
  67.      * })
  68.      */
  69.     private ?string $email;
  70.     /**
  71.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="newsletters")
  72.      * @SerializedName("user")
  73.      * @Groups({
  74.      *     "Newsletter:output",
  75.      * })
  76.      */
  77.     private $user;
  78.     /**
  79.      * @ORM\Column(type="string", length=30)
  80.      * @SerializedName("label")
  81.      * @Groups({
  82.      *     "Newsletter:output",
  83.      * })
  84.      */
  85.     private string $label;
  86.     /**
  87.      * @return string
  88.      */
  89.     public function getId(): ?string
  90.     {
  91.         return $this->id;
  92.     }
  93.     public function getUser(): ?User
  94.     {
  95.         return $this->user;
  96.     }
  97.     public function setUser(?User $user): self
  98.     {
  99.         $this->user $user;
  100.         return $this;
  101.     }
  102.     /**
  103.      * @return mixed
  104.      */
  105.     public function getEmail()
  106.     {
  107.         return $this->email;
  108.     }
  109.     /**
  110.      * @param mixed $email
  111.      *
  112.      * @return Newsletter
  113.      */
  114.     public function setEmail($email)
  115.     {
  116.         $this->email $email;
  117.         return $this;
  118.     }
  119.     /**
  120.      * @return mixed
  121.      */
  122.     public function getLabel()
  123.     {
  124.         return $this->label;
  125.     }
  126.     /**
  127.      * @param mixed $label
  128.      *
  129.      * @return Newsletter
  130.      */
  131.     public function setLabel($label)
  132.     {
  133.         $this->label $label;
  134.         return $this;
  135.     }
  136. }