src/Entity/Email.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Timestampable\Traits\TimestampableEntity;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11.  * @ORM\Entity(repositoryClass="App\Repository\EmailRepository")
  12.  * @ORM\HasLifecycleCallbacks()
  13.  */
  14. #[ApiResource(
  15.     normalizationContext: ['groups' => ['email:item''email:list']],
  16.     denormalizationContext: ['allow_extra_attributes' => true'groups' => ['pinpointCampaign:write']],
  17.     attributes: ['security' => "is_granted('ROLE_USER')"],
  18.     collectionOperations: [
  19.         'get' => ['normalization_context' => ['groups' => ['email:list']]],
  20.         'post' => ['security' => "is_granted('ROLE_ADMIN')"],
  21.     ],
  22.     itemOperations: [
  23.         'get' => ['normalization_context' => ['groups' => ['email:item']]],
  24.         'put' => ['security' => "is_granted('ROLE_ADMIN') or object.owner == user"],
  25.     ],
  26. )]
  27. class Email
  28. {
  29.     use TimestampableEntity;
  30.     /**
  31.      * @ORM\Id()
  32.      * @ORM\GeneratedValue()
  33.      * @ORM\Column(type="integer")
  34.      * @Groups({"email:item","email:list","email:write"})
  35.      */
  36.     private $id;
  37.     /**
  38.      * @ORM\Column(type="string", length=255)
  39.      * @Assert\NotBlank()
  40.      * @Assert\Length(max="255")
  41.      * @Groups({"email:item","email:list","email:write"})
  42.      */
  43.     private $label;
  44.     /**
  45.      * @ORM\Column(type="boolean")
  46.      * @Assert\Type(type="boolean")
  47.      * @Groups({"email:item","email:list","email:write"})
  48.      */
  49.     private $isPinpointTemplate;
  50.     /**
  51.      * @ORM\Column(type="string", length=255)
  52.      * @Assert\NotBlank()
  53.      * @Assert\Length(max="255")
  54.      * @Groups({"email:item","email:list","email:write"})
  55.      */
  56.     private $subject;
  57.     /**
  58.      * @ORM\Column(type="text")
  59.      * @Assert\NotBlank()
  60.      * @Groups({"email:item","email:write"})
  61.      */
  62.     private $body;
  63.     /**
  64.      * @var Collection
  65.      *
  66.      * @ORM\OneToMany(targetEntity="App\Entity\PinpointCampaign", mappedBy="email", cascade={"persist"})
  67.      */
  68.     private $pinpointCampaigns;
  69.     /**
  70.      * Email constructor.
  71.      */
  72.     public function __construct()
  73.     {
  74.         $this->isPinpointTemplate false;
  75.         $this->pinpointCampaigns = new ArrayCollection();
  76.     }
  77.     public function __toString()
  78.     {
  79.         return $this->label;
  80.     }
  81.     public function getId(): ?int
  82.     {
  83.         return $this->id;
  84.     }
  85.     public function getLabel(): ?string
  86.     {
  87.         return $this->label;
  88.     }
  89.     public function setLabel(string $label): self
  90.     {
  91.         $this->label $label;
  92.         return $this;
  93.     }
  94.     public function getIsPinpointTemplate(): bool
  95.     {
  96.         return $this->isPinpointTemplate;
  97.     }
  98.     public function setIsPinpointTemplate(bool $isPinpointTemplate): self
  99.     {
  100.         $this->isPinpointTemplate $isPinpointTemplate;
  101.         return $this;
  102.     }
  103.     public function getSubject(): ?string
  104.     {
  105.         return $this->subject;
  106.     }
  107.     public function setSubject(string $subject): self
  108.     {
  109.         $this->subject $subject;
  110.         return $this;
  111.     }
  112.     public function getBody(): ?string
  113.     {
  114.         return $this->body;
  115.     }
  116.     public function setBody(string $body): self
  117.     {
  118.         $this->body $body;
  119.         return $this;
  120.     }
  121.     /**
  122.      * @return Collection|PinpointCampaign[]
  123.      */
  124.     public function getPinpointCampaigns(): Collection
  125.     {
  126.         return $this->pinpointCampaigns;
  127.     }
  128.     public function addPinpointCampaign(PinpointCampaign $pinpointCampaign): self
  129.     {
  130.         if (!$this->pinpointCampaigns->contains($pinpointCampaign)) {
  131.             $this->pinpointCampaigns[] = $pinpointCampaign;
  132.             $pinpointCampaign->setEmail($this);
  133.         }
  134.         return $this;
  135.     }
  136.     public function removePinpointCampaign(PinpointCampaign $pinpointCampaign): self
  137.     {
  138.         if ($this->pinpointCampaigns->contains($pinpointCampaign)) {
  139.             $this->pinpointCampaigns->removeElement($pinpointCampaign);
  140.             // set the owning side to null (unless already changed)
  141.             if ($pinpointCampaign->getEmail() === $this) {
  142.                 $pinpointCampaign->setEmail(null);
  143.             }
  144.         }
  145.         return $this;
  146.     }
  147. }