<?php
namespace App\Entity;
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;
/**
* @ORM\Entity(repositoryClass=ConversationRepository::class)
*/
class Conversation
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups("conversation")
*/
private $id;
/**
* @ORM\OneToMany(targetEntity=ParticipantConversation::class, mappedBy="conversation", cascade={"persist"}, orphanRemoval=true)
*/
private $participants;
/**
* @ORM\OneToMany(targetEntity=Message::class, mappedBy="conversation")
* @Groups("conversation")
*/
private $messages;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"message","conversation"})
*/
private $title;
/**
* @ORM\Column(type="datetime", nullable=true)
* @Groups({"message","conversation"})
*/
private $createdAt;
/**
* @ORM\OneToMany(targetEntity=Notification::class, mappedBy="conversation")
*/
private $notifications;
public function __construct()
{
$this->participants = new ArrayCollection();
$this->messages = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->notifications = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): self
{
$this->title = $title;
return $this;
}
/**
* @return Collection<int, ParticipantConversation>
*/
public function getParticipants(): Collection
{
return $this->participants;
}
public function addParticipant(ParticipantConversation $participant): self
{
if (!$this->participants->contains($participant)) {
$this->participants[] = $participant;
$participant->setConversation($this);
}
return $this;
}
public function removeParticipant(ParticipantConversation $participant): self
{
if ($this->participants->removeElement($participant)) {
// set the owning side to null (unless already changed)
if ($participant->getConversation() === $this) {
$participant->setConversation(null);
}
}
return $this;
}
/**
* @return Collection<int, Message>
*/
public function getMessages(): Collection
{
return $this->messages;
}
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 getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
/**
* @return Collection<int, Notification>
*/
public function getNotifications(): Collection
{
return $this->notifications;
}
public function addNotification(Notification $notification): self
{
if (!$this->notifications->contains($notification)) {
$this->notifications[] = $notification;
$notification->setConversation($this);
}
return $this;
}
public function removeNotification(Notification $notification): self
{
if ($this->notifications->removeElement($notification)) {
// set the owning side to null (unless already changed)
if ($notification->getConversation() === $this) {
$notification->setConversation(null);
}
}
return $this;
}
}