src/Entity/ChatLog.php line 43

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\Repository\ChatLogRepository;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11.  * @ORM\Entity(repositoryClass=ChatLogRepository::class)
  12.  * @ApiResource(
  13.  *      normalizationContext={
  14.  *          "groups"={"chat_log:read"}
  15.  *      },
  16.  *      denormalizationContext={
  17.  *          "groups"={"chat_log:write"}
  18.  *      },
  19.  *      itemOperations={
  20.  *          "get"={
  21.  *              "security"="is_granted('ROLE_USER')"
  22.  *          }, 
  23.  *          "patch"={
  24.  *              "security"="is_granted('ROLE_USER')"
  25.  *          }, 
  26.  *          "delete"={
  27.  *              "security"="is_granted('ROLE_USER')"
  28.  *          }
  29.  *      },
  30.  *      collectionOperations={
  31.  *          "get"={
  32.  *              "security"="is_granted('ROLE_USER')"
  33.  *          }, 
  34.  *          "post"={
  35.  *              "security"="is_granted('ROLE_USER')"
  36.  *          }
  37.  *      }
  38.  * )
  39.  */
  40. class ChatLog
  41. {
  42.     const TYPE_READ "read";
  43.     const TYPES = [
  44.         self::TYPE_READ => self::TYPE_READ,
  45.     ];
  46.     
  47.     /**
  48.      * @ORM\Id
  49.      * @ORM\GeneratedValue
  50.      * @ORM\Column(type="integer")
  51.      * @ApiProperty(identifier=true)
  52.      * @Groups({"chat_log:read", "chat_log:read:id"})
  53.      */
  54.     private ?int $id null;
  55.     /**
  56.      * @ORM\Column(type="string", length=255, nullable=true, options={"default": "read"})
  57.      * @Groups({"chat_log:read", "chat_log:write", "chat_log:read:type"})          
  58.      * @Assert\NotBlank
  59.      */
  60.     private ?string $type self::TYPE_READ;
  61.     /**
  62.      * @ORM\Column(type="integer", nullable=true, options={"default": 0})
  63.      * @Groups({"chat_log:read", "chat_log:write", "chat_log:read:value"})             
  64.      */
  65.     private ?int $value 0;
  66.     /**
  67.      * @ORM\ManyToOne(targetEntity=User::class)
  68.      * @Assert\NotBlank
  69.      * @Groups({"chat_log:read", "chat_log:write", "chat_log:read:user"})
  70.      */
  71.     private ?User $user;
  72.     /**
  73.      * @ORM\ManyToOne(targetEntity=Chat::class)
  74.      * @Assert\NotBlank
  75.      * @Groups({"chat_log:read", "chat_log:write", "chat_log:read:chat"})
  76.      */
  77.     private ?Chat $chat;
  78.     /**
  79.      * @ORM\Column(type="datetime", nullable=true)
  80.      * @Gedmo\Timestampable(on="create")
  81.      * @Groups({"chat_log:read", "chat_log:read:createdAt"})
  82.      */
  83.     private $createdAt;
  84.     public function getId(): ?int
  85.     {
  86.         return $this->id;
  87.     }
  88.     
  89.     public function getType(): ?string
  90.     {
  91.         return $this->type;
  92.     }
  93.     public function setType(?string $type): self
  94.     {
  95.         $this->type $type;
  96.         return $this;
  97.     }
  98.     public function getValue(): ?int
  99.     {
  100.         return $this->value;
  101.     }
  102.     public function setValue(?int $value): self
  103.     {
  104.         $this->value $value;
  105.         return $this;
  106.     }
  107.     public function getUser(): ?User
  108.     {
  109.         return $this->user;
  110.     }
  111.     public function setUser(?User $user): self
  112.     {
  113.         $this->user $user;
  114.         return $this;
  115.     }
  116.     
  117.     public function getChat(): ?Chat
  118.     {
  119.         return $this->chat;
  120.     }
  121.     public function setChat(?Chat $chat): self
  122.     {
  123.         $this->chat $chat;
  124.         return $this;
  125.     }
  126.     public function getCreatedAt(): ?\DateTimeInterface
  127.     {
  128.         return $this->createdAt;
  129.     }
  130.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  131.     {
  132.         $this->createdAt $createdAt;
  133.         return $this;
  134.     }
  135. }