src/Entity/Account/User.php line 50

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Account;
  3. use App\Entity\Channel\Channel;
  4. use App\Entity\Channel\Group;
  5. use App\Entity\Channel\Service;
  6. use App\Entity\Channel\UserFromChannel;
  7. use App\Entity\ChannelUserData\ChannelUserData;
  8. use App\Entity\Common\Address;
  9. use App\Entity\Common\Contact;
  10. use App\Entity\Common\ImportableData\ImportableDataInterface;
  11. use App\Entity\Common\ImportableData\ImportableDataTrait;
  12. use App\Entity\Sync\SyncableWithExcludedPropertiesInterface;
  13. use App\Repository\Account\UserRepository;
  14. use Doctrine\Common\Collections\ArrayCollection;
  15. use Doctrine\Common\Collections\Collection;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
  18. use DrosalysWeb\ObjectExtensions\Blame\Model\BlameInterface;
  19. use DrosalysWeb\ObjectExtensions\Blame\Model\BlameTrait;
  20. use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampInterface;
  21. use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampTrait;
  22. use Nellapp\Bundle\SDKBundle\Auth\Entity\UserInterface;
  23. use Nellapp\Bundle\SDKBundle\Auth\Entity\UserMethodTrait;
  24. use Nellapp\Bundle\SDKBundle\Auth\Entity\UserWithContact\UserWithContactInterface;
  25. use Nellapp\Bundle\SDKBundle\Auth\Entity\UserWithContact\UserWithContactTrait;
  26. use Nellapp\Bundle\SDKBundle\Sync\EntityKeys;
  27. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  28. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  29. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  30. use Symfony\Component\Serializer\Annotation as Serial;
  31. use Symfony\Component\Validator\Constraints as Assert;
  32. /**
  33.  * @method self|null    getCreatedBy()
  34.  * @method self         setCreatedBy(self $createdBy)
  35.  * @method self|null    getUpdatedBy()
  36.  * @method self         setUpdatedBy(self $updatedBy)
  37.  */
  38. #[UniqueEntity(fields'email'message'user.entity.email.UniqueEntity'groups: ['register''user_edition''super_admin_user_edition''admin_user_edition''flow_channel_user_create_step1''admin_learner_profile''admin_admin_profile'])]
  39. #[UniqueEntity(fields'id'message'user.entity.id.UniqueEntity'groups: ['register''flow_channel_user_create_step1'])]
  40. #[
  41.     ORM\Entity(repositoryClassUserRepository::class),
  42.     ORM\Table(name'account_users'),
  43.     ORM\Index(fields: ['email'], flags: ['fulltext']),
  44.     ORM\Index(fields: ['firstName'], flags: ['fulltext']),
  45.     ORM\Index(fields: ['lastName'], flags: ['fulltext']),
  46. ]
  47. class User implements 
  48.     UserInterface
  49.     UserWithContactInterface
  50.     PasswordAuthenticatedUserInterface
  51.     TimestampInterface
  52.     BlameInterface
  53.     SyncableWithExcludedPropertiesInterface
  54.     ImportableDataInterface
  55. {
  56.     use BlameTrait;
  57.     use TimestampTrait;
  58.     use UserMethodTrait;
  59.     use UserWithContactTrait;
  60.     use ImportableDataTrait;
  61.     #[
  62.         ORM\IdORM\GeneratedValue(strategy'CUSTOM'),
  63.         ORM\CustomIdGenerator(class: UuidGenerator::class),
  64.         ORM\Column(type'string'length36)
  65.     ]
  66.     #[Serial\Groups(['Profile''Manager''Sync''GlobalJSVariable''activity:get'])]
  67.     private ?string $id null;
  68.     #[ORM\Column(type'string'length180uniquetrue)]
  69.     #[
  70.         Assert\NotBlank(message'user.entity.email.NotBlank'groups: ['register''user_edition''admin_user_edition''super_admin_user_edition''group_user''flow_channel_user_create_step1''admin_learner_profile''admin_admin_profile']),
  71.         Assert\Email(message'user.entity.email.Email'mode'strict'groups: ['register''user_edition''admin_user_edition''super_admin_user_edition''group_user''flow_channel_user_create_step1''admin_learner_profile''admin_admin_profile']),
  72.         Assert\Length(
  73.             min6,
  74.             max64,
  75.             minMessage'user.entity.email.Length.min',
  76.             maxMessage'user.entity.email.Length.max',
  77.             groups: ['register''user_edition''admin_user_edition''super_admin_user_edition''group_user''flow_channel_user_create_step1''admin_learner_profile''admin_admin_profile']),
  78.     ]
  79.     #[Serial\Groups(['Profile''Manager''UserPostManager''Sync''activity:get'])]
  80.     private ?string $email null;
  81.     /**
  82.      * @var string[]
  83.      */
  84.     #[ORM\Column(type'json')]
  85.     #[Serial\Groups(['Profile''Sync'])]
  86.     private array $roles = [];
  87.     #[ORM\Column(type'string')]
  88.     #[
  89.         Assert\NotBlank(message'user.entity.password.NotBlank'groups: ['register''user_edition']),
  90.         Assert\Length(
  91.             min8,
  92.             max255,
  93.             minMessage'user.entity.password.Length.min',
  94.             maxMessage'user.entity.password.Length.max',
  95.             groups: ['register''user_edition']),
  96.         Assert\Regex(
  97.             pattern'/(?=.*[0-9])/',
  98.             message'user.entity.password.Regex.digit',
  99.             groups: ['register''user_edition']),
  100.         Assert\Regex(
  101.             pattern'/(?=.*[A-Z])/',
  102.             message'user.entity.password.Regex.up',
  103.             groups: ['register''user_edition']),
  104.         Assert\Regex(
  105.             pattern'/(?=.*[a-z])/',
  106.             message'user.entity.password.Regex.low',
  107.             groups: ['register''user_edition']),
  108.     ]
  109.     private ?string $password null;
  110.     #[ORM\Column(type'boolean')]
  111.     #[
  112.         Assert\NotNull(message'user.entity.enabled.NotNull'),
  113.         Assert\Type(type'boolean'message'user.entity.enabled.Type')
  114.     ]
  115.     private bool $enabled true;
  116.     #[ORM\Column(type'string'length63nullabletrue)]
  117.     private ?string $passwordToken null;
  118.     #[ORM\Column(type'datetime'nullabletrue)]
  119.     private ?\DateTimeInterface $passwordTokenAt null;
  120.     #[ORM\Column(type'string'nullabletrue)]
  121.     #[
  122.         Assert\NotBlank(message'user.entity.firstName.NotBlank'groups: ['register''user_edition''admin_user_edition''super_admin_user_edition''group_user''flow_channel_user_create_step2''admin_learner_profile''admin_admin_profile']),
  123.         Assert\Length(
  124.             min2,
  125.             max255,
  126.             minMessage'user.entity.firstName.Length.min',
  127.             maxMessage'user.entity.firstName.Length.max',
  128.             groups: ['register''user_edition''admin_user_edition''super_admin_user_edition''group_user''flow_channel_user_create_step2''admin_learner_profile''admin_admin_profile'])
  129.     ]
  130.     #[Serial\Groups(['Profile''Manager''UserPostManager''Sync''GlobalJSVariable''activity:get'])]
  131.     private ?string $firstName null;
  132.     #[ORM\Column(type'string'nullabletrue)]
  133.     #[
  134.         Assert\NotBlank(message'user.entity.lastName.NotBlank'groups: ['register''user_edition''admin_user_edition''super_admin_user_edition''group_user''flow_channel_user_create_step2''admin_learner_profile''admin_admin_profile']),
  135.         Assert\Length(
  136.             min2,
  137.             max255,
  138.             minMessage'user.entity.lastName.Length.min',
  139.             maxMessage'user.entity.lastName.Length.max',
  140.             groups: ['register''user_edition''admin_user_edition''super_admin_user_edition''group_user''flow_channel_user_create_step2''admin_learner_profile''admin_admin_profile'])
  141.     ]
  142.     #[Serial\Groups(['Profile''Manager''UserPostManager''Sync''GlobalJSVariable''activity:get'])]
  143.     private ?string $lastName null;
  144.     #[ORM\Column(type'string'length20nullabletrue)]
  145.     #[Assert\Length(
  146.         min8,
  147.         max20,
  148.         minMessage'user.entity.phone.Length.min',
  149.         maxMessage'user.entity.phone.Length.max',
  150.         groups: ['user_edition''admin_user_edition''super_admin_user_edition''flow_channel_user_create_step2''admin_learner_profile''admin_admin_profile'])
  151.     ]
  152.     private ?string $phoneNumber null;
  153.     #[ORM\Column(type'text'nullabletrue)]
  154.     #[Serial\Groups(['Profile''Sync'])]
  155.     private ?string $description null;
  156.     #[ORM\Column(type'string'nullabletrue)]
  157.     #[Assert\Length(max255groups: ['user_edition'])]
  158.     private ?string $roleDescription null;
  159.     #[ORM\Column(type'boolean'nullabletrue)]
  160.     private ?bool $avatar null;
  161.     #[ORM\Column(type'text'nullabletrue)]
  162.     #[Serial\Groups(['Sync''Manager''GlobalJSVariable''activity:get'])]
  163.     private ?string $avatarPath null;
  164.     #[ORM\Column(type'string'length2nullabletrue)]
  165.     #[Assert\Choice(choices: ['m''f''o'], message'user.entity.gender.Choice'groups: ['user_edition''admin_user_edition''super_admin_user_edition''admin_learner_profile''admin_admin_profile'])]
  166.     private ?string $gender null;
  167.     #[ORM\Column(type'date'nullabletrue)]
  168.     private ?\DateTimeInterface $birthAt null;
  169.     #[ORM\Embedded(class: Address::class)]
  170.     #[Assert\Valid(groups: ['user_edition''flow_channel_user_create_step2''admin_learner_profile''admin_admin_profile'])]
  171.     private ?Address $address null;
  172.     #[ORM\Column(type'boolean')]
  173.     private bool $isVerified false;
  174.     #[ORM\OneToOne(mappedBy'user'targetEntityUserFromChannel::class, cascade: ['remove'], orphanRemovaltrue)]
  175.     private ?UserFromChannel $userFromChannel null;
  176.     #[ORM\OneToOne(inversedBy'user'targetEntityContact::class, cascade: ['persist'])]
  177.     #[ORM\JoinColumn(nullabletrueonDelete'SET NULL')]
  178.     #[IdGroups(['Sync'])]
  179.     private ?Contact $contact null;
  180.     #[ORM\Column(type'datetime'nullabletrue)]
  181.     #[Serial\Groups(['Profile''Sync''UserPutSigningDate'])]
  182.     private ?\DateTime $signingLimitDate null;
  183.     #[ORM\Column(type'datetime'nullabletrue)]
  184.     private ?\DateTime $lastConnectedAt null;
  185.     #[ORM\Column(type'boolean'nullablefalse)]
  186.     private bool $shownAlert false// Modal alert displayed for general informations
  187.     #[ORM\OneToMany(mappedBy'user'targetEntityChannelUserData::class)]
  188.     private ?Collection $channelUserDatas;
  189.     #[ORM\ManyToMany(targetEntityGroup::class, mappedBy'users'fetch'EXTRA_LAZY')]
  190.     private ?Collection $groups;
  191.     #[ORM\ManyToMany(targetEntityService::class, mappedBy'users'fetch'EXTRA_LAZY')]
  192.     private ?Collection $services;
  193.     public function __construct()
  194.     {
  195.         $this->channelUserDatas = new ArrayCollection();
  196.         $this->groups = new ArrayCollection();
  197.         $this->services = new ArrayCollection();
  198.     }
  199.     public function getId(): ?string
  200.     {
  201.         return $this->id;
  202.     }
  203.     public static function getSyncKey(): string
  204.     {
  205.         return EntityKeys::USER;
  206.     }
  207.     public function getSyncDisplayLabel(): string
  208.     {
  209.         return $this->getEmail() ?? 'Email';
  210.     }
  211.     public static function getExcludedProperties(): array
  212.     {
  213.         return [
  214.             'lastConnectedAt',
  215.         ];
  216.     }
  217.     #[
  218.         Serial\SerializedName('username'),
  219.         Serial\Groups(['Profile''Manager''Sync'])
  220.     ]
  221.     public function getUsername(): string
  222.     {
  223.         return $this;
  224.     }
  225.     #[
  226.         Serial\Groups(['Profile'])
  227.     ]
  228.     public function getChannelIds(): array
  229.     {
  230.         return $this->getChannelUserDatas()->map(fn(ChannelUserData $cud) => $cud->getChannel()->getId())->toArray();
  231.     }
  232.     public function getRoles(): array
  233.     {
  234.         return array_unique(array_merge($this->roles, [
  235.             'ROLE_USER',
  236.         ]));
  237.     }
  238.     public function setRoles(array $roles): static
  239.     {
  240.         $this->roles array_unique(array_values($roles));
  241.         return $this;
  242.     }
  243.     public function getPassword(): ?string
  244.     {
  245.         return $this->password;
  246.     }
  247.     public function setPassword(string $password): static
  248.     {
  249.         $this->password $password;
  250.         return $this;
  251.     }
  252.     public function getEnabled(): ?bool
  253.     {
  254.         return $this->enabled;
  255.     }
  256.     public function setEnabled(bool $enabled): static
  257.     {
  258.         $this->enabled $enabled;
  259.         return $this;
  260.     }
  261.     public function toggleEnabled(): static
  262.     {
  263.         $this->enabled = !$this->enabled;
  264.         return $this;
  265.     }
  266.     public function getPasswordToken(): ?string
  267.     {
  268.         return $this->passwordToken;
  269.     }
  270.     public function setPasswordToken(?string $passwordToken): static
  271.     {
  272.         $this->passwordToken $passwordToken;
  273.         return $this;
  274.     }
  275.     public function getPasswordTokenAt(): ?\DateTimeInterface
  276.     {
  277.         return $this->passwordTokenAt;
  278.     }
  279.     public function setPasswordTokenAt(?\DateTimeInterface $passwordTokenAt): static
  280.     {
  281.         $this->passwordTokenAt $passwordTokenAt;
  282.         return $this;
  283.     }
  284.     public function getPhoneNumber(): ?string
  285.     {
  286.         return $this->phoneNumber;
  287.     }
  288.     public function setPhoneNumber(?string $phoneNumber): static
  289.     {
  290.         $this->phoneNumber $phoneNumber;
  291.         return $this;
  292.     }
  293.     public function getRoleDescription(): ?string
  294.     {
  295.         return $this->roleDescription;
  296.     }
  297.     public function setRoleDescription(?string $roleDescription): static
  298.     {
  299.         $this->roleDescription $roleDescription;
  300.         return $this;
  301.     }
  302.     public function getGender(): ?string
  303.     {
  304.         return $this->gender;
  305.     }
  306.     public function setGender(?string $gender): static
  307.     {
  308.         $this->gender $gender;
  309.         return $this;
  310.     }
  311.     public function getBirthAt(): ?\DateTimeInterface
  312.     {
  313.         return $this->birthAt;
  314.     }
  315.     public function setBirthAt(?\DateTimeInterface $birthAt): static
  316.     {
  317.         $this->birthAt $birthAt;
  318.         return $this;
  319.     }
  320.     /**
  321.      * @return \DateTime|null
  322.      */
  323.     public function getLastConnectedAt(): ?\DateTime
  324.     {
  325.         return $this->lastConnectedAt;
  326.     }
  327.     /**
  328.      * @param \DateTime|null $lastConnectedAt
  329.      */
  330.     public function setLastConnectedAt(?\DateTime $lastConnectedAt): static
  331.     {
  332.         $this->lastConnectedAt $lastConnectedAt;
  333.         return $this;
  334.     }
  335.     public function getAddress(): Address
  336.     {
  337.         return $this->address ?: $this->address = new Address();
  338.     }
  339.     public function setAddress(Address $address): static
  340.     {
  341.         $this->address $address;
  342.         return $this;
  343.     }
  344.     public function isVerified(): bool
  345.     {
  346.         return $this->isVerified;
  347.     }
  348.     public function setIsVerified(bool $isVerified): static
  349.     {
  350.         $this->isVerified $isVerified;
  351.         return $this;
  352.     }
  353.     public function getGroups(): ?Collection
  354.     {
  355.         return $this->groups;
  356.     }
  357.     public function getGroupsByChannel(Channel $channel): ?array
  358.     {
  359.         return array_filter($this->groups->toArray(), function (Group $group) use ($channel) {
  360.             return $group->getChannel() === $channel;
  361.         });
  362.     }
  363.     public function setGroups(?Collection $groups): User
  364.     {
  365.         $this->groups $groups;
  366.         return $this;
  367.     }
  368.     public function getServices(): ?Collection
  369.     {
  370.         return $this->services;
  371.     }
  372.     public function getUserFromChannel(): ?UserFromChannel
  373.     {
  374.         return $this->userFromChannel;
  375.     }
  376.     public function setUserFromChannel(?UserFromChannel $userFromChannel): self
  377.     {
  378.         $this->userFromChannel $userFromChannel;
  379.         return $this;
  380.     }
  381.     public function isShownAlert(): bool
  382.     {
  383.         return $this->shownAlert;
  384.     }
  385.     public function setShownAlert(bool $shownAlert): User
  386.     {
  387.         $this->shownAlert $shownAlert;
  388.         return $this;
  389.     }
  390.     public function serialize(): ?string
  391.     {
  392.         return serialize([
  393.             $this->id,
  394.             $this->email,
  395.             $this->password,
  396.             $this->enabled,
  397.         ]);
  398.     }
  399.     public function unserialize($data): void
  400.     {
  401.         list(
  402.             $this->id,
  403.             $this->email,
  404.             $this->password,
  405.             $this->enabled
  406.             ) = unserialize($data);
  407.     }
  408. }