<?php
/*
* This file is part of the adrec/platform-api package.
*
* (c) Benjamin Georgeault
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Entity\Channel;
use App\Entity\Account\User;
use App\Entity\Channel\Partner\Partner;
use App\Entity\ChannelUserData\ChannelUserData;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelInterface;
use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelMethodTrait;
use App\Repository\Channel\ChannelRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serial;
use Symfony\Component\Validator\Constraints as Assert;
#[
ORM\Entity(repositoryClass: ChannelRepository::class),
ORM\Table(name: 'channel_channels'),
ORM\Index(columns: ['name'], flags: ['fulltext']),
ORM\Index(columns: ['description'], flags: ['fulltext']),
]
class Channel implements ChannelInterface
{
use ChannelMethodTrait;
#[ORM\Id, ORM\Column(type: 'string', length: 36)]
#[Serial\Groups(['Manager'])]
private ?string $id = null;
#[ORM\Column(type: 'string')]
#[Serial\Groups(['Manager'])]
private ?string $name = null;
#[ORM\Column(type: 'string', nullable: true)]
#[Serial\Groups(['Manager'])]
private ?string $slogan = null;
#[ORM\Column(type: 'boolean', nullable: false)]
private bool $approved = false;
#[ORM\ManyToOne(targetEntity: User::class)]
private ?User $owner = null;
#[ORM\Column(type: 'boolean', nullable: false)]
private bool $canShareContent = false;
#[ORM\Column(type: 'boolean', nullable: false)]
private bool $canUploadVideo = false;
#[ORM\Column(type: 'string', nullable: true)]
private ?string $imagePath = null;
#[ORM\Column(type: 'text', nullable: true)]
#[Assert\Length(
min:20,
max: 2000,
minMessage: 'channel.channel.description.Length.min',
maxMessage: 'channel.channel.description.Length.max'
)]
private ?string $description = null;
#[ORM\OneToMany(mappedBy: 'channel', targetEntity: Link::class, cascade: ['persist', 'remove'], fetch: "EXTRA_LAZY", orphanRemoval: true)]
private $links = null;
#[ORM\ManyToOne(targetEntity: Image::class)]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?Image $image = null;
#[ORM\OneToMany(mappedBy: 'channel', targetEntity: Institution::class, cascade: ['persist', 'remove'], fetch: "EXTRA_LAZY", orphanRemoval: true)]
private $institutions;
#[ORM\OneToMany(mappedBy: 'channel', targetEntity: Partner::class, cascade: ['persist', 'remove'], fetch: "EXTRA_LAZY", orphanRemoval: true)]
private $partners;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $contactEmail;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $contactPhone;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $presentationTitle;
#[ORM\Column(type: 'text', nullable: true)]
private $presentationText;
#[ORM\OneToMany(mappedBy: 'channel', targetEntity: ChannelDescription::class, cascade: ['persist', 'remove'], fetch: "EXTRA_LAZY", orphanRemoval: true)]
private $channelDescriptions;
#[ORM\OneToMany(mappedBy: 'channel', targetEntity: ChannelGallery::class, cascade: ['persist', 'remove'], fetch: "EXTRA_LAZY", orphanRemoval: true)]
#[ORM\OrderBy(['displayOrder' => 'ASC'])]
private $galleryImages;
#[ORM\OneToMany(mappedBy: 'channel', targetEntity: ChannelUserData::class, fetch: "EXTRA_LAZY")]
private Collection $channelUserDatas;
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
private bool $paymentAlert = false;
#[ORM\OneToOne(mappedBy: 'channel', targetEntity: ChannelWhiteLabel::class)]
private ?ChannelWhiteLabel $channelWhiteLabel = null;
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
private bool $enabledIndexing = false;
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
private bool $enabledChatBot = false;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?User $defaultReferralTrainer = null;
/**
* Channel constructor.
*/
public function __construct()
{
$this->institutions = new ArrayCollection();
$this->partners = new ArrayCollection();
$this->channelDescriptions = new ArrayCollection();
$this->galleryImages = new ArrayCollection();
}
public function isCanUploadVideo(): bool
{
return $this->canUploadVideo;
}
/**
* @return string|null
*/
public function getDescription(): ?string
{
return $this->description;
}
/**
* @param string|null $description
*
* @return self
*/
public function setDescription(?string $description)
{
$this->description = $description;
return $this;
}
/**
* @return Link[]|Collection
*/
public function getLinks()
{
return $this->links ?: $this->links = new ArrayCollection();
}
/**
* @param Link $link
*
* @return self
*/
public function addLink(Link $link)
{
if (!$this->getLinks()->contains($link)) {
$this->getLinks()->add($link);
$link->setChannel($this);
}
return $this;
}
/**
* @param Link $link
* @return $this
*/
public function removeLink(Link $link): self
{
if ($this->links->contains($link)) {
$this->links->removeElement($link);
// set the owning side to null (unless already changed)
if ($link->getChannel() === $this) {
$link->setChannel(null);
}
}
return $this;
}
/**
* @return null|Image
*/
public function getImage(): ?Image
{
return $this->image;
}
/**
* @param null|Image $image
* @return $this
*/
public function setImage(?Image $image)
{
$this->image = $image;
return $this;
}
/**
* @return Collection|Institution[]
*/
public function getInstitutions(): Collection
{
return $this->institutions;
}
public function addInstitution(Institution $institution): self
{
if (!$this->institutions->contains($institution)) {
$this->institutions[] = $institution;
$institution->setChannel($this);
}
return $this;
}
public function removeInstitution(Institution $institution): self
{
if ($this->institutions->contains($institution)) {
$this->institutions->removeElement($institution);
// set the owning side to null (unless already changed)
if ($institution->getChannel() === $this) {
$institution->setChannel(null);
}
}
return $this;
}
/**
* @return Collection|Partner[]
*/
public function getPartners(): Collection
{
return $this->partners;
}
public function addPartner(Partner $partner): self
{
if (!$this->partners->contains($partner)) {
$this->partners[] = $partner;
$partner->setChannel($this);
}
return $this;
}
public function removePartner(Partner $partner): self
{
if ($this->partners->contains($partner)) {
$this->partners->removeElement($partner);
// set the owning side to null (unless already changed)
if ($partner->getChannel() === $this) {
$partner->setChannel(null);
}
}
return $this;
}
public function getContactEmail(): ?string
{
return $this->contactEmail;
}
public function setContactEmail(?string $contactEmail): self
{
$this->contactEmail = $contactEmail;
return $this;
}
public function getContactPhone(): ?string
{
return $this->contactPhone;
}
public function setContactPhone(?string $contactPhone): self
{
$this->contactPhone = $contactPhone;
return $this;
}
public function getPresentationTitle(): ?string
{
return $this->presentationTitle;
}
public function setPresentationTitle(?string $presentationTitle): self
{
$this->presentationTitle = $presentationTitle;
return $this;
}
public function getPresentationText(): ?string
{
return $this->presentationText;
}
public function setPresentationText(?string $presentationText): self
{
$this->presentationText = $presentationText;
return $this;
}
/**
* @return Collection|ChannelDescription[]
*/
public function getChannelDescriptions(): Collection
{
return $this->channelDescriptions;
}
public function addChannelDescription(ChannelDescription $channelDescription): self
{
if (!$this->channelDescriptions->contains($channelDescription)) {
$this->channelDescriptions[] = $channelDescription;
$channelDescription->setChannel($this);
}
return $this;
}
public function removeChannelDescription(ChannelDescription $channelDescription): self
{
if ($this->channelDescriptions->contains($channelDescription)) {
$this->channelDescriptions->removeElement($channelDescription);
// set the owning side to null (unless already changed)
if ($channelDescription->getChannel() === $this) {
$channelDescription->setChannel(null);
}
}
return $this;
}
/**
* @return Collection|ChannelGallery[]
*/
public function getGalleryImages(): Collection
{
return $this->galleryImages;
}
public function addGalleryImage(ChannelGallery $galleryImage): self
{
if (!$this->galleryImages->contains($galleryImage)) {
$this->galleryImages[] = $galleryImage;
$galleryImage->setChannel($this);
}
return $this;
}
public function removeGalleryImage(ChannelGallery $galleryImage): self
{
if ($this->galleryImages->contains($galleryImage)) {
$this->galleryImages->removeElement($galleryImage);
// set the owning side to null (unless already changed)
if ($galleryImage->getChannel() === $this) {
$galleryImage->setChannel(null);
}
}
return $this;
}
public function countChannelUserDatas(): int
{
return $this->channelUserDatas->count();
}
public function getWhiteLabel(): ?ChannelWhiteLabel
{
return $this->channelWhiteLabel;
}
public function setChannelWhiteLabel(?ChannelWhiteLabel $channelWhiteLabel): Channel
{
$this->channelWhiteLabel = $channelWhiteLabel;
return $this;
}
public function getDefaultReferralTrainer(): ?User
{
return $this->defaultReferralTrainer;
}
public function setDefaultReferralTrainer(?User $defaultReferralTrainer): Channel
{
$this->defaultReferralTrainer = $defaultReferralTrainer;
return $this;
}
}