src/Entity/Forum/ChapterMessage.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Forum;
  3. use App\Entity\Account\User;
  4. use App\Entity\Scholar\Chapter\Chapter;
  5. use App\Entity\Scholar\Module\Module;
  6. use App\Entity\Scholar\Training\Training;
  7. use App\Repository\Forum\ChapterMessageRepository;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Nellapp\Bundle\SDKBundle\Permission\UserOwner\UserOwnerResourceInterface;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. #[
  12. ORM\Entity(repositoryClass: ChapterMessageRepository::class),
  13. ORM\Table(name: 'forum_chapter_message'),
  14. ]
  15. class ChapterMessage extends AbstractMessage implements UserOwnerResourceInterface
  16. {
  17. #[ORM\ManyToOne(targetEntity: Chapter::class, inversedBy: 'messages')]
  18. #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
  19. private ?Chapter $chapter;
  20. #[ORM\ManyToOne(targetEntity: Training::class)]
  21. #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
  22. private ?Training $training = null;
  23. #[ORM\ManyToOne(targetEntity: Module::class)]
  24. #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
  25. private ?Module $module = null;
  26. #[ORM\ManyToOne(targetEntity: User::class)]
  27. #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
  28. private ?User $user = null;
  29. #[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
  30. #[Groups(['chat_bot'])]
  31. private bool $isBot = false;
  32. #[ORM\Column(type: 'boolean', nullable: false, options: ['default' => true])]
  33. private bool $enabled = true;
  34. public function getChapter(): ?Chapter
  35. {
  36. return $this->chapter;
  37. }
  38. public function setChapter(?Chapter $chapter): self
  39. {
  40. $this->chapter = $chapter;
  41. return $this;
  42. }
  43. public function getUser(): ?User
  44. {
  45. return $this->user;
  46. }
  47. public function setUser(?User $user): static
  48. {
  49. $this->user = $user;
  50. if ($this->user !== null) {
  51. $this->isBot = false;
  52. } else {
  53. $this->isBot = true;
  54. }
  55. return $this;
  56. }
  57. public function getTraining(): ?Training
  58. {
  59. return $this->training;
  60. }
  61. public function setTraining(?Training $training): ChapterMessage
  62. {
  63. $this->training = $training;
  64. return $this;
  65. }
  66. public function getModule(): ?Module
  67. {
  68. return $this->module;
  69. }
  70. public function setModule(?Module $module): ChapterMessage
  71. {
  72. $this->module = $module;
  73. return $this;
  74. }
  75. public function isBot(): bool
  76. {
  77. return $this->isBot;
  78. }
  79. public function setIsBot(bool $isBot): ChapterMessage
  80. {
  81. $this->isBot = $isBot;
  82. if ($this->isBot === true) {
  83. $this->setUser(null);
  84. }
  85. return $this;
  86. }
  87. public function isEnabled(): bool
  88. {
  89. return $this->enabled;
  90. }
  91. public function setEnabled(bool $enabled): ChapterMessage
  92. {
  93. $this->enabled = $enabled;
  94. return $this;
  95. }
  96. public function getUserOwners(): array
  97. {
  98. if ($this->getUser() !== null) {
  99. return [
  100. $this->getUser(),
  101. ];
  102. }
  103. return [];
  104. }
  105. }