src/Entity/User.php line 24
<?phpnamespace App\Entity;use App\Repository\UserRepository;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;use Symfony\Component\Security\Core\User\EquatableInterface;use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;use Symfony\Component\Security\Core\User\UserInterface;use Symfony\Component\Validator\Constraints as Assert;use Symfony\Component\Validator\Context\ExecutionContextInterface;use App\Entity\UserPenalty;use App\Entity\Centers;#[ORM\Entity(repositoryClass: UserRepository::class)]#[UniqueEntity(fields: ['username'])]#[UniqueEntity(fields: ['email'])]#[UniqueEntity(fields: ['dni'])]class User implements UserInterface, EquatableInterface, PasswordAuthenticatedUserInterface{#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]private ?int $id = null;#[ORM\Column(length: 180, unique: true)]#[Assert\NotBlank(message: 'El nombre de usuario es obligatorio')]private ?string $username = null;#[ORM\Column(type: 'json')]private array $roles = [];#[ORM\Column(length: 50)]#[Assert\NotBlank(message: 'El nombre es obligatorio')]private ?string $nomComplet= null;#[ORM\Column(length: 10, unique: true)]#[Assert\NotBlank(message: 'El DNI/NIE es obligarorio')]private ?string $dni= null;#[ORM\Column(length: 250,nullable: true)]private ?string $address= null;#[ORM\Column(length: 50,nullable: true)]private ?string $phone= null;#[ORM\Column(length: 50,nullable: true)]private ?string $notes= null;#[ORM\Column( length: 100, unique: true)]#[Assert\NotBlank(message: 'El campo correo no puede estar vacÃo')]#[Assert\Email(message: 'Email incorrecto')]private ?string $email= null;#[ORM\Column]private ?bool $valid = null;#[ORM\Column]private ?bool $deleted = null;#[ORM\Column( length: 255)]private ?string $password = null;#[ORM\Column(type: 'boolean')]private ?bool $admin = null;#[ORM\OneToMany(mappedBy: 'userId', targetEntity: Registrations::class, orphanRemoval: true)]private Collection $registrations;#[ORM\OneToMany(mappedBy: 'creatorUserId', targetEntity: Attendance::class)]private Collection $attendances;#[ORM\ManyToMany(targetEntity: Events::class, mappedBy: 'courseUser')]private Collection $events;#[ORM\ManyToMany(targetEntity: Events::class, mappedBy: 'managerUsers')]private Collection $managedEvents;#[ORM\Column(length: 255, nullable: true)]private ?string $surname = null;#[ORM\Column(length: 12, nullable: true)]private ?string $customFilterYear = null;#[ORM\Column(type: 'string', length: 64, nullable: true)]private ?string $activationToken = null;#[ORM\Column(type: 'boolean')]private bool $active = false;#[ORM\ManyToOne(inversedBy: 'managementUsers')]#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]private ?Centers $managementCenter = null;#[ORM\Column(type: 'boolean', options: ['default' => false])]private bool $canManageEventRequestsAndRegistrations = false;public function __construct(){$this->registrations = new ArrayCollection();$this->attendances = new ArrayCollection();$this->events = new ArrayCollection();$this->managedEvents = new ArrayCollection();$this->eventRequests = new ArrayCollection();$this->penalties = new ArrayCollection();}public function getId(): ?int{return $this->id;}/*** A visual identifier that represents this user.** @see UserInterface*/public function getUsername(): string{return (string) $this->username;}public function getUserIdentifier(): string{return (string) $this->username;}public function setUsername($username): self{$this->username = $username;return $this;}/*** @see UserInterface*/public function getRoles(): array{return array_values(array_unique($this->roles));}public function setRoles(array $roles): self{$this->roles = array_values(array_unique($roles));return $this;}/*** @see UserInterface*/public function getPassword(): ?string{return $this->password;}/*** @see UserInterface*/public function eraseCredentials(){// If you store any temporary, sensitive data on the user, clear it here// $this->plainPassword = null;}public function getNomComplet(): ?string{return $this->nomComplet;}public function setNomComplet($nomComplet): self{$this->nomComplet = $nomComplet;return $this;}public function getEmail(): ?string{return $this->email;}public function setEmail($email): self{$this->email = $email;return $this;}public function getPhone(): ?string{return $this->phone;}public function setPhone($phone): self{$this->phone = $phone;return $this;}public function getNotes(): ?string{return $this->notes;}public function setNotes($notes): self{$this->notes = $notes;return $this;}public function getAddress(): ?string{return $this->address;}public function setAddress($address): self{$this->address = $address;return $this;}public function getDni(): ?string{return $this->dni;}public function setDni($dni): self{$this->dni = $dni;return $this;}public function isValid(): ?bool{return $this->valid;}public function setValid(bool $valid): self{$this->valid = $valid;return $this;}public function isDeleted(): ?bool{return $this->deleted;}public function setDeleted(bool $deleted): self{$this->deleted = $deleted;return $this;}public function setPassword($password): self{$this->password = $password;return $this;}public function getAvatarUrl(): string{return "/avatar/".urlencode((string)$this->nomComplet);}public function getColorCode(): string{$code = dechex(crc32($this->getUsername()));$code = substr($code, 0, 6);return '#'.$code;}#[Assert\Callback]public function validate(ExecutionContextInterface $context, $payload){/*if (strlen($this->password)< 3){$context->buildViolation('Mot de passe trop court')->atPath('justpassword')->addViolation();}*/}public function __toString(): string{return "$this->nomComplet ($this->id)";}public function isAdmin(): ?bool{return $this->admin;}public function setAdmin(bool $admin): self{$this->admin = $admin;return $this;}public function isEqualTo(UserInterface $user): bool{if ($user instanceof User) {return $this->isValid() && !$this->isDeleted() && $this->getPassword() == $user->getPassword() && $this->getUsername() == $user->getUsername()&& $this->getEmail() == $user->getEmail();}return false;}/*** @return mixed*/public function getSalt(): ?string{//not used herereturn null;}/*** @return Collection<int, Registrations>*/public function getRegistrations(): Collection{return $this->registrations;}/*** @return Collection<int, Registrations>*/public function getActiveRegistrations(): Collection{return $this->registrations->filter(static function (Registrations $registration): bool {return (bool) $registration->isActive();});}public function addRegistration(Registrations $registration): static{if (!$this->registrations->contains($registration)) {$this->registrations->add($registration);$registration->setUserId($this);}return $this;}public function removeRegistration(Registrations $registration): static{if ($this->registrations->removeElement($registration)) {// set the owning side to null (unless already changed)if ($registration->getUserId() === $this) {$registration->setUserId(null);}}return $this;}/*** @return Collection<int, Attendance>*/public function getAttendances(): Collection{return $this->attendances;}public function addAttendance(Attendance $attendance): static{if (!$this->attendances->contains($attendance)) {$this->attendances->add($attendance);$attendance->setCreatorUserId($this);}return $this;}public function removeAttendance(Attendance $attendance): static{if ($this->attendances->removeElement($attendance)) {// set the owning side to null (unless already changed)if ($attendance->getCreatorUserId() === $this) {$attendance->setCreatorUserId(null);}}return $this;}/*** @return Collection<int, Events>*/public function getEvents(): Collection{return $this->events;}public function addEvent(Events $event): static{if (!$this->events->contains($event)) {$this->events->add($event);$event->addCourseUser($this);}return $this;}public function removeEvent(Events $event): static{if ($this->events->removeElement($event)) {$event->removeCourseUser($this);}return $this;}/*** @return Collection<int, Events>*/public function getManagedEvents(): Collection{return $this->managedEvents;}public function addManagedEvent(Events $managedEvent): static{if (!$this->managedEvents->contains($managedEvent)) {$this->managedEvents->add($managedEvent);$managedEvent->addManagerUser($this);}return $this;}public function removeManagedEvent(Events $managedEvent): static{if ($this->managedEvents->removeElement($managedEvent)) {$managedEvent->removeManagerUser($this);}return $this;}public function getSurname(): ?string{return $this->surname;}public function setSurname(?string $surname): static{$this->surname = $surname;return $this;}public function getCustomFilterYear(): ?string{return $this->customFilterYear;}public function setCustomFilterYear(?string $customFilterYear): static{$this->customFilterYear = $customFilterYear;return $this;}#[ORM\OneToOne(mappedBy: 'user', cascade: ['persist', 'remove'])]private ?UserProfile $profile = null;#[ORM\OneToMany(mappedBy: 'user', targetEntity: EventRequest::class, orphanRemoval: true)]private Collection $eventRequests;#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserPenalty::class, orphanRemoval: true)]private Collection $penalties;public function getProfile(): ?UserProfile{return $this->profile;}public function setProfile(?UserProfile $profile): self{$this->profile = $profile;if ($profile && $profile->getUser() !== $this) {$profile->setUser($this);}return $this;}/*** @return Collection<int, EventRequest>*/public function getEventRequests(): Collection{return $this->eventRequests;}/*** @return Collection<int, UserPenalty>*/public function getPenalties(): Collection{return $this->penalties;}public function addEventRequest(EventRequest $eventRequest): static{if (!$this->eventRequests->contains($eventRequest)) {$this->eventRequests->add($eventRequest);$eventRequest->setUser($this);}return $this;}public function removeEventRequest(EventRequest $eventRequest): static{if ($this->eventRequests->removeElement($eventRequest)) {// set the owning side to null (unless already changed)if ($eventRequest->getUser() === $this) {$eventRequest->setUser(null);}}return $this;}public function isActive(): bool{return $this->active;}public function setActive(bool $active): self{$this->active = $active;return $this;}public function getActivationToken(): ?string{return $this->activationToken;}public function setActivationToken(?string $activationToken): self{$this->activationToken = $activationToken;return $this;}public function isEnabled(): bool{return $this->active && !$this->deleted;}public function getManagementCenter(): ?Centers{return $this->managementCenter;}public function setManagementCenter(?Centers $managementCenter): self{$this->managementCenter = $managementCenter;return $this;}public function canManageEventRequestsAndRegistrations(): bool{return $this->canManageEventRequestsAndRegistrations;}public function isCanManageEventRequestsAndRegistrations(): bool{return $this->canManageEventRequestsAndRegistrations;}public function setCanManageEventRequestsAndRegistrations(bool $canManageEventRequestsAndRegistrations): self{$this->canManageEventRequestsAndRegistrations = $canManageEventRequestsAndRegistrations;return $this;}}