src/Entity/Workroom.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Common\StateInterface;
  4. use App\Repository\WorkroomRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassWorkroomRepository::class)]
  9. class Workroom
  10. {
  11.     public const BINDINGS = [
  12.         '[[WORKROOM.NAME]]',
  13.         '[[WORKROOM.PROJECT.NAME]]',
  14.     ];
  15.     public const STATE_CLOSED StateInterface::STATE_WKR_CLOSED_INT;
  16.     
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column(type'integer')]
  20.     private $id;
  21.     #[ORM\Column(type'string'length255)]
  22.     private $name;
  23.     #[ORM\OneToOne(targetEntityChat::class, mappedBy'workroom'cascade: ['persist''remove'])]
  24.     private $chat;
  25.     #[ORM\OneToMany(targetEntitySection::class, mappedBy'workroom'cascade: ['remove'])]
  26.     private $sections;
  27.     #[ORM\OneToMany(targetEntitySemanticTag::class, mappedBy'workroom')]
  28.     private $semanticTags;
  29.     #[ORM\OneToMany(targetEntityWorkroomResource::class, mappedBy'workroom'cascade: ['remove'])]
  30.     private $workroomResources;
  31.     #[ORM\ManyToOne(targetEntityProject::class, inversedBy'workrooms')]
  32.     #[ORM\JoinColumn(onDelete'CASCADE')]
  33.     private $project;
  34.     #[ORM\OneToMany(targetEntityUserWorkroom::class, mappedBy'workroom'cascade: ['remove'])]
  35.     private $userWorkrooms;
  36.     #[ORM\OneToMany(targetEntityWorkroomFolder::class, mappedBy'workroom'cascade: ['remove'])]
  37.     private $workroomFolders;
  38.     #[ORM\Column(type'string'length255uniquetrue)]
  39.     private $uuid;
  40.     #[ORM\ManyToMany(targetEntityInvitation::class, mappedBy'workroom')]
  41.     private $invitations;
  42.     #[ORM\OneToMany(targetEntityWorkroomRevision::class, mappedBy'workroom'orphanRemovaltruecascade: ['remove'])]
  43.     private $workroomRevisions;
  44.     #[ORM\OneToOne(targetEntityWorkroomArena::class, mappedBy'workroom'cascade: ['persist''remove'])]
  45.     private $workroomArena;
  46.     #[ORM\Column(name'state'type'smallint'options: ['default' => 1])]
  47.     private $state;
  48.     #[ORM\Column(type'smallint')]
  49.     private $position;
  50.     private Collection $chats;
  51.     /**
  52.      * Workroom constructor.
  53.      */
  54.     public function __construct()
  55.     {
  56.         $this->chats = new ArrayCollection();
  57.         $this->sections = new ArrayCollection();
  58.         $this->workroomResources = new ArrayCollection();
  59.         $this->userWorkrooms = new ArrayCollection();
  60.         $this->workroomFolders = new ArrayCollection();
  61.         $this->invitations = new ArrayCollection();
  62.         $this->workroomRevisions = new ArrayCollection();
  63.     }
  64.     public function __toString()
  65.     {
  66.         return $this->name;
  67.     }
  68.     
  69.     public function getBindings(): array
  70.     {
  71.         return [
  72.             'WORKROOM.NAME' => $this->getName(),
  73.             'WORKROOM.PROJECT.NAME' => $this->getProject()->getName(),
  74.         ];
  75.     }
  76.     /**
  77.      * @return int|null
  78.      */
  79.     public function getId(): ?int
  80.     {
  81.         return $this->id;
  82.     }
  83.     /**
  84.      * @return string|null
  85.      */
  86.     public function getName(): ?string
  87.     {
  88.         return $this->name;
  89.     }
  90.     /**
  91.      * @param string $name
  92.      * @return $this
  93.      */
  94.     public function setName(string $name): self
  95.     {
  96.         $this->name $name;
  97.         return $this;
  98.     }
  99.     public function getChat(): ?Chat
  100.     {
  101.         return $this->chat;
  102.     }
  103.     public function setChat(Chat $chat): self
  104.     {
  105.         // set the owning side of the relation if necessary
  106.         if ($chat->getWorkroom() !== $this) {
  107.             $chat->setWorkroom($this);
  108.         }
  109.         $this->chat $chat;
  110.         return $this;
  111.     }
  112.     /**
  113.      * @return Collection|Section[]
  114.      */
  115.     public function getSections(): Collection
  116.     {
  117.         return $this->sections;
  118.     }
  119.     /**
  120.      * @param Section $section
  121.      * @return $this
  122.      */
  123.     public function addSection(Section $section): self
  124.     {
  125.         if (!$this->sections->contains($section)) {
  126.             $this->sections[] = $section;
  127.             $section->setWorkroom($this);
  128.         }
  129.         return $this;
  130.     }
  131.     /**
  132.      * @param Section $section
  133.      * @return $this
  134.      */
  135.     public function removeSection(Section $section): self
  136.     {
  137.         if ($this->sections->removeElement($section)) {
  138.             // set the owning side to null (unless already changed)
  139.             if ($section->getWorkroom() === $this) {
  140.                 $section->setWorkroom(null);
  141.             }
  142.         }
  143.         return $this;
  144.     }
  145.     /**
  146.      * @return Collection|WorkroomResource[]
  147.      */
  148.     public function getWorkroomResources(): Collection
  149.     {
  150.         return $this->workroomResources;
  151.     }
  152.     /**
  153.      * @param WorkroomResource $workroomResource
  154.      * @return $this
  155.      */
  156.     public function addWorkroomResource(WorkroomResource $workroomResource): self
  157.     {
  158.         if (!$this->workroomResources->contains($workroomResource)) {
  159.             $this->workroomResources[] = $workroomResource;
  160.             $workroomResource->setWorkroom($this);
  161.         }
  162.         return $this;
  163.     }
  164.     /**
  165.      * @param WorkroomResource $workroomResource
  166.      * @return $this
  167.      */
  168.     public function removeWorkroomResource(WorkroomResource $workroomResource): self
  169.     {
  170.         if ($this->workroomResources->removeElement($workroomResource)) {
  171.             // set the owning side to null (unless already changed)
  172.             if ($workroomResource->getWorkroom() === $this) {
  173.                 $workroomResource->setWorkroom(null);
  174.             }
  175.         }
  176.         return $this;
  177.     }
  178.     /**
  179.      * @return Project|null
  180.      */
  181.     public function getProject(): ?Project
  182.     {
  183.         return $this->project;
  184.     }
  185.     /**
  186.      * @param Project|null $project
  187.      * @return $this
  188.      */
  189.     public function setProject(?Project $project): self
  190.     {
  191.         $this->project $project;
  192.         return $this;
  193.     }
  194.     /**
  195.      * @return Collection|UserWorkroom[]
  196.      */
  197.     public function getUserWorkrooms(): Collection
  198.     {
  199.         return $this->userWorkrooms;
  200.     }
  201.     /**
  202.      * @param UserWorkroom $userWorkroom
  203.      * @return $this
  204.      */
  205.     public function addUserWorkroom(UserWorkroom $userWorkroom): self
  206.     {
  207.         if (!$this->userWorkrooms->contains($userWorkroom)) {
  208.             $this->userWorkrooms[] = $userWorkroom;
  209.             $userWorkroom->setWorkroom($this);
  210.         }
  211.         return $this;
  212.     }
  213.     /**
  214.      * @param UserWorkroom $userWorkroom
  215.      * @return $this
  216.      */
  217.     public function removeUserWorkroom(UserWorkroom $userWorkroom): self
  218.     {
  219.         if ($this->userWorkrooms->removeElement($userWorkroom)) {
  220.             // set the owning side to null (unless already changed)
  221.             if ($userWorkroom->getWorkroom() === $this) {
  222.                 $userWorkroom->setWorkroom(null);
  223.             }
  224.         }
  225.         return $this;
  226.     }
  227.     /**
  228.      * @return Collection|WorkroomFolder[]
  229.      */
  230.     public function getWorkroomFolders(): Collection
  231.     {
  232.         return $this->workroomFolders;
  233.     }
  234.     public function addWorkroomFolder(WorkroomFolder $workroomFolder): self
  235.     {
  236.         if (!$this->workroomFolders->contains($workroomFolder)) {
  237.             $this->workroomFolders[] = $workroomFolder;
  238.             $workroomFolder->setWorkroom($this);
  239.         }
  240.         return $this;
  241.     }
  242.     public function removeWorkroomFolder(WorkroomFolder $workroomFolder): self
  243.     {
  244.         if ($this->workroomFolders->removeElement($workroomFolder)) {
  245.             // set the owning side to null (unless already changed)
  246.             if ($workroomFolder->getWorkroom() === $this) {
  247.                 $workroomFolder->setWorkroom(null);
  248.             }
  249.         }
  250.         return $this;
  251.     }
  252.     public function getUuid(): ?string
  253.     {
  254.         return $this->uuid;
  255.     }
  256.     public function setUuid(string $uuid): self
  257.     {
  258.         $this->uuid $uuid;
  259.         return $this;
  260.     }
  261.     /**
  262.      * @return $this
  263.      * @throws \Exception
  264.      */
  265.     public function generateUuid(): self
  266.     {
  267.         $this->uuid bin2hex(random_bytes(16));
  268.         return $this;
  269.     }
  270.     /**
  271.      * Gets triggered only on insert.
  272.      * Set created date.
  273.      */
  274.     #[ORM\PrePersist]
  275.     public function onPrePersist()
  276.     {
  277.         $this->generateUuid();
  278.         return $this;
  279.     }
  280.     /**
  281.      * @return Collection|Invitation[]
  282.      */
  283.     public function getInvitations(): Collection
  284.     {
  285.         return $this->invitations;
  286.     }
  287.     public function addInvitation(Invitation $invitation): self
  288.     {
  289.         if (!$this->invitations->contains($invitation)) {
  290.             $this->invitations[] = $invitation;
  291.             $invitation->addWorkroom($this);
  292.         }
  293.         return $this;
  294.     }
  295.     public function removeInvitation(Invitation $invitation): self
  296.     {
  297.         if ($this->invitations->removeElement($invitation)) {
  298.             $invitation->removeWorkroom($this);
  299.         }
  300.         return $this;
  301.     }
  302.     /**
  303.      * @return Collection|WorkroomRevision[]
  304.      */
  305.     public function getWorkroomRevisions(): Collection
  306.     {
  307.         return $this->workroomRevisions;
  308.     }
  309.     public function addWorkroomRevision(WorkroomRevision $workroomRevision): self
  310.     {
  311.         if (!$this->workroomRevisions->contains($workroomRevision)) {
  312.             $this->workroomRevisions[] = $workroomRevision;
  313.             $workroomRevision->setWorkroom($this);
  314.         }
  315.         return $this;
  316.     }
  317.     public function removeWorkroomRevision(WorkroomRevision $workroomRevision): self
  318.     {
  319.         if ($this->workroomRevisions->removeElement($workroomRevision)) {
  320.             // set the owning side to null (unless already changed)
  321.             if ($workroomRevision->getWorkroom() === $this) {
  322.                 $workroomRevision->setWorkroom(null);
  323.             }
  324.         }
  325.         return $this;
  326.     }
  327.     public function getWorkroomArena(): ?WorkroomArena
  328.     {
  329.         return $this->workroomArena;
  330.     }
  331.     public function setWorkroomArena(WorkroomArena $workroomArena): self
  332.     {
  333.         // set the owning side of the relation if necessary
  334.         if ($workroomArena->getWorkroom() !== $this) {
  335.             $workroomArena->setWorkroom($this);
  336.         }
  337.         $this->workroomArena $workroomArena;
  338.         return $this;
  339.     }
  340.     public function getState(): ?int
  341.     {
  342.         return $this->state;
  343.     }
  344.     public function setState(int $state): self
  345.     {
  346.         $this->state $state;
  347.         return $this;
  348.     }
  349.     /**
  350.      * @return int|null
  351.      */
  352.     public function getPosition(): ?int
  353.     {
  354.         return $this->position;
  355.     }
  356.     /**
  357.      * @param int $position
  358.      * @return $this
  359.      */
  360.     public function setPosition(int $position): self
  361.     {
  362.         $this->position $position;
  363.         return $this;
  364.     }
  365. }