<?php
namespace App\Entity;
use App\Repository\ConversationRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ConversationRepository::class)]
class Conversation
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\OneToOne(targetEntity: Message::class, cascade: ['persist', 'remove'])]
private $lastMessage;
#[ORM\OneToMany(targetEntity: Message::class, mappedBy: 'conversation')]
private $messages;
#[ORM\OneToMany(targetEntity: Participant::class, mappedBy: 'conversation')]
private $participants;
#[ORM\Column(type: 'string', length: 255)]
private $token;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'traineeConversations')]
private $trainee;
#[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'proConversations')]
private $pro;
#[ORM\Column(type: 'datetime', nullable: true)]
private $lastActivity;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $proLocale;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $traineeLocale;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $firstActivity;
public function __construct()
{
$this->messages = new ArrayCollection();
$this->participants = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getLastMessage(): ?Message
{
return $this->lastMessage;
}
public function setLastMessage(?Message $lastMessage): self
{
$this->lastMessage = $lastMessage;
return $this;
}
/**
* @return Collection|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;
}
/**
* @return Collection|Participant[]
*/
public function getParticipants(): Collection
{
return $this->participants;
}
public function addParticipant(Participant $participant): self
{
if (!$this->participants->contains($participant)) {
$this->participants[] = $participant;
$participant->setConversation($this);
}
return $this;
}
public function removeParticipant(Participant $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;
}
public function getToken(): ?string
{
return $this->token;
}
public function setToken(string $token): self
{
$this->token = $token;
return $this;
}
public function getTrainee(): ?User
{
return $this->trainee;
}
public function setTrainee(?User $trainee): self
{
$this->trainee = $trainee;
return $this;
}
public function getPro(): ?User
{
return $this->pro;
}
public function setPro(?User $pro): self
{
$this->pro = $pro;
return $this;
}
public function getLastActivity(): ?\DateTimeInterface
{
return $this->lastActivity;
}
public function setLastActivity(\DateTimeInterface $lastActivity): self
{
$this->lastActivity = $lastActivity;
return $this;
}
public function getProLocale(): ?string
{
return $this->proLocale;
}
public function setProLocale(?string $proLocale): self
{
$this->proLocale = $proLocale;
return $this;
}
public function getTraineeLocale(): ?string
{
return $this->traineeLocale;
}
public function setTraineeLocale(?string $traineeLocale): self
{
$this->traineeLocale = $traineeLocale;
return $this;
}
public function getFirstActivity(): ?string
{
return $this->firstActivity;
}
public function setFirstActivity(?string $firstActivity): self
{
$this->firstActivity = $firstActivity;
return $this;
}
}