<?php
namespace App\Entity;
use App\Entity\Common\StateInterface;
use App\Repository\WorkroomRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: WorkroomRepository::class)]
class Workroom
{
public const BINDINGS = [
'[[WORKROOM.NAME]]',
'[[WORKROOM.PROJECT.NAME]]',
];
public const STATE_CLOSED = StateInterface::STATE_WKR_CLOSED_INT;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private $name;
#[ORM\OneToOne(targetEntity: Chat::class, mappedBy: 'workroom', cascade: ['persist', 'remove'])]
private $chat;
#[ORM\OneToMany(targetEntity: Section::class, mappedBy: 'workroom', cascade: ['remove'])]
private $sections;
#[ORM\OneToMany(targetEntity: SemanticTag::class, mappedBy: 'workroom')]
private $semanticTags;
#[ORM\OneToMany(targetEntity: WorkroomResource::class, mappedBy: 'workroom', cascade: ['remove'])]
private $workroomResources;
#[ORM\ManyToOne(targetEntity: Project::class, inversedBy: 'workrooms')]
#[ORM\JoinColumn(onDelete: 'CASCADE')]
private $project;
#[ORM\OneToMany(targetEntity: UserWorkroom::class, mappedBy: 'workroom', cascade: ['remove'])]
private $userWorkrooms;
#[ORM\OneToMany(targetEntity: WorkroomFolder::class, mappedBy: 'workroom', cascade: ['remove'])]
private $workroomFolders;
#[ORM\Column(type: 'string', length: 255, unique: true)]
private $uuid;
#[ORM\ManyToMany(targetEntity: Invitation::class, mappedBy: 'workroom')]
private $invitations;
#[ORM\OneToMany(targetEntity: WorkroomRevision::class, mappedBy: 'workroom', orphanRemoval: true, cascade: ['remove'])]
private $workroomRevisions;
#[ORM\OneToOne(targetEntity: WorkroomArena::class, mappedBy: 'workroom', cascade: ['persist', 'remove'])]
private $workroomArena;
#[ORM\Column(name: 'state', type: 'smallint', options: ['default' => 1])]
private $state;
#[ORM\Column(type: 'smallint')]
private $position;
private Collection $chats;
/**
* Workroom constructor.
*/
public function __construct()
{
$this->chats = new ArrayCollection();
$this->sections = new ArrayCollection();
$this->workroomResources = new ArrayCollection();
$this->userWorkrooms = new ArrayCollection();
$this->workroomFolders = new ArrayCollection();
$this->invitations = new ArrayCollection();
$this->workroomRevisions = new ArrayCollection();
}
public function __toString()
{
return $this->name;
}
public function getBindings(): array
{
return [
'WORKROOM.NAME' => $this->getName(),
'WORKROOM.PROJECT.NAME' => $this->getProject()->getName(),
];
}
/**
* @return int|null
*/
public function getId(): ?int
{
return $this->id;
}
/**
* @return string|null
*/
public function getName(): ?string
{
return $this->name;
}
/**
* @param string $name
* @return $this
*/
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getChat(): ?Chat
{
return $this->chat;
}
public function setChat(Chat $chat): self
{
// set the owning side of the relation if necessary
if ($chat->getWorkroom() !== $this) {
$chat->setWorkroom($this);
}
$this->chat = $chat;
return $this;
}
/**
* @return Collection|Section[]
*/
public function getSections(): Collection
{
return $this->sections;
}
/**
* @param Section $section
* @return $this
*/
public function addSection(Section $section): self
{
if (!$this->sections->contains($section)) {
$this->sections[] = $section;
$section->setWorkroom($this);
}
return $this;
}
/**
* @param Section $section
* @return $this
*/
public function removeSection(Section $section): self
{
if ($this->sections->removeElement($section)) {
// set the owning side to null (unless already changed)
if ($section->getWorkroom() === $this) {
$section->setWorkroom(null);
}
}
return $this;
}
/**
* @return Collection|WorkroomResource[]
*/
public function getWorkroomResources(): Collection
{
return $this->workroomResources;
}
/**
* @param WorkroomResource $workroomResource
* @return $this
*/
public function addWorkroomResource(WorkroomResource $workroomResource): self
{
if (!$this->workroomResources->contains($workroomResource)) {
$this->workroomResources[] = $workroomResource;
$workroomResource->setWorkroom($this);
}
return $this;
}
/**
* @param WorkroomResource $workroomResource
* @return $this
*/
public function removeWorkroomResource(WorkroomResource $workroomResource): self
{
if ($this->workroomResources->removeElement($workroomResource)) {
// set the owning side to null (unless already changed)
if ($workroomResource->getWorkroom() === $this) {
$workroomResource->setWorkroom(null);
}
}
return $this;
}
/**
* @return Project|null
*/
public function getProject(): ?Project
{
return $this->project;
}
/**
* @param Project|null $project
* @return $this
*/
public function setProject(?Project $project): self
{
$this->project = $project;
return $this;
}
/**
* @return Collection|UserWorkroom[]
*/
public function getUserWorkrooms(): Collection
{
return $this->userWorkrooms;
}
/**
* @param UserWorkroom $userWorkroom
* @return $this
*/
public function addUserWorkroom(UserWorkroom $userWorkroom): self
{
if (!$this->userWorkrooms->contains($userWorkroom)) {
$this->userWorkrooms[] = $userWorkroom;
$userWorkroom->setWorkroom($this);
}
return $this;
}
/**
* @param UserWorkroom $userWorkroom
* @return $this
*/
public function removeUserWorkroom(UserWorkroom $userWorkroom): self
{
if ($this->userWorkrooms->removeElement($userWorkroom)) {
// set the owning side to null (unless already changed)
if ($userWorkroom->getWorkroom() === $this) {
$userWorkroom->setWorkroom(null);
}
}
return $this;
}
/**
* @return Collection|WorkroomFolder[]
*/
public function getWorkroomFolders(): Collection
{
return $this->workroomFolders;
}
public function addWorkroomFolder(WorkroomFolder $workroomFolder): self
{
if (!$this->workroomFolders->contains($workroomFolder)) {
$this->workroomFolders[] = $workroomFolder;
$workroomFolder->setWorkroom($this);
}
return $this;
}
public function removeWorkroomFolder(WorkroomFolder $workroomFolder): self
{
if ($this->workroomFolders->removeElement($workroomFolder)) {
// set the owning side to null (unless already changed)
if ($workroomFolder->getWorkroom() === $this) {
$workroomFolder->setWorkroom(null);
}
}
return $this;
}
public function getUuid(): ?string
{
return $this->uuid;
}
public function setUuid(string $uuid): self
{
$this->uuid = $uuid;
return $this;
}
/**
* @return $this
* @throws \Exception
*/
public function generateUuid(): self
{
$this->uuid = bin2hex(random_bytes(16));
return $this;
}
/**
* Gets triggered only on insert.
* Set created date.
*/
#[ORM\PrePersist]
public function onPrePersist()
{
$this->generateUuid();
return $this;
}
/**
* @return Collection|Invitation[]
*/
public function getInvitations(): Collection
{
return $this->invitations;
}
public function addInvitation(Invitation $invitation): self
{
if (!$this->invitations->contains($invitation)) {
$this->invitations[] = $invitation;
$invitation->addWorkroom($this);
}
return $this;
}
public function removeInvitation(Invitation $invitation): self
{
if ($this->invitations->removeElement($invitation)) {
$invitation->removeWorkroom($this);
}
return $this;
}
/**
* @return Collection|WorkroomRevision[]
*/
public function getWorkroomRevisions(): Collection
{
return $this->workroomRevisions;
}
public function addWorkroomRevision(WorkroomRevision $workroomRevision): self
{
if (!$this->workroomRevisions->contains($workroomRevision)) {
$this->workroomRevisions[] = $workroomRevision;
$workroomRevision->setWorkroom($this);
}
return $this;
}
public function removeWorkroomRevision(WorkroomRevision $workroomRevision): self
{
if ($this->workroomRevisions->removeElement($workroomRevision)) {
// set the owning side to null (unless already changed)
if ($workroomRevision->getWorkroom() === $this) {
$workroomRevision->setWorkroom(null);
}
}
return $this;
}
public function getWorkroomArena(): ?WorkroomArena
{
return $this->workroomArena;
}
public function setWorkroomArena(WorkroomArena $workroomArena): self
{
// set the owning side of the relation if necessary
if ($workroomArena->getWorkroom() !== $this) {
$workroomArena->setWorkroom($this);
}
$this->workroomArena = $workroomArena;
return $this;
}
public function getState(): ?int
{
return $this->state;
}
public function setState(int $state): self
{
$this->state = $state;
return $this;
}
/**
* @return int|null
*/
public function getPosition(): ?int
{
return $this->position;
}
/**
* @param int $position
* @return $this
*/
public function setPosition(int $position): self
{
$this->position = $position;
return $this;
}
}