<?php
/*
* This file is part of the adrec-platform package.
*
* (c) Benjamin Georgeault <https://www.pressop.eu>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Entity\Forum;
use App\Entity\Account\User;
use App\Entity\Common\Assignable;
use App\Entity\Scholar\Chapter\Chapter;
use App\Entity\Scholar\Lesson\Lesson;
use App\Entity\Scholar\Module\Module;
use App\Entity\Scholar\Training\Training;
use App\Repository\Forum\MessageRepository;
use App\Validator\Constraints as AcmeAssert;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
#[
ORM\Entity(repositoryClass: MessageRepository::class),
ORM\Table(name: 'forum_chapter_message'),
]
class Message extends Assignable
{
#[ORM\Column(type: 'text', nullable: true)]
#[
Assert\NotBlank(message: 'scholar.forum.content.NotBlank'),
Assert\Length(
min: 2,
max: 2000,
minMessage: 'scholar.forum.content.Length.min',
maxMessage: 'scholar.forum.content.Length.max',
),
AcmeAssert\HtmlTagConstraint(),
AcmeAssert\InjuryConstraint(message: 'scholar.forum.content.InjuryConstraint')
]
private ?string $content = null;
#[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\OneToMany(mappedBy: 'parent', targetEntity: Message::class, orphanRemoval: true)]
private $children = null;
#[ORM\ManyToOne(targetEntity: Message::class, inversedBy: 'children')]
#[ORM\JoinColumn(nullable: true, onDelete: 'CASCADE')]
private $parent = null;
/**
* @return string|null
*/
public function getContent(): ?string
{
return $this->content;
}
/**
* @param string|null $content
*/
public function setContent(?string $content): void
{
$this->content = $content;
}
public function getChapter(): ?Chapter
{
return $this->chapter;
}
public function setChapter(?Chapter $chapter): self
{
$this->chapter = $chapter;
return $this;
}
/**
* @return User|null
*/
public function getUser(): ?User
{
return $this->user;
}
/**
* @param User|null $user
*/
public function setUser(?User $user): void
{
$this->user = $user;
}
/**
* @return Message[]|Collection
*/
public function getChildren()
{
return $this->children;
}
/**
* @param Message[]|Collection $children
*/
public function setChildren($children): void
{
$this->children = $children;
}
/**
* @return Message|null
*/
public function getParent(): ?Message
{
return $this->parent;
}
/**
* @param Message|null $parent
*/
public function setParent(?Message $parent): void
{
$this->parent = $parent;
}
public function getTraining(): ?Training
{
return $this->training;
}
public function setTraining(?Training $training): Message
{
$this->training = $training;
return $this;
}
public function getModule(): ?Module
{
return $this->module;
}
public function setModule(?Module $module): Message
{
$this->module = $module;
return $this;
}
}