<?php
namespace App\Entity;
use App\Repository\AdminUserRepository;
use Doctrine\ORM\Mapping as ORM;
use Umbrella\AdminBundle\Entity\BaseAdminUser;
use Umbrella\CoreBundle\Search\Annotation\Searchable;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* @ORM\Table(name="admin_user")
* @ORM\Entity(repositoryClass=AdminUserRepository::class)
* @Searchable
* @UniqueEntity(fields={"email"})
*/
class AdminUser extends BaseAdminUser
{
public const ROLE_ADMIN = 'ROLE_ADMIN';
public const ROLE_DEALER = 'ROLE_DEALER';
public const ROLE_SERVICE = 'ROLE_SERVICE';
public const ROLE_OFFICE = 'ROLE_OFFICE';
public const LOCALE_RU = 'ru';
public const LOCALE_EN = 'en';
public static array $roleTypes = [
self::ROLE_ADMIN => 'roles.admin',
self::ROLE_DEALER => 'roles.dealer',
self::ROLE_SERVICE => 'roles.service',
self::ROLE_OFFICE => 'roles.office',
];
public const LOCALES = [
self::LOCALE_RU,
self::LOCALE_EN,
];
/**
* @ORM\Id
* @ORM\GeneratedValue(strategy="SEQUENCE")
* @ORM\SequenceGenerator(sequenceName="admin_user_id_seq", allocationSize=1, initialValue=1)
*/
public ?int $id = null;
/**
* @ORM\Column(type="string")
*/
public ?string $plainPassword = null;
/**
* @ORM\Column(type="string")
*/
public ?string $role = null;
/**
* @ORM\ManyToOne(targetEntity=Dealer::class, inversedBy="users")
* @var Dealer|null
*/
public ?Dealer $dealer = null;
/**
* @ORM\Column(type="string", length=2, options={"default":"ru"})
* @var string
*/
public string $locale = self::LOCALE_RU;
public function eraseCredentials()
{
}
/**
* @return array|null
*/
public function getRoles(): ?array
{
if (empty($this->role)) {
return ['ROLE_ADMIN'];
}
return [$this->role];
}
}