<?php
namespace App\Entity\Channel;
use App\Entity\Account\User;
use App\Entity\Sync\SyncableInterface;
use App\Repository\Channel\ChannelConfigurationRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
use Nellapp\Bundle\SDKBundle\Channel\Entity\Configuration\BaseChannelConfigurationInterface;
use Nellapp\Bundle\SDKBundle\Channel\Entity\Configuration\BaseChannelConfigurationMethodTrait;
use Nellapp\Bundle\SDKBundle\Channel\Entity\Configuration\ELearningChannelConfigurationInterface;
use Nellapp\Bundle\SDKBundle\Channel\Entity\Configuration\ELearningChannelConfigurationMethodTrait;
use Nellapp\Bundle\SDKBundle\Channel\Entity\Configuration\PlanningChannelConfigurationInterface;
use Nellapp\Bundle\SDKBundle\Channel\Entity\Configuration\PlanningChannelConfigurationMethodTrait;
use Nellapp\Bundle\SDKBundle\Sync\EntityKeys;
use Symfony\Component\Serializer\Annotation as Serial;
use Symfony\Component\Validator\Constraints as Assert;
#[
ORM\Entity(repositoryClass: ChannelConfigurationRepository::class),
ORM\Table(name: 'channel_configuration')
]
class ChannelConfiguration implements BaseChannelConfigurationInterface, PlanningChannelConfigurationInterface, ELearningChannelConfigurationInterface, SyncableInterface
{
use BaseChannelConfigurationMethodTrait;
use PlanningChannelConfigurationMethodTrait;
use ELearningChannelConfigurationMethodTrait;
#[ORM\Id, ORM\GeneratedValue, ORM\Column(type: 'integer', nullable: false)]
#[Serial\Groups(['Sync'])]
private ?int $id = null;
#[ORM\OneToOne(mappedBy: 'configuration', targetEntity: Channel::class, fetch: 'EAGER')]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
#[IdGroups(['Sync'])]
private ?Channel $channel = null;
#[ORM\Column(type: 'string', length: 50, nullable: true)]
#[Assert\Timezone(
message: 'channel.configuration.timezone.Timezone',
)]
#[Serial\Groups(['Sync'])]
private ?string $timezone = null;
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
#[IdGroups(['Sync'])]
private ?User $defaultReferralTrainer = null;
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
private bool $showPositioningTestResults = false;
#[ORM\Column(type: 'simple_array', nullable: false, options: ['default' => '1,2,3,4,5'])]
#[Assert\NotBlank]
#[Serial\Groups(['Sync'])]
private array $planningDays = [1, 2, 3, 4, 5];
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
#[Serial\Groups(['Sync'])]
private bool $enabledConference = false;
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
private bool $enabledPartnerApiIndex = false;
#[ORM\ManyToOne(targetEntity: User::class, fetch: 'EAGER')]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?User $commercialUser = null;
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
#[Serial\Groups(['Sync'])]
private bool $enabledConferenceByDefaultOnEvents = false;
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
#[Serial\Groups(['Sync'])]
private bool $enabledSigningModalityEvents = false;
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
#[Serial\Groups(['Sync'])]
private bool $askForReferentCorrection = false;
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
#[Serial\Groups(['Sync'])]
private bool $enableCustomTimeOnPracticalCase = false;
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
#[Serial\Groups(['Sync'])]
private bool $enableBunnyStream = false;
#[ORM\Column(type: 'string', nullable: true)]
private ?string $zapierWebhookUrl = null;
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
#[Serial\Groups(['Sync'])]
private bool $enabledCrm = false;
/** @var Collection<int, Service> */
#[ORM\ManyToMany(targetEntity: Service::class)]
#[ORM\JoinTable(name: 'channel_configuration_dsf_services')]
#[IdGroups(['Sync'])]
private Collection $dsfServicesToNotify;
public function __construct()
{
$this->dsfServicesToNotify = new ArrayCollection();
}
public static function getSyncKey(): string
{
return EntityKeys::CHANNEL_CONFIGURATION;
}
public function getSyncDisplayLabel(): string
{
return $this->getChannel() . ' - configuration';
}
public function getShowPositioningTestResults(): bool
{
return $this->showPositioningTestResults;
}
public function setShowPositioningTestResults(bool $showPositioningTestResults): static
{
$this->showPositioningTestResults = $showPositioningTestResults;
return $this;
}
public function toggleEnabledConference(): static
{
$this->enabledConference = !$this->enabledConference;
return $this;
}
public function isEnabledPartnerApiIndex(): bool
{
return $this->enabledPartnerApiIndex;
}
public function setEnabledPartnerApiIndex(bool $enabledPartnerApiIndex): static
{
$this->enabledPartnerApiIndex = $enabledPartnerApiIndex;
return $this;
}
public function toggleEnabledPartnerApiIndex(): static
{
$this->enabledPartnerApiIndex = !$this->enabledPartnerApiIndex;
return $this;
}
public function getCommercialUser(): ?User
{
return $this->commercialUser;
}
public function setCommercialUser(?User $commercialUser): ChannelConfiguration
{
$this->commercialUser = $commercialUser;
return $this;
}
public function getZapierWebhookUrl(): ?string
{
return $this->zapierWebhookUrl;
}
public function setZapierWebhookUrl(?string $zapierWebhookUrl): ChannelConfiguration
{
$this->zapierWebhookUrl = $zapierWebhookUrl;
return $this;
}
public function toggleEnabledCrm(): static
{
$this->enabledCrm = !$this->enabledCrm;
return $this;
}
public function isEnableCustomTimeOnPracticalCase(): bool
{
return $this->enableCustomTimeOnPracticalCase;
}
public function setEnableCustomTimeOnPracticalCase(bool $enableCustomTimeOnPracticalCase): static
{
$this->enableCustomTimeOnPracticalCase = $enableCustomTimeOnPracticalCase;
return $this;
}
/** @return Collection<int, Service> */
public function getDsfServicesToNotify(): Collection
{
return $this->dsfServicesToNotify ?? new ArrayCollection();
}
public function addDsfServicesToNotify(Service $service): static
{
if (!$this->dsfServicesToNotify->contains($service)) {
$this->dsfServicesToNotify->add($service);
}
return $this;
}
public function removeDsfServicesToNotify(Service $service): static
{
$this->dsfServicesToNotify->removeElement($service);
return $this;
}
}