src/Modules/User/Entity/User.php line 21
<?phpnamespace App\Modules\User\Entity;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\ORM\Mapping as ORM;use Gedmo\Mapping\Annotation as Gedmo;use Symfony\Component\Security\Core\User\UserInterface;use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;use App\Admin\Modules\User\Entity\UserAdmin;use App\Admin\Modules\Partner\Entity\UserPartner;use App\Admin\Modules\Voucher\Entity\VoucherPackageVoucher;use App\Admin\Modules\Contract\Entity\UserContractTrader;use App\Admin\Modules\Contract\Entity\UserContractSubstantiveDepartmentEmployee;use App\Admin\SuperAdmin\Modules\Trader\Entity\UserTrader;/*** @ORM\Table(name="user", indexes={@ORM\Index(name="username", columns={"username"}), @ORM\Index(name="email", columns={"email"}), @ORM\Index(name="type", columns={"type"}), @ORM\Index(name="system_id", columns={"system_id"}), @ORM\Index(name="is_active", columns={"is_active"}), @ORM\Index(name="api_key", columns={"api_key"}), @ORM\Index(name="api_auth_token", columns={"api_auth_token"}), @ORM\Index(name="added_at", columns={"added_at"})})* @ORM\Entity(repositoryClass="App\Modules\User\Repository\UserRepository")*/class User implements UserInterface, PasswordAuthenticatedUserInterface, \Serializable{const TYPE_SUPER_ADMIN = 1;const TYPE_ADMIN = 2;const TYPE_PARTNER = 3;const TYPE_USER = 4;const TYPE_TRADER = 5;const TYPE_CONTRACT_TRADER = 6;const TYPE_CONTRACT_SUBSTANTIVE_DEPARTMENT_EMPLOYEE = 7;const SYSTEM_ADMIN_SYSTEM_ID = 'sysonline';const SYSTEM_VOUCHER_ADMIN_SYSTEM_ID = 'voucher';/*** @ORM\Column(type="integer")* @ORM\Id* @ORM\GeneratedValue(strategy="AUTO")*/private $id;/*** @ORM\Column(type="string", length=255)*/private $username;/*** @ORM\Column(type="string", length=64)*/private $password;/*** @ORM\Column(type="string", length=255)*/private $email;/*** @var \App\Admin\Modules\Voucher\Entity\VoucherPackageVoucher** @ORM\OneToOne(targetEntity="App\Admin\Modules\Voucher\Entity\VoucherPackageVoucher", mappedBy="user")* @ORM\JoinColumns({* @ORM\JoinColumn(name="id_voucher_package_voucher", referencedColumnName="id", nullable=true, onDelete="CASCADE")* })*/private $voucher;/*** @ORM\Column(name="api_key", type="string", length=100, nullable=true)*/private $apiKey;/*** @ORM\Column(name="api_auth_token", type="string", length=100, nullable=true)*/private $apiAuthToken;/*** @ORM\Column(name="selected_lang", type="string", length=2, nullable=true)*/private $selectedLang;/*** @var int** @ORM\Column(name="type", type="smallint", nullable=false)*/private $type;/*** @ORM\Column(name="system_id", type="string", length=255, nullable=true)*/private $systemId;/*** @ORM\Column(name="is_active", type="boolean")*/private $isActive;/*** @var \DateTime** @ORM\Column(name="added_at", type="datetime", nullable=false)* @Gedmo\Timestampable(on="create")*/private $addedAt;/*** @var \App\Admin\Modules\User\Entity\UserAdmin** @ORM\OneToMany(targetEntity="App\Admin\Modules\User\Entity\UserAdmin", mappedBy="user", cascade={"persist"}, orphanRemoval=true)*/private $admin;/*** @var \App\Admin\Modules\Partner\Entity\UserPartner** @ORM\OneToMany(targetEntity="App\Admin\Modules\Partner\Entity\UserPartner", mappedBy="user", cascade={"persist"}, orphanRemoval=true)*/private $partner;/*** @var \App\Admin\SuperAdmin\Modules\Trader\Entity\UserTrader** @ORM\OneToMany(targetEntity="App\Admin\SuperAdmin\Modules\Trader\Entity\UserTrader", mappedBy="user", cascade={"persist"}, orphanRemoval=true)*/private $trader;/*** @var \App\Admin\Modules\Contract\Entity\UserContractTrader** @ORM\OneToMany(targetEntity="App\Admin\Modules\Contract\Entity\UserContractTrader", mappedBy="user", cascade={"persist"}, orphanRemoval=true)*/private $contractTrader;/*** @var \App\Admin\Modules\Contract\Entity\UserContractSubstantiveDepartmentEmployee** @ORM\OneToMany(targetEntity="App\Admin\Modules\Contract\Entity\UserContractSubstantiveDepartmentEmployee", mappedBy="user", cascade={"persist"}, orphanRemoval=true)*/private $contractSubstantiveDepartmentEmployee;public function __construct(){$this->isActive = false;// may not be needed, see section on salt below// $this->salt = md5(uniqid('', true));$this->admin = new ArrayCollection();$this->partner = new ArrayCollection();$this->trader = new ArrayCollection();$this->contractTrader = new ArrayCollection();$this->contractSubstantiveDepartmentEmployee = new ArrayCollection();}/** @see \Serializable::serialize() */public function serialize(){return serialize(array($this->id,$this->username,$this->password,// see section on salt below// $this->salt,));}/** @see \Serializable::unserialize() */public function unserialize($serialized){list ($this->id,$this->username,$this->password,// see section on salt below// $this->salt) = unserialize($serialized, array('allowed_classes' => false));}private function _getFromCollection($propertyName){if ($this->$propertyName && count($this->$propertyName))return $this->$propertyName->first();elsereturn null;}private function _addToCollection($propertyName, $value){if (!$this->$propertyName)$this->$propertyName = new ArrayCollection();elseif (count($this->$propertyName))$this->$propertyName->removeElement($this->$propertyName->first());$value->setUser($this);$this->$propertyName[] = $value;return $this;}public function getAdmin(): ?UserAdmin{return $this->_getFromCollection('admin');}public function setAdmin(?UserAdmin $admin): self{return $this->_addToCollection('admin', $admin);}public function getPartner(): ?UserPartner{return $this->_getFromCollection('partner');}public function setPartner(?UserPartner $partner): self{return $this->_addToCollection('partner', $partner);}public function getTrader(): ?UserTrader{return $this->_getFromCollection('trader');}public function setTrader(?UserTrader $trader): self{return $this->_addToCollection('trader', $trader);}public function getContractTrader(): ?UserContractTrader{return $this->_getFromCollection('contractTrader');}public function setContractTrader(?UserContractTrader $trader): self{return $this->_addToCollection('contractTrader', $trader);}public function getContractTraderNameWithId(){return $this->contractTrader[0]->getNameWithId();}public function getContractSubstantiveDepartmentEmployee(): ?UserContractSubstantiveDepartmentEmployee{return $this->_getFromCollection('contractSubstantiveDepartmentEmployee');}public function setContractSubstantiveDepartmentEmployee(?UserContractSubstantiveDepartmentEmployee $employee): self{return $this->_addToCollection('contractSubstantiveDepartmentEmployee', $employee);}public function getContractSubstantiveDepartmentEmployeeNameWithId(){return $this->contractSubstantiveDepartmentEmployee[0]->getNameWithId();}public function getUserIdentifier(): string{return $this->username;}public function getId(): ?int{return $this->id;}public function getDisplayName(){switch($this->type){case self::TYPE_ADMIN:return $this->getAdmin()->getCompanyName();case self::TYPE_PARTNER:return $this->getPartner()->getName();case self::TYPE_TRADER:return $this->getTrader()->getFirstName() . ' ' . $this->getTrader()->getLastName();case self::TYPE_CONTRACT_TRADER:return $this->getContractTrader()->getFirstName() . ' ' . $this->getContractTrader()->getLastName();case self::TYPE_CONTRACT_SUBSTANTIVE_DEPARTMENT_EMPLOYEE:return $this->getContractSubstantiveDepartmentEmployee()->getFirstName() . ' ' . $this->getContractSubstantiveDepartmentEmployee()->getFirstName();default:return $this->username;}}public function getFullApiKey(){if ($this->apiKey != '')return $this->id . '.' . $this->apiKey;}public function getEmail(): ?string{return $this->email;}public function setEmail(string $email): self{$this->email = $email;return $this;}public function getIsActive(): ?bool{return $this->isActive;}public function setIsActive(?bool $isActive): self{$this->isActive = $isActive;return $this;}public function setUsername(string $username): self{$this->username = $username;return $this;}public function getUsername(){return $this->username;}public function getSalt(){// you *may* need a real salt depending on your encoder// see section on salt belowreturn null;}public function getPassword(): ?string{return $this->password;}public function setPassword(string $password): self{$this->password = $password;return $this;}public function getRoles(): array{switch($this->type){case self::TYPE_SUPER_ADMIN:return ['ROLE_SUPER_ADMIN'];case self::TYPE_ADMIN:return ['ROLE_ADMIN'];case self::TYPE_PARTNER:return ['ROLE_PARTNER'];case self::TYPE_TRADER:return ['ROLE_TRADER'];case self::TYPE_CONTRACT_TRADER:return ['ROLE_CONTRACT_TRADER'];case self::TYPE_CONTRACT_SUBSTANTIVE_DEPARTMENT_EMPLOYEE:return ['ROLE_CONTRACT_SUBSTANTIVE_DEPARTMENT_EMPLOYEE'];case self::TYPE_USER:return ['ROLE_USER'];default:throw new \Exception('Unknown user.');}}public function eraseCredentials(){}public function getType(): ?int{return $this->type;}public function setType(int $type): self{$this->type = $type;return $this;}public function getSelectedLang(): ?string{return $this->selectedLang;}public function setSelectedLang(?string $selectedLang): self{$this->selectedLang = $selectedLang;return $this;}public function isIsActive(): ?bool{return $this->isActive;}public function getVoucher(): ?VoucherPackageVoucher{return $this->voucher;}public function setVoucher(?VoucherPackageVoucher $voucher, bool $setVoucherUser = true): self{if ($voucher && $setVoucherUser)$voucher->setUser($this, false);$this->voucher = $voucher;return $this;}public function getAddedAt(): ?\DateTimeInterface{return $this->addedAt;}public function setAddedAt(\DateTimeInterface $addedAt): self{$this->addedAt = $addedAt;return $this;}public function getSystemId(): ?string{return $this->systemId;}public function setSystemId(?string $systemId): self{$this->systemId = $systemId;return $this;}public function getApiKey(): ?string{return $this->apiKey;}public function setApiKey(?string $apiKey): self{$this->apiKey = $apiKey;return $this;}public function getApiAuthToken(): ?string{return $this->apiAuthToken;}public function setApiAuthToken(?string $apiAuthToken): self{$this->apiAuthToken = $apiAuthToken;return $this;}}