src/Entity/Conversation.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\ConversationRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. #[ApiResource(
  10.     normalizationContext: [
  11.         'groups' => ['read:conversation:collection']
  12.     ],
  13.     collectionOperations: [
  14.         'get',
  15.         'post',
  16.         // 'get_messages' => [
  17.         //     'method' => 'GET',
  18.         //     'path' => '/conversations/{id}/messages',
  19.         //     'controller' => ApiConversationController::class,
  20.         // ],
  21.     ],
  22.     // operations: [
  23.     //     new GetCollection(
  24.     //         controller: MyCustomController::class,
  25.     //     ),
  26.     // ],
  27. )]
  28. #[ORM\Entity(repositoryClassConversationRepository::class)]
  29. class Conversation
  30. {
  31.     public const STATUS_BLOCKED 'STATUS_BLOCKED';
  32.     public const STATUS_PENDING 'STATUS_PENDING';
  33.     public const STATUS_RECEIVED 'STATUS_RECEIVED';
  34.     public const STATUS_ACCEPTED 'STATUS_ACCEPTED';
  35.     public const STATUS_REJECTED 'STATUS_REJECTED';
  36.     public const STATUS_DELETED 'STATUS_DELETED';
  37.     public const TYPE_USER_PRIVATE 'conversation:type:private';
  38.     public const TYPE_USER_GROUP 'conversation:type:group';
  39.     public const TYPE_USER_GROUP_HIDDEN 'conversation:type:group:hidden';
  40.     public const TYPE_ACTIVITY_CONVERSATION_INVITATION_SEND 'conversation:invitation:send';
  41.     public const TYPE_ACTIVITY_CONVERSATION_MESSAGE_SEND 'conversation:message:send';
  42.     #[Groups(['read:conversation:collection'])]
  43.     #[ORM\Id]
  44.     #[ORM\GeneratedValue]
  45.     #[ORM\Column(type'integer')]
  46.     private $id;
  47.     #[Groups(['read:conversation:collection'])]
  48.     #[ORM\Column(type'datetime')]
  49.     private $dateCreation;
  50.     #[Groups(['read:conversation:collection'])]
  51.     #[ORM\Column(type'datetime'nullabletrue)]
  52.     private $dateUpdate;
  53.     #[Groups(['read:conversation:collection'])]
  54.     #[ORM\Column(type'string'length255)]
  55.     private $status;
  56.     #[Groups(['read:conversation:collection'])]
  57.     #[ORM\Column(type'string'length255)]
  58.     private $type;
  59.     #[Groups(['read:conversation:collection'])]
  60.     #[ORM\OneToMany(mappedBy'conversation'targetEntityMessage::class, cascade: ['persist''remove'])]
  61.     private $messages;
  62.     #[Groups(['read:conversation:collection'])]
  63.     #[ORM\ManyToOne(targetEntityGroupUser::class, cascade: ['persist''remove'])]
  64.     private GroupUser $groupUser;
  65.     #[ORM\Column(nullabletrue)]
  66.     private ?int $scroreBarVariation null;
  67.     #[Groups(['read:conversation:collection'])]
  68.     #[ORM\OneToOne(inversedBy'conversation'cascade: ['persist''remove'])]
  69.     private ?Event $event null;
  70.     #[ORM\ManyToOne]
  71.     private ?User $initialUser null;
  72.     public function __construct()
  73.     {
  74.         $this->messages = new ArrayCollection();
  75.     }
  76.     public function getId(): ?int
  77.     {
  78.         return $this->id;
  79.     }
  80.     public function getDateCreation(): ?\DateTimeInterface
  81.     {
  82.         return $this->dateCreation;
  83.     }
  84.     public function setDateCreation(\DateTimeInterface $dateCreation): self
  85.     {
  86.         $this->dateCreation $dateCreation;
  87.         return $this;
  88.     }
  89.     public function getDateUpdate(): ?\DateTimeInterface
  90.     {
  91.         return $this->dateUpdate;
  92.     }
  93.     public function setDateUpdate(?\DateTimeInterface $dateUpdate): self
  94.     {
  95.         $this->dateUpdate $dateUpdate;
  96.         return $this;
  97.     }
  98.     public function getStatus(): ?string
  99.     {
  100.         return $this->status;
  101.     }
  102.     public function setStatus(string $status): self
  103.     {
  104.         $this->status $status;
  105.         return $this;
  106.     }
  107.     /**
  108.      * @return Collection<int, Message>
  109.      */
  110.     public function getMessages(): array
  111.     {
  112.         return $this->messages->getValues();
  113.     }
  114.     public function addMessage(Message $message): self
  115.     {
  116.         if (!$this->messages->contains($message)) {
  117.             $this->messages[] = $message;
  118.             $message->setConversation($this);
  119.         }
  120.         return $this;
  121.     }
  122.     public function removeMessage(Message $message): self
  123.     {
  124.         if ($this->messages->removeElement($message)) {
  125.             // set the owning side to null (unless already changed)
  126.             if ($message->getConversation() === $this) {
  127.                 $message->setConversation(null);
  128.             }
  129.         }
  130.         return $this;
  131.     }
  132.     public function getType(): ?string
  133.     {
  134.         return $this->type;
  135.     }
  136.     public function setType(string $type): self
  137.     {
  138.         $this->type $type;
  139.         return $this;
  140.     }
  141.     public function getGroupUser(): ?GroupUser
  142.     {
  143.         return $this->groupUser;
  144.     }
  145.     public function setGroupUser(?GroupUser $groupUser): self
  146.     {
  147.         $this->groupUser $groupUser;
  148.         return $this;
  149.     }
  150.     public function getScroreBarVariation(): ?int
  151.     {
  152.         return $this->scroreBarVariation;
  153.     }
  154.     public function setScroreBarVariation(?int $scroreBarVariation): static
  155.     {
  156.         $this->scroreBarVariation $scroreBarVariation;
  157.         return $this;
  158.     }
  159.     public function getEvent(): ?Event
  160.     {
  161.         return $this->event;
  162.     }
  163.     public function setEvent(Event $event): static
  164.     {
  165.         $this->event $event;
  166.         return $this;
  167.     }
  168.     public function getInitialUser(): ?User
  169.     {
  170.         return $this->initialUser;
  171.     }
  172.     public function setInitialUser(?User $initialUser): static
  173.     {
  174.         $this->initialUser $initialUser;
  175.         return $this;
  176.     }
  177. }