src/Entity/Channel/Channel.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Channel;
  3. use App\Entity\Account\User;
  4. use App\Entity\Channel\Google\ChannelGoogleDriveFolder;
  5. use App\Entity\Sync\SyncableInterface;
  6. use App\Enum\ChannelPaymentStatusEnum;
  7. use App\Enum\ChannelStatusEnum;
  8. use App\Repository\Channel\ChannelRepository;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Doctrine\Common\Collections\Collection;
  11. use Doctrine\ORM\Mapping as ORM;
  12. use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
  13. use DrosalysWeb\ObjectExtensions\Blame\Model\BlameInterface;
  14. use DrosalysWeb\ObjectExtensions\Blame\Model\BlameTrait;
  15. use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampInterface;
  16. use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampTrait;
  17. use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelInterface;
  18. use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelMethodTrait;
  19. use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelWhiteLabel\ChannelWhiteLabelInterface;
  20. use Nellapp\Bundle\SDKBundle\Sync\EntityKeys;
  21. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  22. use Symfony\Component\Security\Core\User\UserInterface;
  23. use Symfony\Component\Serializer\Annotation as Serial;
  24. use Symfony\Component\Validator\Constraints as Assert;
  25. #[
  26. ORM\Entity(repositoryClass: ChannelRepository::class),
  27. ORM\Table(name: 'channel_channels'),
  28. ORM\Index(columns: ['name'], flags: ['fulltext']),
  29. ]
  30. class Channel implements TimestampInterface, BlameInterface, SyncableInterface, ChannelInterface
  31. {
  32. use ChannelMethodTrait;
  33. use BlameTrait;
  34. use TimestampTrait;
  35. #[ORM\Id, ORM\GeneratedValue(strategy: 'CUSTOM'), ORM\CustomIdGenerator(class: UuidGenerator::class), ORM\Column(type: 'string', length: 36)]
  36. #[Serial\Groups(['Manager', 'Sync', 'GlobalJSVariable'])]
  37. private ?string $id = null;
  38. #[ORM\Column(type: 'string', length: 63)]
  39. #[Serial\Groups(['Manager', 'Sync', 'GlobalJSVariable'])]
  40. #[Assert\NotBlank(
  41. message: 'channel.channel.name.NotBlank',
  42. )]
  43. #[Assert\Length(
  44. min: 2,
  45. max: 63,
  46. minMessage: 'channel.channel.name.Length.min',
  47. maxMessage: 'channel.channel.name.Length.max',
  48. )]
  49. private ?string $name = null;
  50. #[ORM\Column(type: 'string', length: 255, nullable: true)]
  51. #[Assert\Length(
  52. min: 5,
  53. max: 255,
  54. minMessage: 'channel.channel.slogan.Length.min',
  55. maxMessage: 'channel.channel.slogan.Length.max'
  56. )]
  57. private ?string $slogan = null;
  58. #[ORM\Column(type: 'string', length: 255, nullable: true)]
  59. #[Assert\Length(
  60. max: 255,
  61. maxMessage: 'channel.channel.slogan.Length.max'
  62. )]
  63. private ?string $website = null;
  64. #[ORM\Column(type: 'string', length: 20, nullable: true)]
  65. #[Assert\Length(
  66. min: 8,
  67. max: 20,
  68. minMessage: 'user.entity.phone.Length.min',
  69. maxMessage: 'user.entity.phone.Length.max'
  70. )
  71. ]
  72. private ?string $phoneNumber = null;
  73. #[ORM\Column(type: 'boolean', nullable: false)]
  74. #[Serial\Groups(['Sync'])]
  75. #[Assert\Type(
  76. type: 'boolean',
  77. message: 'channel.channel.approved.Type',
  78. )]
  79. private bool $approved = false;
  80. #[ORM\Column(type: 'boolean', nullable: false)]
  81. private bool $canShareContent = false;
  82. #[ORM\ManyToOne(targetEntity: User::class), ORM\JoinColumn(nullable: false)]
  83. #[IdGroups(['Manager', 'Sync'])]
  84. #[Assert\NotNull(
  85. message: 'channel.channel.owner.NotNull',
  86. )]
  87. private ?User $owner = null;
  88. #[ORM\OneToMany(mappedBy: 'channel', targetEntity: Organization::class, cascade: ['persist'], fetch: 'LAZY', orphanRemoval: true)]
  89. private Collection $organizations;
  90. #[ORM\Column(type: 'text', nullable: true)]
  91. #[Serial\Groups(['Sync'])]
  92. private ?string $imagePath = null;
  93. #[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
  94. #[Serial\Groups(['Sync'])]
  95. private bool $paymentAlert = false;
  96. #[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
  97. private bool $sepaMandate = false;
  98. #[ORM\Column(type: 'integer', nullable: false, options: ['default' => 2000])] // => default 20%
  99. private int $tva = 2000;
  100. #[ORM\Column(type: 'integer', nullable: false, options: ['default' => ChannelPaymentStatusEnum::UNKNOWN])]
  101. #[Assert\Choice(callback: [ChannelPaymentStatusEnum::class, 'getChoices'])]
  102. private int $paymentStatus = ChannelPaymentStatusEnum::UNKNOWN;
  103. #[ORM\Column(type: 'integer', nullable: false, options: ['default' => ChannelStatusEnum::ACTIVE])]
  104. private int $status = ChannelStatusEnum::ACTIVE;
  105. #[ORM\OneToMany(mappedBy: 'channel', targetEntity: ChannelUserRole::class, cascade: ['persist', 'remove'], fetch: 'LAZY', orphanRemoval: true)]
  106. private ?Collection $channelUserRoles;
  107. #[ORM\OneToOne(mappedBy: 'channel', targetEntity: ChannelWhiteLabel::class, cascade: ['persist', 'remove'], fetch: 'LAZY', orphanRemoval: true)]
  108. private ?ChannelWhiteLabel $whiteLabel = null;
  109. #[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
  110. #[Serial\Groups(['Sync'])]
  111. private bool $enabledIndexing = false;
  112. #[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
  113. #[Serial\Groups(['Sync'])]
  114. private bool $enabledNellbotTutor = false;
  115. #[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
  116. #[Serial\Groups(['Sync'])]
  117. private bool $enabledNellbotAgent = false;
  118. #[ORM\Column(type: 'boolean', nullable: false, options: ['default' => true])]
  119. #[Serial\Groups(['Sync'])]
  120. private bool $tuaProposal = true;
  121. #[ORM\OneToOne(inversedBy: 'channel', targetEntity: ChannelGoogleDriveFolder::class, cascade: ['persist', 'remove'], fetch: 'EXTRA_LAZY', orphanRemoval: true)]
  122. #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
  123. private ?ChannelGoogleDriveFolder $channelGoogleDriveFolder = null;
  124. #[ORM\OneToOne(inversedBy: 'channel', targetEntity: ChannelConfiguration::class, cascade: ['persist', 'remove'], fetch: 'LAZY', orphanRemoval: true)]
  125. #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
  126. private ?ChannelConfiguration $configuration = null;
  127. public function __construct()
  128. {
  129. $this->channelUserRoles = new ArrayCollection();
  130. $this->organizations = new ArrayCollection();
  131. }
  132. public static function getSyncKey(): string
  133. {
  134. return EntityKeys::CHANNEL;
  135. }
  136. public function getSyncDisplayLabel(): string
  137. {
  138. return $this->__toString();
  139. }
  140. public function toggleApproved(): static
  141. {
  142. $this->approved = !$this->approved;
  143. return $this;
  144. }
  145. public function togglePaymentAlert(): static
  146. {
  147. $this->paymentAlert = !$this->paymentAlert;
  148. return $this;
  149. }
  150. public function isOwner(?UserInterface $user): bool
  151. {
  152. return $user && $this->owner->isEqualTo($user);
  153. }
  154. public function getOrganizations(): Collection
  155. {
  156. return $this->organizations ?? $this->organizations = new ArrayCollection();
  157. }
  158. public function setOrganizations(Collection $organizations): Channel
  159. {
  160. $this->organizations = $organizations;
  161. return $this;
  162. }
  163. public function addOrganization(Organization $organization): Channel
  164. {
  165. if (!$this->getOrganizations()->contains($organization)) {
  166. $this->getOrganizations()->add($organization);
  167. $organization->setChannel($this);
  168. }
  169. return $this;
  170. }
  171. public function getWebsite(): ?string
  172. {
  173. return $this->website;
  174. }
  175. public function setWebsite(?string $website): Channel
  176. {
  177. $this->website = $website;
  178. return $this;
  179. }
  180. public function getPhoneNumber(): ?string
  181. {
  182. return $this->phoneNumber;
  183. }
  184. public function setPhoneNumber(?string $phoneNumber): Channel
  185. {
  186. $this->phoneNumber = $phoneNumber;
  187. return $this;
  188. }
  189. public function isSepaMandate(): bool
  190. {
  191. return $this->sepaMandate;
  192. }
  193. public function setSepaMandate(bool $sepaMandate): Channel
  194. {
  195. $this->sepaMandate = $sepaMandate;
  196. return $this;
  197. }
  198. public function toggleSepaMandate(): Channel
  199. {
  200. $this->sepaMandate = !$this->sepaMandate;
  201. return $this;
  202. }
  203. public function getTva(): int
  204. {
  205. return $this->tva;
  206. }
  207. public function setTva(int $tva): void
  208. {
  209. $this->tva = $tva;
  210. }
  211. public function getTvaDisplayed(): float
  212. {
  213. return $this->tva / 100;
  214. }
  215. public function getStatus(): int
  216. {
  217. return $this->status;
  218. }
  219. public function setStatus(int $status): Channel
  220. {
  221. $this->status = $status;
  222. return $this;
  223. }
  224. public function toggleStatus(): Channel
  225. {
  226. $this->status = !$this->status;
  227. return $this;
  228. }
  229. public function getPaymentStatus(): int
  230. {
  231. return $this->paymentStatus;
  232. }
  233. public function setPaymentStatus(int $paymentStatus): Channel
  234. {
  235. $this->paymentStatus = $paymentStatus;
  236. return $this;
  237. }
  238. public function getChannelUserRoles(): Collection
  239. {
  240. return $this->channelUserRoles ?? $this->channelUserRoles = new ArrayCollection();
  241. }
  242. public function setChannelUserRoles(?Collection $channelUserRoles): Channel
  243. {
  244. $this->channelUserRoles = $channelUserRoles;
  245. return $this;
  246. }
  247. public function addChannelUserRole(ChannelUserRole $channelUserRole): static
  248. {
  249. if (!$this->getChannelUserRoles()->contains($channelUserRole)) {
  250. $this->getChannelUserRoles()->add($channelUserRole);
  251. $channelUserRole->setChannel($this);
  252. }
  253. return $this;
  254. }
  255. public function getWhiteLabel(): ?ChannelWhiteLabelInterface
  256. {
  257. return $this->whiteLabel;
  258. }
  259. public function setWhiteLabel(?ChannelWhiteLabelInterface $whiteLabel): static
  260. {
  261. $this->whiteLabel = $whiteLabel;
  262. return $this;
  263. }
  264. public function toggleNellbotTutor(): static
  265. {
  266. $this->enabledNellbotTutor = !$this->enabledNellbotTutor;
  267. return $this;
  268. }
  269. public function toggleNellbotAgent(): static
  270. {
  271. $this->enabledNellbotAgent = !$this->enabledNellbotAgent;
  272. return $this;
  273. }
  274. public function isTuaProposal(): bool
  275. {
  276. return $this->tuaProposal;
  277. }
  278. public function setTuaProposal(bool $tuaProposal): static
  279. {
  280. $this->tuaProposal = $tuaProposal;
  281. return $this;
  282. }
  283. public function toggleTuaProposal(): static
  284. {
  285. $this->tuaProposal = !$this->tuaProposal;
  286. return $this;
  287. }
  288. public function getChannelGoogleDriveFolder(): ?ChannelGoogleDriveFolder
  289. {
  290. return $this->channelGoogleDriveFolder;
  291. }
  292. public function setChannelGoogleDriveFolder(?ChannelGoogleDriveFolder $channelGoogleDriveFolder): Channel
  293. {
  294. $this->channelGoogleDriveFolder = $channelGoogleDriveFolder;
  295. return $this;
  296. }
  297. public function isEnabledGoogleDrive(): bool
  298. {
  299. return $this->getChannelGoogleDriveFolder() !== null;
  300. }
  301. public function getConfiguration(): ?ChannelConfiguration
  302. {
  303. return $this->configuration;
  304. }
  305. public function setConfiguration(?ChannelConfiguration $configuration): static
  306. {
  307. $this->configuration = $configuration;
  308. $this->configuration?->setChannel($this);
  309. return $this;
  310. }
  311. }