src/Entity/Channel/Channel.php line 32

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