<?php
namespace App\Entity;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
use App\Util\SecurityUtil;
use App\Entity\Traits\UserPropertyTrait;
/**
*
* @ORM\Entity(repositoryClass="App\Repository\UserRepository")
* @ORM\Table(name="users")
* @UniqueEntity("username")
*/
class User implements UserInterface
{
use UserPropertyTrait;
const NAME = '用户';
/**
*
* @ORM\ManyToOne(targetEntity="College")
*/
protected $adminCollege;
/**
*
* @ORM\Column(length=25)
* @Assert\Choice(callback={"App\Util\SecurityUtil", "roleOptions"})
*/
protected $role = SecurityUtil::ROLE_APPLICANT;
/**
*
* @ORM\OneToOne(targetEntity="UserInfo")
*/
protected $userInfo;
/**
*
* @see UserInterface
*/
public function getRoles(): array
{
return [
$this->role
];
}
public function setRoles(array $roles)
{
$this->roles = $roles;
}
public function getPassword(): ?string
{
return null;
}
public function getAdminCollege(): ?College
{
return $this->adminCollege;
}
public function setAdminCollege(?College $adminCollege)
{
$this->adminCollege = $adminCollege;
}
public function getRole(): string
{
return $this->role;
}
public function setRole(string $role)
{
$this->role = $role;
}
public function setUserInfo(?UserInfo $userInfo)
{
$this->userInfo = $userInfo;
}
public function getUserInfo(): ?UserInfo
{
return $this->userInfo;
}
public function getRoleName(): string
{
return SecurityUtil::ROLE_NAMES[$this->role];
}
public function __toString(): string
{
return $this->name ?: $this->username;
}
}