<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\ConversationRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
#[ApiResource(
normalizationContext: [
'groups' => ['read:conversation:collection']
],
collectionOperations: [
'get',
'post',
// 'get_messages' => [
// 'method' => 'GET',
// 'path' => '/conversations/{id}/messages',
// 'controller' => ApiConversationController::class,
// ],
],
// operations: [
// new GetCollection(
// controller: MyCustomController::class,
// ),
// ],
)]
#[ORM\Entity(repositoryClass: ConversationRepository::class)]
class Conversation
{
public const STATUS_BLOCKED = 'STATUS_BLOCKED';
public const STATUS_PENDING = 'STATUS_PENDING';
public const STATUS_RECEIVED = 'STATUS_RECEIVED';
public const STATUS_ACCEPTED = 'STATUS_ACCEPTED';
public const STATUS_REJECTED = 'STATUS_REJECTED';
public const STATUS_DELETED = 'STATUS_DELETED';
public const TYPE_USER_PRIVATE = 'conversation:type:private';
public const TYPE_USER_GROUP = 'conversation:type:group';
public const TYPE_USER_GROUP_HIDDEN = 'conversation:type:group:hidden';
public const TYPE_ACTIVITY_CONVERSATION_INVITATION_SEND = 'conversation:invitation:send';
public const TYPE_ACTIVITY_CONVERSATION_MESSAGE_SEND = 'conversation:message:send';
#[Groups(['read:conversation:collection'])]
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[Groups(['read:conversation:collection'])]
#[ORM\Column(type: 'datetime')]
private $dateCreation;
#[Groups(['read:conversation:collection'])]
#[ORM\Column(type: 'datetime', nullable: true)]
private $dateUpdate;
#[Groups(['read:conversation:collection'])]
#[ORM\Column(type: 'string', length: 255)]
private $status;
#[Groups(['read:conversation:collection'])]
#[ORM\Column(type: 'string', length: 255)]
private $type;
#[Groups(['read:conversation:collection'])]
#[ORM\OneToMany(mappedBy: 'conversation', targetEntity: Message::class, cascade: ['persist', 'remove'])]
private $messages;
#[Groups(['read:conversation:collection'])]
#[ORM\ManyToOne(targetEntity: GroupUser::class, cascade: ['persist', 'remove'])]
private GroupUser $groupUser;
#[ORM\Column(nullable: true)]
private ?int $scroreBarVariation = null;
#[Groups(['read:conversation:collection'])]
#[ORM\OneToOne(inversedBy: 'conversation', cascade: ['persist', 'remove'])]
private ?Event $event = null;
#[ORM\ManyToOne]
private ?User $initialUser = null;
public function __construct()
{
$this->messages = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getDateCreation(): ?\DateTimeInterface
{
return $this->dateCreation;
}
public function setDateCreation(\DateTimeInterface $dateCreation): self
{
$this->dateCreation = $dateCreation;
return $this;
}
public function getDateUpdate(): ?\DateTimeInterface
{
return $this->dateUpdate;
}
public function setDateUpdate(?\DateTimeInterface $dateUpdate): self
{
$this->dateUpdate = $dateUpdate;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
/**
* @return Collection<int, Message>
*/
public function getMessages(): array
{
return $this->messages->getValues();
}
public function addMessage(Message $message): self
{
if (!$this->messages->contains($message)) {
$this->messages[] = $message;
$message->setConversation($this);
}
return $this;
}
public function removeMessage(Message $message): self
{
if ($this->messages->removeElement($message)) {
// set the owning side to null (unless already changed)
if ($message->getConversation() === $this) {
$message->setConversation(null);
}
}
return $this;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getGroupUser(): ?GroupUser
{
return $this->groupUser;
}
public function setGroupUser(?GroupUser $groupUser): self
{
$this->groupUser = $groupUser;
return $this;
}
public function getScroreBarVariation(): ?int
{
return $this->scroreBarVariation;
}
public function setScroreBarVariation(?int $scroreBarVariation): static
{
$this->scroreBarVariation = $scroreBarVariation;
return $this;
}
public function getEvent(): ?Event
{
return $this->event;
}
public function setEvent(Event $event): static
{
$this->event = $event;
return $this;
}
public function getInitialUser(): ?User
{
return $this->initialUser;
}
public function setInitialUser(?User $initialUser): static
{
$this->initialUser = $initialUser;
return $this;
}
}