src/Entity/Message.php line 50

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
  8. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  9. use App\Repository\MessageRepository;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Gedmo\Mapping\Annotation as Gedmo;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. use Symfony\Component\Validator\Constraints as Assert;
  14. /**
  15.  * @ORM\Entity(repositoryClass=MessageRepository::class)
  16.  * @ApiResource(
  17.  *     input="App\Dto\MessageInput",
  18.  *     denormalizationContext={
  19.  *          "groups"={"message:write"}
  20.  *     },
  21.  *     normalizationContext={
  22.  *          "groups"={"message:read"}
  23.  *     },
  24.  *     collectionOperations={
  25.  *          "get"={"security"="is_granted('ROLE_ADMIN')"},
  26.  *          "post_contact"={
  27.  *              "security"="is_granted('ROLE_USER')",
  28.  *              "path"="/message_contacts",
  29.  *              "method"="POST",
  30.  *              "controller"="App\Controller\Api\MessageController::postContact"
  31.  *          }
  32.  *     },
  33.  *     itemOperations={
  34.  *          "get"={"security"="is_granted('ROLE_ADMIN')"}
  35.  *     }
  36.  * )
  37.  * @ApiFilter(SearchFilter::class, properties={"user.code":"partial", "status", "subject"})
  38.  * @ApiFilter(DateFilter::class, properties={"createdAt"})
  39.  * @ApiFilter(OrderFilter::class, properties={"id", "user.code", "user.client.company", "subject", "createdAt", "status"})
  40.  * @ApiFilter(PropertyFilter::class, 
  41.  *      arguments={
  42.  *          "parameterName"="fields", 
  43.  *          "overrideDefaultProperties"=true
  44.  *     }
  45.  * )
  46.  */
  47. class Message
  48. {
  49.     const UNREAD 'unread';
  50.     const READ 'read';
  51.     /**
  52.      * @ORM\Id
  53.      * @ORM\GeneratedValue
  54.      * @ORM\Column(type="integer")
  55.      * @Groups({"message:read"})
  56.      */
  57.     private $id;
  58.     /**
  59.      * @ORM\Column(type="string", length=255)
  60.      * @Groups({"message:read", "message:write"})
  61.      */
  62.     private $subject;
  63.     /**
  64.      * @ORM\Column(type="text")
  65.      * @Groups({"message:read", "message:write"})
  66.      */
  67.     private $content;
  68.     /**
  69.      * @ORM\ManyToOne(targetEntity=TvUser::class, inversedBy="messages")
  70.      * @ORM\JoinColumn(nullable=true)
  71.      */
  72.     private $tvUser;
  73.     /**
  74.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="messages")
  75.      * @ORM\JoinColumn(nullable=true)
  76.      * @Assert\NotNull
  77.      * @Groups({"message:read"})
  78.      */
  79.     private $user;
  80.     /**
  81.      * @ORM\Column(type="datetime", nullable=true)
  82.      * @Gedmo\Timestampable(on="create")
  83.      * @Groups({"message:read"})
  84.      */
  85.     private $createdAt;
  86.     /**
  87.      * @ORM\Column(type="string", length=255)
  88.      * @Groups({"message:read"})
  89.      */
  90.     private $status self::UNREAD;
  91.     /**
  92.      * @var null|string
  93.      */
  94.     public $recipients null;
  95.     /**
  96.      * @ORM\Column(type="string", length=255, nullable=true)
  97.      * @Assert\Email
  98.      * @Groups({"message:read", "message:write"})
  99.      */
  100.     private $email;
  101.     public function getId(): ?int
  102.     {
  103.         return $this->id;
  104.     }
  105.     public function getSubject(): ?string
  106.     {
  107.         return $this->subject;
  108.     }
  109.     public function setSubject(string $subject): self
  110.     {
  111.         $this->subject $subject;
  112.         return $this;
  113.     }
  114.     public function getContent(): ?string
  115.     {
  116.         return $this->content;
  117.     }
  118.     public function setContent(string $content): self
  119.     {
  120.         $this->content $content;
  121.         return $this;
  122.     }
  123.     public function getTvUser(): ?TvUser
  124.     {
  125.         return $this->tvUser;
  126.     }
  127.     public function setTvUser(?TvUser $tvUser): self
  128.     {
  129.         $this->tvUser $tvUser;
  130.         return $this;
  131.     }
  132.     public function getUser(): ?User
  133.     {
  134.         return $this->user;
  135.     }
  136.     public function setUser(?User $user): self
  137.     {
  138.         $this->user $user;
  139.         return $this;
  140.     }
  141.     public function getCreatedAt(): ?\DateTimeInterface
  142.     {
  143.         return $this->createdAt;
  144.     }
  145.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  146.     {
  147.         $this->createdAt $createdAt;
  148.         return $this;
  149.     }
  150.     public function getStatus(): ?string
  151.     {
  152.         return $this->status;
  153.     }
  154.     public function setStatus(string $status): self
  155.     {
  156.         $this->status $status;
  157.         return $this;
  158.     }
  159.     /**
  160.      * @return string[]
  161.      */
  162.     public function getStatuses(): array
  163.     {
  164.         return [
  165.           self::UNREAD,
  166.           self::READ,
  167.         ];
  168.     }
  169.     public function getEmail(): ?string
  170.     {
  171.         return $this->email;
  172.     }
  173.     public function setEmail(?string $email): self
  174.     {
  175.         $this->email $email;
  176.         return $this;
  177.     }
  178. }