<?php
namespace App\Entity;
use Serializable;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use App\Entity\UserRole;
class User implements UserInterface, PasswordAuthenticatedUserInterface {
/**
* @var integer
*/
private $id;
/**
* @var string
*/
private $uuid;
/**
* @var string
*/
private $username;
/**
* @var string
*/
private $password;
/**
* @var string
*/
private $email;
/**
* @var boolean
*/
private $isActive;
/**
* @var \DateTime
*/
private $createdAt;
/**
* @var \DateTime
*/
private $lastLogin;
/**
* @var \Doctrine\Common\Collections\Collection
*/
private $roles;
/**
* @var \App\Entity\UserData
*/
private $userData;
/**
* @var \App\Entity\UserSetting
*/
private $userSetting;
/**
* @var \App\Entity\UserAvatar|null
*/
private $avatar;
/**
* Constructor
*/
public function __construct() {
$this->uuid = "";
$this->username = "";
$this->password = "";
$this->isActive = true;
$this->roles = new ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId() {
return $this->id;
}
public function getUuid(): string {
return $this->uuid;
}
/**
* Set username
*
* @param string $username
*
* @return User
*/
public function setUsername($username) {
$this->username = $username;
return $this;
}
/**
* Get username
*
* @return string
*/
public function getUsername() {
return $this->username;
}
/**
* Get user identifier
*
* @return string
*/
public function getUserIdentifier(): string {
return $this->uuid;
}
/**
* Set password
*
* @param string $password
*
* @return User
*/
public function setPassword($password) {
$this->password = $password;
return $this;
}
/**
* Get password
*
* @return string
*/
public function getPassword(): ?string {
return $this->password;
}
public function setUuid(string $uuid) {
$this->uuid = $uuid;
return $this;
}
/**
* Set email
*
* @param string $email
*
* @return User
*/
public function setEmail($email) {
$this->email = $email;
return $this;
}
/**
* Get email
*
* @return string
*/
public function getEmail() {
return $this->email;
}
/**
* Set isActive
*
* @param boolean $isActive
*
* @return User
*/
public function setIsActive($isActive) {
$this->isActive = $isActive;
return $this;
}
/**
* Get isActive
*
* @return boolean
*/
public function getIsActive() {
return $this->isActive;
}
/**
* Set createdAt
*
* @param \DateTime $createdAt
*
* @return User
*/
public function setCreatedAt($createdAt) {
$this->createdAt = $createdAt;
return $this;
}
/**
* Get createdAt
*
* @return \DateTime
*/
public function getCreatedAt() {
return $this->createdAt;
}
/**
* Set lastLogin
*
* @param \DateTime $lastLogin
*
* @return User
*/
public function setLastLogin($lastLogin) {
$this->lastLogin = $lastLogin;
return $this;
}
/**
* Get lastLogin
*
* @return \DateTime
*/
public function getLastLogin() {
return $this->lastLogin;
}
/**
* Add role
*
* @param UserRole $role
*
* @return User
*/
public function addRole(UserRole $role) {
$this->roles[] = $role;
return $this;
}
/**
* Remove role
*
* @param UserRole $role
*/
public function removeRole(UserRole $role) {
$this->roles->removeElement($role);
}
/**
* Get roles
*
* @return \Doctrine\Common\Collections\Collection
*/
// Because of the symfony security UserInterface, this has to return
// an Array of strings
public function getRoles() {
$roleArray = array();
foreach ($this->roles as $role) {
array_push($roleArray, $role->getName());
}
return $roleArray;
}
/**
* Get roles
*
* @return \Doctrine\Common\Collections\Collection
*/
// Because of the symfony security UserInterface, this has to return
// an Array of strings
public function getRolesAsObjects() {
$roleArray = array();
foreach ($this->roles as $role) {
array_push($roleArray, $role);
}
return $roleArray;
}
// this is our actual getRolesFunction to get them as Entity Collection
public function getRolesAsCollection() {
return $this->roles;
}
public function countUserRoles() {
return count($this->roles);
}
public function hasRoleID($roleID) {
/* @var $userRole UserRole */
foreach ($this->roles as $userRole) {
if ($userRole->getId() == $roleID) {
return true;
}
}
return false;
}
public function hasRole($roleText) {
if (in_array($roleText, $this->getRoles())) {
return true;
} else {
return false;
}
}
public function hasRoleArr($roles) {
$userRoles = $this->getRoles();
foreach ($roles as $role) {
if (in_array($role, $userRoles)) {
return true;
}
}
return false;
}
public function isTeacher() {
return $this->hasRole('ROLE_TEACHER');
}
public function isDirector() {
return $this->hasRole('ROLE_DIRECTOR');
}
public function isCompany() {
return $this->hasRole('ROLE_COMPANY');
}
public function isBoPartner() {
return $this->hasRole('ROLE_BOPARTNER');
}
public function isSchool() {
return $this->hasRole('ROLE_SECONDARY_SCHOOL');
}
public function isSchoolClass() {
return $this->hasRole('ROLE_SCHOOL_CLASS');
}
/**
* Set userData.
*
* @param \App\Entity\UserData|null $userData
*
* @return User
*/
public function setUserData(\App\Entity\UserData $userData = null) {
$this->userData = $userData;
return $this;
}
/**
* Get userData.
*
* @return \App\Entity\UserData|null
*/
public function getUserData() {
return $this->userData;
}
/**
* Set userSetting.
*
* @param \App\Entity\UserSetting|null $userSetting
*
* @return User
*/
public function setUserSetting(\App\Entity\UserSetting $userSetting = null) {
$this->userSetting = $userSetting;
return $this;
}
/**
* Get userSetting.
*
* @return \App\Entity\UserSetting|null
*/
public function getUserSetting() {
return $this->userSetting;
}
public function getAvatar(): ?\App\Entity\UserAvatar {
return $this->avatar;
}
public function setAvatar(?\App\Entity\UserAvatar $avatar): void {
$this->avatar = $avatar;
}
public function getTypeText() {
if ($this->isCompany()) {
return 'UNT';
}
if ($this->isBoPartner()) {
return 'BOP';
}
if ($this->isSchool()) {
return 'WFS';
}
if ($this->isDirector()) {
return 'DIR';
}
if ($this->isTeacher()) {
return 'LEH';
}
return '';
}
public function getName() {
if (!empty($this->userData)) {
return $this->userData->getName();
}
return '';
}
public function getFullName() {
if (!empty($this->userData)) {
return $this->userData->getFullName();
}
return '';
}
public function __serialize(): array {
return array(
'id' => $this->id,
'uuid' => $this->uuid,
'email' => $this->email,
'username' => $this->username,
'password' => $this->password,
'isactive' => $this->isActive
);
}
public function __unserialize(array $data): void {
$this->id = $data['id'];
$this->uuid = $data['uuid'];
$this->email = $data['email'];
$this->username = $data['username'];
$this->password = $data['password'];
$this->isActive = $data['isactive'];
}
/**
* The User Interface forces us to implement that method
*/
public function eraseCredentials() {
}
public function isAccountNonExpired(): bool {
return true;
}
public function isAccountNonLocked(): bool {
return true;
}
public function isCredentialsNonExpired(): bool {
return true;
}
public function isEnabled(): bool {
return $this->isActive;
}
public function getSalt(): ?string {
return null;
}
public function __toString() {
$id = $this->id;
$username = $this->username;
return "UserID: $id, Username: $username";
}
}