src/Entity/ChannelUserData/ChannelUserData.php line 39

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