<?php
namespace App\Entity\ChannelUserData;
use App\Entity\Account\User;
use App\Entity\Channel\Channel;
use App\Entity\Channel\PositioningTest\Attempt\Attempt;
use App\Entity\ChannelUserData\Cursus\AbstractCursus;
use App\Entity\Common\ImportableData\ImportableDataInterface;
use App\Entity\Common\ImportableData\ImportableDataTrait;
use App\Entity\Sync\SyncableInterface;
use App\Repository\ChannelUserData\ChannelUserDataRepository;
use DateTimeInterface;
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\ChannelInterface;
use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelUserData\ChannelUserDataInterface;
use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelUserData\ChannelUserDataMethodTrait;
use Nellapp\Bundle\SDKBundle\Enum\ChannelUserData\RqthStatusEnum;
use Nellapp\Bundle\SDKBundle\Permission\Entity\ChannelResourceInterface;
use Nellapp\Bundle\SDKBundle\Permission\UserOwner\UserOwnerResourceInterface;
use Nellapp\Bundle\SDKBundle\Sync\EntityKeys;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
use Symfony\Component\Serializer\Annotation as Serial;
use Symfony\Component\Validator\Constraints as Assert;
#[
ORM\Entity(repositoryClass: ChannelUserDataRepository::class),
ORM\Table(name: 'channel_user_data'),
ORM\UniqueConstraint(fields: ['user', 'channel']),
ORM\InheritanceType('JOINED'),
ORM\DiscriminatorColumn(name: 'type', type: 'string'),
ORM\DiscriminatorMap(['learnerType' => ChannelUserData::class, 'adminType' => AdminChannelUserData::class]),
]
class ChannelUserData implements ChannelUserDataInterface, SyncableInterface, ChannelResourceInterface, ImportableDataInterface, UserOwnerResourceInterface
{
use ImportableDataTrait;
use ChannelUserDataMethodTrait;
#[
ORM\Id, ORM\GeneratedValue(strategy: 'CUSTOM'),
ORM\CustomIdGenerator(class: UuidGenerator::class),
ORM\Column(type: 'string', length: 36)
]
#[Serial\Groups(['Sync', 'Manager', 'GlobalJSVariable'])]
private ?string $id = null;
#[ORM\ManyToOne(targetEntity: User::class, cascade: ['persist'], inversedBy: 'channelUserDatas')]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
#[Assert\Valid(groups: ['Default', 'admin_learner_profile', 'admin_admin_profile'])]
#[Serial\Groups(['Manager'])]
#[IdGroups(['Sync'])]
private ?User $user = null;
#[ORM\ManyToOne(targetEntity: Channel::class)]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
#[IdGroups(['Sync'])]
private ?Channel $channel = null;
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => true])]
#[Assert\NotBlank(groups: ['flow_channel_user_create_step3'])]
#[Serial\Groups(['Sync'])]
private ?bool $isLearner = null;
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => true])]
#[Serial\Groups(['Sync'])]
private ?bool $isActive = true;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Assert\Length(max: 255, maxMessage: 'channel_user_data.birthName.Length.maxMessage', groups: ['Default', 'admin_learner_profile', 'admin_admin_profile'])]
private ?string $birthName = null;
#[ORM\Column(type: 'date', nullable: true)]
private ?DateTimeInterface $birthAt = null;
#[ORM\OneToMany(mappedBy: 'channelUserData', targetEntity: AbstractCursus::class, cascade: ['remove'], fetch: 'LAZY', orphanRemoval: true)]
private Collection $cursuses;
#[ORM\OneToMany(mappedBy: 'channelUserData', targetEntity: Attempt::class, fetch: 'LAZY')]
private ?Collection $positioningTestAttempts;
#[ORM\Column(type: 'string', length: 15, nullable: true)]
#[
Assert\Length(min: 4, max: 15, minMessage: 'common.address.postCode.Length.min', maxMessage: 'common.address.postCode.Length.max', groups: ['Default', 'admin_learner_profile', 'admin_admin_profile']),
Assert\Regex(pattern: '/^\d{4,15}$/', message: 'common.address.postCode.Regex', groups: ['Default', 'admin_learner_profile', 'admin_admin_profile'])
]
private ?string $birthPostalCode = null;
#[ORM\Column(type: 'string', nullable: true)]
#[Assert\Length(min: 2, max: 255, minMessage: 'common.address.city.Length.min', maxMessage: 'common.address.city.Length.max', groups: ['Default', 'admin_learner_profile', 'admin_admin_profile'])]
private ?string $birthCity = null;
#[ORM\Column(type: 'string', length: 2, nullable: true)]
#[
Assert\Length(min: 2, max: 2, exactMessage: 'common.address.country.Length.exact'),
Assert\Country(message: 'common.address.country.Country')
]
private ?string $birthCountry = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Assert\Length(max: 255, maxMessage: 'channel_user_data.nationality.Length.maxMessage', groups: ['Default', 'admin_learner_profile', 'admin_admin_profile'])]
private ?string $nationality = null;
#[ORM\Column(type: 'integer', nullable: true)]
#[Assert\Choice(callback: [RqthStatusEnum::class, 'getChoices'])]
private ?int $rqth = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[Assert\Length(max: 255, maxMessage: 'channel_user_data.rqthDetails.Length.maxMessage', groups: ['Default', 'admin_learner_profile'])]
private ?string $rqthDetails = null;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $lastWorkQualificationDetails = null;
#[ORM\Column(type: 'integer', nullable: true)]
private ?int $lastWorkQualification = null;
#[ORM\Column(type: 'integer', nullable: true)]
private ?int $lastWorkStatus = null;
#[ORM\Column(type: 'integer', nullable: true)]
private ?int $scholarLevel = null;
#[ORM\Column(type: 'integer', nullable: true)]
private ?int $scholarDiploma = null;
#[ORM\Column(type: 'string', nullable: true)]
#[Assert\Length(max: 255, maxMessage: 'channel_user_data.scholarDiplomaOther.Length.maxMessage')]
private ?string $scholarDiplomaOther = null;
public function __construct()
{
$this->cursuses = new ArrayCollection();
$this->positioningTestAttempts = new ArrayCollection();
}
public static function getSyncKey(): string
{
return EntityKeys::CHANNEL_USER_DATA;
}
public function getSyncDisplayLabel(): string
{
return $this->getUser();
}
public function isLearner(): ?bool
{
return !$this instanceof AdminChannelUserData;
}
public function getBirthName(): ?string
{
return $this->birthName;
}
public function setBirthName(?string $birthName): self
{
$this->birthName = $birthName;
return $this;
}
public function getBirthAt(): ?DateTimeInterface
{
return $this->birthAt;
}
public function setBirthAt(?DateTimeInterface $birthAt): self
{
$this->birthAt = $birthAt;
return $this;
}
public function getNationality(): ?string
{
return $this->nationality;
}
public function setNationality(?string $nationality): self
{
$this->nationality = $nationality;
return $this;
}
public function getRqth(): ?int
{
return $this->rqth;
}
public function setRqth(?int $rqth): self
{
$this->rqth = $rqth;
return $this;
}
public function getRqthDetails(): ?string
{
return $this->rqthDetails;
}
public function setRqthDetails(?string $rqthDetails): self
{
$this->rqthDetails = $rqthDetails;
return $this;
}
public function getLastWorkQualificationDetails(): ?string
{
return $this->lastWorkQualificationDetails;
}
public function setLastWorkQualificationDetails(?string $lastWorkQualificationDetails): self
{
$this->lastWorkQualificationDetails = $lastWorkQualificationDetails;
return $this;
}
public function getLastWorkQualification(): ?int
{
return $this->lastWorkQualification;
}
public function setLastWorkQualification(?int $lastWorkQualification): ChannelUserData
{
$this->lastWorkQualification = $lastWorkQualification;
return $this;
}
public function getLastWorkStatus(): ?int
{
return $this->lastWorkStatus;
}
public function setLastWorkStatus(?int $lastWorkStatus): ChannelUserData
{
$this->lastWorkStatus = $lastWorkStatus;
return $this;
}
public function getScholarLevel(): ?int
{
return $this->scholarLevel;
}
public function setScholarLevel(?int $scholarLevel): ChannelUserData
{
$this->scholarLevel = $scholarLevel;
return $this;
}
public function getScholarDiploma(): ?int
{
return $this->scholarDiploma;
}
public function setScholarDiploma(?int $scholarDiploma): ChannelUserData
{
$this->scholarDiploma = $scholarDiploma;
return $this;
}
public function getBirthPostalCode(): ?string
{
return $this->birthPostalCode;
}
public function setBirthPostalCode(?string $birthPostalCode): ChannelUserData
{
$this->birthPostalCode = $birthPostalCode;
return $this;
}
public function getBirthCity(): ?string
{
return $this->birthCity;
}
public function setBirthCity(?string $birthCity): ChannelUserData
{
$this->birthCity = $birthCity;
return $this;
}
public function getBirthCountry(): ?string
{
return $this->birthCountry;
}
public function setBirthCountry(?string $birthCountry): ChannelUserData
{
$this->birthCountry = $birthCountry;
return $this;
}
public function getCursuses(): Collection
{
return $this->cursuses;
}
public function setCursuses(Collection $cursuses): ChannelUserData
{
$this->cursuses = $cursuses;
return $this;
}
public function getPositioningTestAttempts(): ?Collection
{
return $this->positioningTestAttempts;
}
public function addPositioningTestAttempt(Attempt $positioningTestAttempt): self
{
if (!$this->positioningTestAttempts->contains($positioningTestAttempt)) {
$positioningTestAttempt->setChannelUserData($this);
$this->positioningTestAttempts[] = $positioningTestAttempt;
}
return $this;
}
public function removePositioningTestAttempt(Attempt $positioningTestAttempt): self
{
if ($this->positioningTestAttempts->contains($positioningTestAttempt)) {
$positioningTestAttempt->setChannelUserData(null);
$this->positioningTestAttempts->removeElement($positioningTestAttempt);
}
return $this;
}
public function getScholarDiplomaOther(): ?string
{
return $this->scholarDiplomaOther;
}
public function setScholarDiplomaOther(?string $scholarDiplomaOther): ChannelUserData
{
$this->scholarDiplomaOther = $scholarDiplomaOther;
return $this;
}
public function toggleIsActive(): void
{
$this->isActive = !$this->isActive;
}
public static function getPermissionResourceClass(): ?string
{
return null;
}
public function getOwnerChannel(): ?ChannelInterface
{
return $this->getChannel();
}
public function __toString()
{
return $this->getUser();
}
public function getUserOwners(): array
{
return $this->getUser() !== null ? [$this->getUser()] : [];
}
}