<?php
namespace App\Entity\Forum;
use App\Entity\Account\User;
use App\Entity\Scholar\Chapter\Chapter;
use App\Entity\Scholar\Module\Module;
use App\Entity\Scholar\Training\Training;
use App\Repository\Forum\ChapterMessageRepository;
use Doctrine\ORM\Mapping as ORM;
use Nellapp\Bundle\SDKBundle\Permission\UserOwner\UserOwnerResourceInterface;
use Symfony\Component\Serializer\Annotation\Groups;
#[
ORM\Entity(repositoryClass: ChapterMessageRepository::class),
ORM\Table(name: 'forum_chapter_message'),
]
class ChapterMessage extends AbstractMessage implements UserOwnerResourceInterface
{
#[ORM\ManyToOne(targetEntity: Chapter::class, inversedBy: 'messages')]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private ?Chapter $chapter;
#[ORM\ManyToOne(targetEntity: Training::class)]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?Training $training = null;
#[ORM\ManyToOne(targetEntity: Module::class)]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?Module $module = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?User $user = null;
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
#[Groups(['chat_bot'])]
private bool $isBot = false;
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => true])]
private bool $enabled = true;
public function getChapter(): ?Chapter
{
return $this->chapter;
}
public function setChapter(?Chapter $chapter): self
{
$this->chapter = $chapter;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): static
{
$this->user = $user;
if ($this->user !== null) {
$this->isBot = false;
} else {
$this->isBot = true;
}
return $this;
}
public function getTraining(): ?Training
{
return $this->training;
}
public function setTraining(?Training $training): ChapterMessage
{
$this->training = $training;
return $this;
}
public function getModule(): ?Module
{
return $this->module;
}
public function setModule(?Module $module): ChapterMessage
{
$this->module = $module;
return $this;
}
public function isBot(): bool
{
return $this->isBot;
}
public function setIsBot(bool $isBot): ChapterMessage
{
$this->isBot = $isBot;
if ($this->isBot === true) {
$this->setUser(null);
}
return $this;
}
public function isEnabled(): bool
{
return $this->enabled;
}
public function setEnabled(bool $enabled): ChapterMessage
{
$this->enabled = $enabled;
return $this;
}
public function getUserOwners(): array
{
if ($this->getUser() !== null) {
return [
$this->getUser(),
];
}
return [];
}
}