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', 'partner_api_channels_index'])]
  37. private ?string $id = null;
  38. #[ORM\Column(type: 'string', length: 63)]
  39. #[Serial\Groups(['Manager', 'Sync', 'GlobalJSVariable', 'partner_api_channels_index'])]
  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. #[Serial\Groups(['partner_api_channels_index'])]
  60. #[Assert\Length(
  61. max: 255,
  62. maxMessage: 'channel.channel.slogan.Length.max'
  63. )]
  64. private ?string $website = null;
  65. #[ORM\Column(type: 'string', length: 20, nullable: true)]
  66. #[Serial\Groups(['partner_api_channels_index'])]
  67. #[Assert\Length(
  68. min: 8,
  69. max: 20,
  70. minMessage: 'user.entity.phone.Length.min',
  71. maxMessage: 'user.entity.phone.Length.max'
  72. )
  73. ]
  74. private ?string $phoneNumber = null;
  75. #[ORM\Column(type: 'boolean', nullable: false)]
  76. #[Serial\Groups(['Sync'])]
  77. #[Assert\Type(
  78. type: 'boolean',
  79. message: 'channel.channel.approved.Type',
  80. )]
  81. private bool $approved = false;
  82. #[ORM\Column(type: 'boolean', nullable: false)]
  83. private bool $canShareContent = false;
  84. #[ORM\ManyToOne(targetEntity: User::class), ORM\JoinColumn(nullable: false)]
  85. #[IdGroups(['Manager', 'Sync'])]
  86. #[Assert\NotNull(
  87. message: 'channel.channel.owner.NotNull',
  88. )]
  89. private ?User $owner = null;
  90. #[ORM\OneToMany(mappedBy: 'channel', targetEntity: Organization::class, cascade: ['persist'], fetch: 'LAZY', orphanRemoval: true)]
  91. private Collection $organizations;
  92. #[ORM\Column(type: 'text', nullable: true)]
  93. #[Serial\Groups(['Sync'])]
  94. private ?string $imagePath = null;
  95. #[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
  96. #[Serial\Groups(['Sync'])]
  97. private bool $paymentAlert = false;
  98. #[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
  99. private bool $sepaMandate = false;
  100. #[ORM\Column(type: 'integer', nullable: false, options: ['default' => 2000])] // => default 20%
  101. private int $tva = 2000;
  102. #[ORM\Column(type: 'integer', nullable: false, options: ['default' => ChannelPaymentStatusEnum::UNKNOWN])]
  103. #[Assert\Choice(callback: [ChannelPaymentStatusEnum::class, 'getChoices'])]
  104. private int $paymentStatus = ChannelPaymentStatusEnum::UNKNOWN;
  105. #[ORM\Column(type: 'integer', nullable: false, options: ['default' => ChannelStatusEnum::ACTIVE])]
  106. private int $status = ChannelStatusEnum::ACTIVE;
  107. #[ORM\OneToMany(mappedBy: 'channel', targetEntity: ChannelUserRole::class, cascade: ['persist', 'remove'], fetch: 'LAZY', orphanRemoval: true)]
  108. private ?Collection $channelUserRoles;
  109. #[ORM\OneToOne(mappedBy: 'channel', targetEntity: ChannelWhiteLabel::class, cascade: ['persist', 'remove'], fetch: 'LAZY', orphanRemoval: true)]
  110. private ?ChannelWhiteLabel $whiteLabel = null;
  111. #[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
  112. #[Serial\Groups(['Sync'])]
  113. private bool $enabledIndexing = false;
  114. #[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
  115. #[Serial\Groups(['Sync'])]
  116. private bool $enabledChatBot = false;
  117. #[ORM\Column(type: 'boolean', nullable: false, options: ['default' => true])]
  118. #[Serial\Groups(['Sync'])]
  119. private bool $tuaProposal = true;
  120. #[ORM\OneToOne(inversedBy: 'channel', targetEntity: ChannelGoogleDriveFolder::class, cascade: ['persist', 'remove'], fetch: 'EXTRA_LAZY', orphanRemoval: true)]
  121. #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
  122. private ?ChannelGoogleDriveFolder $channelGoogleDriveFolder = null;
  123. #[ORM\OneToOne(inversedBy: 'channel', targetEntity: ChannelConfiguration::class, cascade: ['persist', 'remove'], fetch: 'LAZY', orphanRemoval: true)]
  124. #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
  125. private ?ChannelConfiguration $configuration = null;
  126. public function __construct()
  127. {
  128. $this->channelUserRoles = new ArrayCollection();
  129. $this->organizations = new ArrayCollection();
  130. }
  131. public static function getSyncKey(): string
  132. {
  133. return EntityKeys::CHANNEL;
  134. }
  135. public function getSyncDisplayLabel(): string
  136. {
  137. return $this->__toString();
  138. }
  139. public function toggleApproved(): static
  140. {
  141. $this->approved = !$this->approved;
  142. return $this;
  143. }
  144. public function togglePaymentAlert(): static
  145. {
  146. $this->paymentAlert = !$this->paymentAlert;
  147. return $this;
  148. }
  149. public function isOwner(?UserInterface $user): bool
  150. {
  151. return $user && $this->owner->isEqualTo($user);
  152. }
  153. public function getOrganizations(): Collection
  154. {
  155. return $this->organizations ?? $this->organizations = new ArrayCollection();
  156. }
  157. public function setOrganizations(Collection $organizations): Channel
  158. {
  159. $this->organizations = $organizations;
  160. return $this;
  161. }
  162. public function addOrganization(Organization $organization): Channel
  163. {
  164. if (!$this->getOrganizations()->contains($organization)) {
  165. $this->getOrganizations()->add($organization);
  166. $organization->setChannel($this);
  167. }
  168. return $this;
  169. }
  170. public function getWebsite(): ?string
  171. {
  172. return $this->website;
  173. }
  174. public function setWebsite(?string $website): Channel
  175. {
  176. $this->website = $website;
  177. return $this;
  178. }
  179. public function getPhoneNumber(): ?string
  180. {
  181. return $this->phoneNumber;
  182. }
  183. public function setPhoneNumber(?string $phoneNumber): Channel
  184. {
  185. $this->phoneNumber = $phoneNumber;
  186. return $this;
  187. }
  188. public function isSepaMandate(): bool
  189. {
  190. return $this->sepaMandate;
  191. }
  192. public function setSepaMandate(bool $sepaMandate): Channel
  193. {
  194. $this->sepaMandate = $sepaMandate;
  195. return $this;
  196. }
  197. public function toggleSepaMandate(): Channel
  198. {
  199. $this->sepaMandate = !$this->sepaMandate;
  200. return $this;
  201. }
  202. public function getTva(): int
  203. {
  204. return $this->tva;
  205. }
  206. public function setTva(int $tva): void
  207. {
  208. $this->tva = $tva;
  209. }
  210. public function getTvaDisplayed(): float
  211. {
  212. return $this->tva / 100;
  213. }
  214. public function getStatus(): int
  215. {
  216. return $this->status;
  217. }
  218. public function setStatus(int $status): Channel
  219. {
  220. $this->status = $status;
  221. return $this;
  222. }
  223. public function toggleStatus(): Channel
  224. {
  225. $this->status = !$this->status;
  226. return $this;
  227. }
  228. public function getPaymentStatus(): int
  229. {
  230. return $this->paymentStatus;
  231. }
  232. public function setPaymentStatus(int $paymentStatus): Channel
  233. {
  234. $this->paymentStatus = $paymentStatus;
  235. return $this;
  236. }
  237. public function getChannelUserRoles(): Collection
  238. {
  239. return $this->channelUserRoles ?? $this->channelUserRoles = new ArrayCollection();
  240. }
  241. public function setChannelUserRoles(?Collection $channelUserRoles): Channel
  242. {
  243. $this->channelUserRoles = $channelUserRoles;
  244. return $this;
  245. }
  246. public function addChannelUserRole(ChannelUserRole $channelUserRole): static
  247. {
  248. if (!$this->getChannelUserRoles()->contains($channelUserRole)) {
  249. $this->getChannelUserRoles()->add($channelUserRole);
  250. $channelUserRole->setChannel($this);
  251. }
  252. return $this;
  253. }
  254. public function getWhiteLabel(): ?ChannelWhiteLabelInterface
  255. {
  256. return $this->whiteLabel;
  257. }
  258. public function setWhiteLabel(?ChannelWhiteLabelInterface $whiteLabel): static
  259. {
  260. $this->whiteLabel = $whiteLabel;
  261. return $this;
  262. }
  263. public function toggleEnabledChatBot(): static
  264. {
  265. $this->enabledChatBot = !$this->enabledChatBot;
  266. return $this;
  267. }
  268. public function isTuaProposal(): bool
  269. {
  270. return $this->tuaProposal;
  271. }
  272. public function setTuaProposal(bool $tuaProposal): static
  273. {
  274. $this->tuaProposal = $tuaProposal;
  275. return $this;
  276. }
  277. public function toggleTuaProposal(): static
  278. {
  279. $this->tuaProposal = !$this->tuaProposal;
  280. return $this;
  281. }
  282. public function getChannelGoogleDriveFolder(): ?ChannelGoogleDriveFolder
  283. {
  284. return $this->channelGoogleDriveFolder;
  285. }
  286. public function setChannelGoogleDriveFolder(?ChannelGoogleDriveFolder $channelGoogleDriveFolder): Channel
  287. {
  288. $this->channelGoogleDriveFolder = $channelGoogleDriveFolder;
  289. return $this;
  290. }
  291. public function isEnabledGoogleDrive(): bool
  292. {
  293. return $this->getChannelGoogleDriveFolder() !== null;
  294. }
  295. public function getConfiguration(): ?ChannelConfiguration
  296. {
  297. return $this->configuration;
  298. }
  299. public function setConfiguration(?ChannelConfiguration $configuration): static
  300. {
  301. $this->configuration = $configuration;
  302. $this->configuration?->setChannel($this);
  303. return $this;
  304. }
  305. }