src/Entity/Account/User.php line 46

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