registeredAt = new \DateTime(); $this->preferences = new ArrayCollection(); } /** * @return int */ public function getId() { return $this->id; } /** * @return \DateTime */ public function getRegisteredAt() { return $this->registeredAt; } /** * @param \DateTime $registeredAt * @return $this */ public function setRegisteredAt(\DateTime $registeredAt) { $this->registeredAt = $registeredAt; return $this; } /** * @param string $alias * @return $this */ public function setAlias($alias) { $this->alias = $alias; return $this; } /** * @return string */ public function getAlias() { return $this->alias; } /** * @param boolean $active * @return $this */ public function setActive($active) { $this->active = (bool) $active; return $this; } /** * @return boolean */ public function isActive() { return $this->active; } /** * @param string $password * @return $this */ public function setPassword($password) { $this->password = $password; return $this; } /** * Get password * * @return string */ public function getPassword() { return $this->password; } /** * Only for form editing, you don't need this method! * * @return string */ public function getPlainPassword() { return $this->plainPassword; } /** * Only for form editing, you don't need this method! * * @param string $password * @return $this */ public function setPlainPassword($password) { $this->plainPassword = $password; return $this; } /** * @return string */ public function getUsername() { return $this->username; } /** * @param string $username * @return $this */ public function setUsername($username) { $this->username = $username; return $this; } /** * @return string */ public function getEmail() { return $this->email; } /** * @param string $email * @return $this */ public function setEmail($email) { $this->email = $email; return $this; } /** * @return string */ public function getTitle() { return $this->title; } /** * @param string $title * @return $this */ public function setTitle($title) { $this->title = $title; return $this; } /** * @return string */ public function getAvatar() { return $this->avatar; } /** * @param string $avatar * @return $this */ public function setAvatar($avatar) { $this->avatar = $avatar; return $this; } /** * Returns the roles or permissions granted to the user for security. * * @return string[] */ public function getRoles() { $roles = $this->roles; // guarantees that a user always has at least one role for security if (empty($roles)) { $roles[] = 'ROLE_USER'; } return array_unique($roles); } /** * @param string[] $roles * @return $this */ public function setRoles(array $roles) { $this->roles = $roles; return $this; } /** * @return UserPreference[]|Collection */ public function getPreferences(): Collection { return $this->preferences; } /** * @param UserPreference[]|Collection $preferences * @return User */ public function setPreferences(array $preferences) { if (!($preferences instanceof Collection) && is_array($preferences)) { $preferences = new ArrayCollection($preferences); } $this->preferences = $preferences; return $this; } /** * @param string $name * @return UserPreference|null */ public function getPreference(string $name) { foreach ($this->preferences as $preference) { if ($preference->getName() == $name) { return $preference; } } return null; } /** * @param $name * @param null $default * @return bool|int|null|string */ public function getPreferenceValue($name, $default = null) { $preference = $this->getPreference($name); if ($preference === null) { return $default; } return $preference->getValue(); } /** * @param UserPreference $preference * @return User */ public function addPreference(UserPreference $preference) { $this->preferences->add($preference); return $this; } /** * @inheritdoc */ public function isAccountNonExpired() { return true; } /** * @inheritdoc */ public function isAccountNonLocked() { return true; } /** * @inheritdoc */ public function isCredentialsNonExpired() { return true; } /** * @return bool */ public function isEnabled() { return $this->isActive(); } /** * Returns the salt that was originally used to encode the password. */ public function getSalt() { // See "Do you need to use a Salt?" at http://symfony.com/doc/current/cookbook/security/entity_provider.html // we're using bcrypt in security.yml to encode the password, so // the salt value is built-in and you don't have to generate one return; } /** * Removes sensitive data from the user. */ public function eraseCredentials() { // if you had a plainPassword property, you'd nullify it here // $this->plainPassword = null; } /** * @return string */ public function __toString() { return $this->getAlias() ?: $this->getUsername(); } }