permissions = new PermissionsEmbed(); } /** * Checks if the current user, is the user which represents the not logged in (anonymous) users. * * @return bool true if this user is the anonymous user */ public function isAnonymousUser(): bool { return $this->id === static::ID_ANONYMOUS && 'anonymous' === $this->name; } /** * A visual identifier that represents this user. * * @see UserInterface */ public function getUsername(): string { return (string) $this->name; } /** * @see UserInterface */ public function getRoles(): array { $roles = []; //$roles = $this->roles; // guarantee every user at least has ROLE_USER $roles[] = 'ROLE_USER'; return array_unique($roles); } public function setRoles(array $roles): self { //$this->roles = $roles; return $this; } /** * @see UserInterface * Gets the password hash for this entity. */ public function getPassword(): string { return (string) $this->password; } /** * Sets the password hash for this user. * * @param string $password * * @return User */ public function setPassword(string $password): self { $this->password = $password; return $this; } /** * @see UserInterface */ public function getSalt() { // not needed when using the "bcrypt" algorithm in security.yaml } /** * @see UserInterface */ public function eraseCredentials() { // If you store any temporary, sensitive data on the user, clear it here // $this->plainPassword = null; } /** * Gets the currency the user prefers when showing him prices. * @return Currency|null The currency the user prefers, or null if the global currency should be used. */ public function getCurrency(): ?Currency { return $this->currency; } /** * Sets the currency the users prefers to see prices in. * @param Currency|null $currency * @return User */ public function setCurrency(?Currency $currency): User { $this->currency = $currency; return $this; } /** * Returns the ID as an string, defined by the element class. * This should have a form like P000014, for a part with ID 14. * * @return string The ID as a string; */ public function getIDString(): string { return 'U'.sprintf('%06d', $this->getID()); } public function getPermissions(): PermissionsEmbed { return $this->permissions; } /** * Check if the user needs a password change * @return bool */ public function isNeedPwChange(): bool { return $this->need_pw_change; } /** * Set the status, if the user needs a password change. * @param bool $need_pw_change * @return User */ public function setNeedPwChange(bool $need_pw_change): User { $this->need_pw_change = $need_pw_change; return $this; } /************************************************ * Getters ************************************************/ /** * Returns the full name in the format FIRSTNAME LASTNAME [(USERNAME)]. * Example: Max Muster (m.muster). * * @param bool $including_username include the username in the full name * * @return string a string with the full name of this user */ public function getFullName(bool $including_username = false): string { $str = $this->getFirstName().' '.$this->getLastName(); if ($including_username) { $str .= ' ('.$this->getName().')'; } return $str; } public function setName(string $new_name): NamedDBElement { // Anonymous user is not allowed to change its username if (!$this->isAnonymousUser()) { $this->name = $new_name; } return $this; } /** * @return string */ public function getFirstName(): ?string { return $this->first_name; } /** * @param string $first_name * * @return User */ public function setFirstName(?string $first_name): User { $this->first_name = $first_name; return $this; } /** * @return string */ public function getLastName(): ?string { return $this->last_name; } /** * @param string $last_name * * @return User */ public function setLastName(?string $last_name): User { $this->last_name = $last_name; return $this; } /** * @return string */ public function getDepartment(): ?string { return $this->department; } /** * @param string $department * * @return User */ public function setDepartment(?string $department): User { $this->department = $department; return $this; } /** * @return string */ public function getEmail(): ?string { return $this->email; } /** * @param string $email * * @return User */ public function setEmail(?string $email): User { $this->email = $email; return $this; } /** * @return string */ public function getLanguage(): ?string { return $this->language; } /** * @param string $language * * @return User */ public function setLanguage(?string $language): User { $this->language = $language; return $this; } /** * @return string */ public function getTimezone(): ?string { return $this->timezone; } /** * @param string $timezone * * @return User */ public function setTimezone(?string $timezone): User { $this->timezone = $timezone; return $this; } /** * @return string */ public function getTheme(): ?string { return $this->theme; } /** * @param string $theme * * @return User */ public function setTheme(?string $theme): User { $this->theme = $theme; return $this; } public function getGroup(): ?Group { return $this->group; } public function setGroup(?Group $group): self { $this->group = $group; return $this; } public function __toString() { return $this->getFullName(true); } }