src/Entity/ChannelUserData/ChannelUserData.php line 37

Open in your IDE?
  1. <?php
  2. namespace App\Entity\ChannelUserData;
  3. use App\Entity\Account\User;
  4. use App\Entity\Channel\Channel;
  5. use App\Entity\Channel\PositioningTest\Attempt\Attempt;
  6. use App\Entity\ChannelUserData\Cursus\AbstractCursus;
  7. use App\Entity\Common\ImportableData\ImportableDataInterface;
  8. use App\Entity\Common\ImportableData\ImportableDataTrait;
  9. use App\Entity\Sync\SyncableInterface;
  10. use App\Repository\ChannelUserData\ChannelUserDataRepository;
  11. use DateTimeInterface;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
  16. use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelInterface;
  17. use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelUserData\ChannelUserDataInterface;
  18. use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelUserData\ChannelUserDataMethodTrait;
  19. use Nellapp\Bundle\SDKBundle\Enum\ChannelUserData\RqthStatusEnum;
  20. use Nellapp\Bundle\SDKBundle\Permission\Entity\ChannelResourceInterface;
  21. use Nellapp\Bundle\SDKBundle\Permission\UserOwner\UserOwnerResourceInterface;
  22. use Nellapp\Bundle\SDKBundle\Sync\EntityKeys;
  23. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  24. use Symfony\Component\Serializer\Annotation as Serial;
  25. use Symfony\Component\Validator\Constraints as Assert;
  26. #[
  27.     ORM\Entity(repositoryClassChannelUserDataRepository::class),
  28.     ORM\Table(name'channel_user_data'),
  29.     ORM\UniqueConstraint(fields: ['user''channel']),
  30.     ORM\InheritanceType('JOINED'),
  31.     ORM\DiscriminatorColumn(name'type'type'string'),
  32.     ORM\DiscriminatorMap(['learnerType' => ChannelUserData::class, 'adminType' => AdminChannelUserData::class]),
  33. ]
  34. class ChannelUserData implements ChannelUserDataInterfaceSyncableInterfaceChannelResourceInterfaceImportableDataInterfaceUserOwnerResourceInterface
  35. {
  36.     use ImportableDataTrait;
  37.     use ChannelUserDataMethodTrait;
  38.     #[
  39.         ORM\IdORM\GeneratedValue(strategy'CUSTOM'),
  40.         ORM\CustomIdGenerator(class: UuidGenerator::class),
  41.         ORM\Column(type'string'length36)
  42.     ]
  43.     #[Serial\Groups(['Sync''Manager''GlobalJSVariable'])]
  44.     private ?string $id null;
  45.     #[ORM\ManyToOne(targetEntityUser::class, cascade: ['persist'], inversedBy'channelUserDatas')]
  46.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  47.     #[Assert\Valid(groups: ['Default''admin_learner_profile''admin_admin_profile'])]
  48.     #[Serial\Groups(['Manager'])]
  49.     #[IdGroups(['Sync'])]
  50.     private ?User $user null;
  51.     #[ORM\ManyToOne(targetEntityChannel::class)]
  52.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  53.     #[IdGroups(['Sync'])]
  54.     private ?Channel $channel null;
  55.     #[ORM\Column(type'boolean'nullablefalseoptions: ['default' => true])]
  56.     #[Assert\NotBlank(groups: ['flow_channel_user_create_step3'])]
  57.     #[Serial\Groups(['Sync'])]
  58.     private ?bool $isLearner null;
  59.     #[ORM\Column(type'boolean'nullablefalseoptions: ['default' => true])]
  60.     #[Serial\Groups(['Sync'])]
  61.     private ?bool $isActive true;
  62.     #[ORM\Column(type'string'length255nullabletrue)]
  63.     #[Assert\Length(max255maxMessage'channel_user_data.birthName.Length.maxMessage'groups: ['Default''admin_learner_profile''admin_admin_profile'])]
  64.     private ?string $birthName null;
  65.     #[ORM\Column(type'date'nullabletrue)]
  66.     private ?DateTimeInterface $birthAt null;
  67.     #[ORM\OneToMany(mappedBy'channelUserData'targetEntityAbstractCursus::class, cascade: ['remove'], fetch'LAZY'orphanRemovaltrue)]
  68.     private Collection $cursuses;
  69.     #[ORM\OneToMany(mappedBy'channelUserData'targetEntityAttempt::class, fetch'LAZY')]
  70.     private ?Collection $positioningTestAttempts;
  71.     #[ORM\Column(type'string'length15nullabletrue)]
  72.     #[
  73.         Assert\Length(min4max15minMessage'common.address.postCode.Length.min'maxMessage'common.address.postCode.Length.max'groups: ['Default''admin_learner_profile''admin_admin_profile']),
  74.         Assert\Regex(pattern'/^\d{4,15}$/'message'common.address.postCode.Regex'groups: ['Default''admin_learner_profile''admin_admin_profile'])
  75.     ]
  76.     private ?string $birthPostalCode null;
  77.     #[ORM\Column(type'string'nullabletrue)]
  78.     #[Assert\Length(min2max255minMessage'common.address.city.Length.min'maxMessage'common.address.city.Length.max'groups: ['Default''admin_learner_profile''admin_admin_profile'])]
  79.     private ?string $birthCity null;
  80.     #[ORM\Column(type'string'length2nullabletrue)]
  81.     #[
  82.         Assert\Length(min2max2exactMessage'common.address.country.Length.exact'),
  83.         Assert\Country(message'common.address.country.Country')
  84.     ]
  85.     private ?string $birthCountry null;
  86.     #[ORM\Column(type'string'length255nullabletrue)]
  87.     #[Assert\Length(max255maxMessage'channel_user_data.nationality.Length.maxMessage'groups: ['Default''admin_learner_profile''admin_admin_profile'])]
  88.     private ?string $nationality null;
  89.     #[ORM\Column(type'integer'nullabletrue)]
  90.     #[Assert\Choice(callback: [RqthStatusEnum::class, 'getChoices'])]
  91.     private ?int $rqth null;
  92.     #[ORM\Column(type'string'length255nullabletrue)]
  93.     #[Assert\Length(max255maxMessage'channel_user_data.rqthDetails.Length.maxMessage'groups: ['Default''admin_learner_profile'])]
  94.     private ?string $rqthDetails null;
  95.     #[ORM\Column(type'string'length255nullabletrue)]
  96.     private ?string $lastWorkQualificationDetails null;
  97.     #[ORM\Column(type'integer'nullabletrue)]
  98.     private ?int $lastWorkQualification null;
  99.     #[ORM\Column(type'integer'nullabletrue)]
  100.     private ?int $lastWorkStatus null;
  101.     #[ORM\Column(type'integer'nullabletrue)]
  102.     private ?int $scholarLevel null;
  103.     #[ORM\Column(type'integer'nullabletrue)]
  104.     private ?int $scholarDiploma null;
  105.     #[ORM\Column(type'string'nullabletrue)]
  106.     #[Assert\Length(max255maxMessage'channel_user_data.scholarDiplomaOther.Length.maxMessage')]
  107.     private ?string $scholarDiplomaOther null;
  108.     public function __construct()
  109.     {
  110.         $this->cursuses = new ArrayCollection();
  111.         $this->positioningTestAttempts = new ArrayCollection();
  112.     }
  113.     public static function getSyncKey(): string
  114.     {
  115.         return EntityKeys::CHANNEL_USER_DATA;
  116.     }
  117.     public function getSyncDisplayLabel(): string
  118.     {
  119.         return $this->getUser();
  120.     }
  121.     public function isLearner(): ?bool
  122.     {
  123.         return !$this instanceof AdminChannelUserData;
  124.     }
  125.     public function getBirthName(): ?string
  126.     {
  127.         return $this->birthName;
  128.     }
  129.     public function setBirthName(?string $birthName): self
  130.     {
  131.         $this->birthName $birthName;
  132.         return $this;
  133.     }
  134.     public function getBirthAt(): ?DateTimeInterface
  135.     {
  136.         return $this->birthAt;
  137.     }
  138.     public function setBirthAt(?DateTimeInterface $birthAt): self
  139.     {
  140.         $this->birthAt $birthAt;
  141.         return $this;
  142.     }
  143.     public function getNationality(): ?string
  144.     {
  145.         return $this->nationality;
  146.     }
  147.     public function setNationality(?string $nationality): self
  148.     {
  149.         $this->nationality $nationality;
  150.         return $this;
  151.     }
  152.     public function getRqth(): ?int
  153.     {
  154.         return $this->rqth;
  155.     }
  156.     public function setRqth(?int $rqth): self
  157.     {
  158.         $this->rqth $rqth;
  159.         return $this;
  160.     }
  161.     public function getRqthDetails(): ?string
  162.     {
  163.         return $this->rqthDetails;
  164.     }
  165.     public function setRqthDetails(?string $rqthDetails): self
  166.     {
  167.         $this->rqthDetails $rqthDetails;
  168.         return $this;
  169.     }
  170.     public function getLastWorkQualificationDetails(): ?string
  171.     {
  172.         return $this->lastWorkQualificationDetails;
  173.     }
  174.     public function setLastWorkQualificationDetails(?string $lastWorkQualificationDetails): self
  175.     {
  176.         $this->lastWorkQualificationDetails $lastWorkQualificationDetails;
  177.         return $this;
  178.     }
  179.     public function getLastWorkQualification(): ?int
  180.     {
  181.         return $this->lastWorkQualification;
  182.     }
  183.     public function setLastWorkQualification(?int $lastWorkQualification): ChannelUserData
  184.     {
  185.         $this->lastWorkQualification $lastWorkQualification;
  186.         return $this;
  187.     }
  188.     public function getLastWorkStatus(): ?int
  189.     {
  190.         return $this->lastWorkStatus;
  191.     }
  192.     public function setLastWorkStatus(?int $lastWorkStatus): ChannelUserData
  193.     {
  194.         $this->lastWorkStatus $lastWorkStatus;
  195.         return $this;
  196.     }
  197.     public function getScholarLevel(): ?int
  198.     {
  199.         return $this->scholarLevel;
  200.     }
  201.     public function setScholarLevel(?int $scholarLevel): ChannelUserData
  202.     {
  203.         $this->scholarLevel $scholarLevel;
  204.         return $this;
  205.     }
  206.     public function getScholarDiploma(): ?int
  207.     {
  208.         return $this->scholarDiploma;
  209.     }
  210.     public function setScholarDiploma(?int $scholarDiploma): ChannelUserData
  211.     {
  212.         $this->scholarDiploma $scholarDiploma;
  213.         return $this;
  214.     }
  215.     public function getBirthPostalCode(): ?string
  216.     {
  217.         return $this->birthPostalCode;
  218.     }
  219.     public function setBirthPostalCode(?string $birthPostalCode): ChannelUserData
  220.     {
  221.         $this->birthPostalCode $birthPostalCode;
  222.         return $this;
  223.     }
  224.     public function getBirthCity(): ?string
  225.     {
  226.         return $this->birthCity;
  227.     }
  228.     public function setBirthCity(?string $birthCity): ChannelUserData
  229.     {
  230.         $this->birthCity $birthCity;
  231.         return $this;
  232.     }
  233.     public function getBirthCountry(): ?string
  234.     {
  235.         return $this->birthCountry;
  236.     }
  237.     public function setBirthCountry(?string $birthCountry): ChannelUserData
  238.     {
  239.         $this->birthCountry $birthCountry;
  240.         return $this;
  241.     }
  242.     public function getCursuses(): Collection
  243.     {
  244.         return $this->cursuses;
  245.     }
  246.     public function setCursuses(Collection $cursuses): ChannelUserData
  247.     {
  248.         $this->cursuses $cursuses;
  249.         return $this;
  250.     }
  251.     public function getPositioningTestAttempts(): ?Collection
  252.     {
  253.         return $this->positioningTestAttempts;
  254.     }
  255.     public function addPositioningTestAttempt(Attempt $positioningTestAttempt): self
  256.     {
  257.         if (!$this->positioningTestAttempts->contains($positioningTestAttempt)) {
  258.             $positioningTestAttempt->setChannelUserData($this);
  259.             $this->positioningTestAttempts[] = $positioningTestAttempt;
  260.         }
  261.         return $this;
  262.     }
  263.     public function removePositioningTestAttempt(Attempt $positioningTestAttempt): self
  264.     {
  265.         if ($this->positioningTestAttempts->contains($positioningTestAttempt)) {
  266.             $positioningTestAttempt->setChannelUserData(null);
  267.             $this->positioningTestAttempts->removeElement($positioningTestAttempt);
  268.         }
  269.         return $this;
  270.     }
  271.     public function getScholarDiplomaOther(): ?string
  272.     {
  273.         return $this->scholarDiplomaOther;
  274.     }
  275.     public function setScholarDiplomaOther(?string $scholarDiplomaOther): ChannelUserData
  276.     {
  277.         $this->scholarDiplomaOther $scholarDiplomaOther;
  278.         return $this;
  279.     }
  280.     public function toggleIsActive(): void
  281.     {
  282.         $this->isActive = !$this->isActive;
  283.     }
  284.     public static function getPermissionResourceClass(): ?string
  285.     {
  286.         return null;
  287.     }
  288.     public function getOwnerChannel(): ?ChannelInterface
  289.     {
  290.         return $this->getChannel();
  291.     }
  292.     public function __toString()
  293.     {
  294.         return $this->getUser();
  295.     }
  296.     public function getUserOwners(): array
  297.     {
  298.         return $this->getUser() !== null ? [$this->getUser()] : [];
  299.     }
  300. }