<?php
namespace App\Entity;
use App\Repository\UserRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Entity(repositoryClass: UserRepository::class)]
#[UniqueEntity(fields: ['email'], message: 'There is already an account with this email')]
class User implements UserInterface, PasswordAuthenticatedUserInterface, TwoFactorInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $firstName = null;
#[ORM\Column(length: 255)]
private ?string $lastName = null;
#[ORM\Column(length: 180, unique: true)]
private ?string $email = null;
/**
* @var array<int, string>
*/
#[ORM\Column]
private array $roles = [];
#[ORM\Column(type: 'boolean')]
private ?bool $isVerified = false;
#[ORM\Column(type: 'boolean')]
private ?bool $isApproved = false;
#[ORM\Column(type: 'boolean')]
private ?bool $canChangeTheme = true;
#[ORM\Column(type: 'boolean')]
private ?bool $showHideCollateralCoverage = false;
#[ORM\Column(type: 'boolean')]
private ?bool $showHideTradeRequestLink = true;
/**
* @var string The hashed password
*/
#[ORM\Column]
#[Assert\Length(min: 8, minMessage: 'Your password must be at least 8 characters long')]
#[Assert\Regex(pattern: '^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\W).*$^', message: 'Your password must contain at least one lowercase, one uppercase, one number and one special character')]
private ?string $password = null;
#[Assert\EqualTo(propertyPath: 'password', message: 'Your passwords do not match!')]
public string $confirmPassword;
#[ORM\Column(length: 180, nullable: true)]
private ?string $authCode = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $institutionName = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $mainPhoneNumber = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $mobilePhoneNumber = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $referralAgent = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $invitationCode = null;
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $notes = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $sector = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $country = null;
#[ORM\Column(nullable: true)]
private ?float $feeMargin = 10;
#[ORM\ManyToOne(inversedBy: 'users')]
#[ORM\JoinColumn]
private ?Theme $associatedTheme = null;
#[ORM\OneToOne(mappedBy: 'user', cascade: ['persist', 'remove'])]
private ?UserForm $userForm = null;
/**
* @var Collection<int, SdsFormRequest>
*/
#[ORM\OneToMany(mappedBy: 'user', targetEntity: SdsFormRequest::class)]
private Collection $sdsFormRequests;
#[ORM\Column(type: 'boolean')]
private ?bool $isDeleted = false;
#[ORM\Column]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\Column]
private ?\DateTimeImmutable $updatedAt = null;
#[ORM\ManyToOne(inversedBy: 'users')]
private ?Currency $selectedCurrency = null;
/**
* @var array<int, string>|null
*/
#[ORM\Column(nullable: true)]
private ?array $additionalEmails = null;
/**
* @var Collection<int, Client>
*/
#[ORM\ManyToMany(targetEntity: Client::class, inversedBy: 'users')]
private Collection $clients;
/**
* @var Collection<int, SdsRequestsHistory>
*/
#[ORM\OneToMany(mappedBy: 'editedBy', targetEntity: SdsRequestsHistory::class)]
private Collection $sdsRequestsHistories;
/**
* @var Collection<int, SdsFormRequest>
*/
#[ORM\OneToMany(mappedBy: 'createdBy', targetEntity: SdsFormRequest::class)]
private Collection $createdRequests;
/**
* @var Collection<int, Counterparty>
*/
#[ORM\ManyToMany(targetEntity: Counterparty::class, mappedBy: 'cptyUsers')]
private Collection $counterparties;
/**
* @var Collection<int, SdsFormRequest>
*/
#[ORM\OneToMany(mappedBy: 'deletedBy', targetEntity: SdsFormRequest::class)]
private Collection $deletedSdsFormRequests;
/**
* @var Collection<int, ClientSsi>
*/
#[ORM\OneToMany(mappedBy: 'submittedBy', targetEntity: ClientSsi::class)]
private Collection $submittedClientSsis;
/**
* @var Collection<int, ClientSsi>
*/
#[ORM\OneToMany(mappedBy: 'editedBy', targetEntity: ClientSsi::class)]
private Collection $editedClientSsis;
/**
* @var Collection<int, ClientSsi>
*/
#[ORM\OneToMany(mappedBy: 'declinedBy', targetEntity: ClientSsi::class)]
private Collection $declinedClientSsis;
public function __construct()
{
$this->sdsFormRequests = new ArrayCollection();
$this->setCreatedAt(new \DateTimeImmutable());
$this->setUpdatedAt(new \DateTimeImmutable());
$this->clients = new ArrayCollection();
$this->sdsRequestsHistories = new ArrayCollection();
$this->createdRequests = new ArrayCollection();
$this->counterparties = new ArrayCollection();
$this->deletedSdsFormRequests = new ArrayCollection();
$this->submittedClientSsis = new ArrayCollection();
$this->editedClientSsis = new ArrayCollection();
$this->declinedClientSsis = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getFirstName(): ?string
{
return $this->firstName;
}
public function setFirstName(string $firstName): self
{
$this->firstName = $firstName;
return $this;
}
public function getLastName(): ?string
{
return $this->lastName;
}
public function setLastName(string $lastName): self
{
$this->lastName = $lastName;
return $this;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
/** @param array<int, string> $roles */
public function setRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function isVerified(): bool
{
return $this->isVerified;
}
public function setIsVerified(bool $isVerified): self
{
$this->isVerified = $isVerified;
return $this;
}
public function isApproved(): ?bool
{
return $this->isApproved;
}
public function setIsApproved(bool $isApproved): self
{
$this->isApproved = $isApproved;
return $this;
}
public function canChangeTheme(): ?bool
{
return $this->canChangeTheme;
}
public function setCanChangeTheme(bool $canChangeTheme): self
{
$this->canChangeTheme = $canChangeTheme;
return $this;
}
public function getShowHideCollateralCoverage(): ?bool
{
return $this->showHideCollateralCoverage;
}
public function setShowHideCollateralCoverage(bool $showHideCollateralCoverage): self
{
$this->showHideCollateralCoverage = $showHideCollateralCoverage;
return $this;
}
public function getShowHideTradeRequestLink(): ?bool
{
return $this->showHideTradeRequestLink;
}
public function setShowHideTradeRequestLink(bool $showHideTradeRequestLink): self
{
$this->showHideTradeRequestLink = $showHideTradeRequestLink;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @see PasswordAuthenticatedUserInterface
*/
public function getPassword(): string
{
return $this->password;
}
public function setPassword(string $password): self
{
$this->password = $password;
return $this;
}
/**
* @see UserInterface
*/
public function eraseCredentials(): void
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
/**
* Return true if the user should do two-factor authentication.
*/
public function isEmailAuthEnabled(): bool
{
return true; // This can be persisted fielD to switch email code authentication on/off
}
/**
* Return user email address.
*/
public function getEmailAuthRecipient(): string
{
return $this->email;
}
/**
* Return the authentication code.
*/
public function getEmailAuthCode(): ?string
{
if (null === $this->authCode) {
throw new \LogicException('The email authentication code was not set');
}
return $this->authCode;
}
/**
* Set the authentication code.
*/
public function setEmailAuthCode(string $authCode): void
{
$this->authCode = $authCode;
}
public function getInstitutionName(): ?string
{
return $this->institutionName;
}
public function setInstitutionName(string $institutionName): self
{
$this->institutionName = $institutionName;
return $this;
}
public function getMainPhoneNumber(): ?string
{
return $this->mainPhoneNumber;
}
public function setMainPhoneNumber(string $mainPhoneNumber): self
{
$this->mainPhoneNumber = $mainPhoneNumber;
return $this;
}
public function getMobilePhoneNumber(): ?string
{
return $this->mobilePhoneNumber;
}
public function setMobilePhoneNumber(?string $mobilePhoneNumber): self
{
$this->mobilePhoneNumber = $mobilePhoneNumber;
return $this;
}
public function getReferralAgent(): ?string
{
return $this->referralAgent;
}
public function setReferralAgent(?string $referralAgent): self
{
$this->referralAgent = $referralAgent;
return $this;
}
public function getInvitationCode(): ?string
{
return $this->invitationCode;
}
public function setInvitationCode(?string $invitationCode): self
{
$this->invitationCode = $invitationCode;
return $this;
}
public function getNotes(): ?string
{
return $this->notes;
}
public function setNotes(?string $notes): self
{
$this->notes = $notes;
return $this;
}
public function getSector(): ?string
{
return $this->sector;
}
public function setSector(?string $sector): self
{
$this->sector = $sector;
return $this;
}
public function getCountry(): ?string
{
return $this->country;
}
public function setCountry(string $country): self
{
$this->country = $country;
return $this;
}
public function getFeeMargin(): ?float
{
return $this->feeMargin;
}
public function setFeeMargin(?float $feeMargin): self
{
$this->feeMargin = $feeMargin;
return $this;
}
public function getAssociatedTheme(): ?Theme
{
return $this->associatedTheme;
}
public function setAssociatedTheme(?Theme $associatedTheme): self
{
$this->associatedTheme = $associatedTheme;
return $this;
}
public function getUserForm(): ?UserForm
{
return $this->userForm;
}
public function setUserForm(UserForm $userForm): self
{
// set the owning side of the relation if necessary
if ($userForm->getUser() !== $this) {
$userForm->setUser($this);
}
$this->userForm = $userForm;
return $this;
}
/**
* @return Collection<int, SdsFormRequest>
*/
public function getSdsFormRequests(): Collection
{
return $this->sdsFormRequests;
}
public function addSdsFormRequest(SdsFormRequest $sdsFormRequest): self
{
if (!$this->sdsFormRequests->contains($sdsFormRequest)) {
$this->sdsFormRequests->add($sdsFormRequest);
$sdsFormRequest->setUser($this);
}
return $this;
}
public function removeSdsFormRequest(SdsFormRequest $sdsFormRequest): self
{
if ($this->sdsFormRequests->removeElement($sdsFormRequest)) {
// set the owning side to null (unless already changed)
if ($sdsFormRequest->getUser() === $this) {
$sdsFormRequest->setUser(null);
}
}
return $this;
}
public function isIsDeleted(): ?bool
{
return $this->isDeleted;
}
public function setIsDeleted(bool $isDeleted): self
{
$this->isDeleted = $isDeleted;
return $this;
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeImmutable $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function getSelectedCurrency(): ?Currency
{
return $this->selectedCurrency;
}
public function setSelectedCurrency(?Currency $selectedCurrency): self
{
$this->selectedCurrency = $selectedCurrency;
return $this;
}
public function getAdditionalEmails(): ?string
{
return $this->additionalEmails ? implode(';', $this->additionalEmails) : null;
}
/** @param array<int, string>|null $additionalEmails */
public function setAdditionalEmails(?array $additionalEmails): self
{
$this->additionalEmails = $additionalEmails;
return $this;
}
/**
* @return Collection<int, Client>
*/
public function getClients(): Collection
{
return $this->clients;
}
public function addClient(Client $client): self
{
if (!$this->clients->contains($client)) {
$this->clients->add($client);
}
return $this;
}
public function removeClient(Client $client): self
{
$this->clients->removeElement($client);
return $this;
}
/**
* @return Collection<int, SdsRequestsHistory>
*/
public function getSdsRequestsHistories(): Collection
{
return $this->sdsRequestsHistories;
}
public function addSdsRequestsHistory(SdsRequestsHistory $sdsRequestsHistory): self
{
if (!$this->sdsRequestsHistories->contains($sdsRequestsHistory)) {
$this->sdsRequestsHistories->add($sdsRequestsHistory);
$sdsRequestsHistory->setEditedBy($this);
}
return $this;
}
public function removeSdsRequestsHistory(SdsRequestsHistory $sdsRequestsHistory): self
{
if ($this->sdsRequestsHistories->removeElement($sdsRequestsHistory)) {
// set the owning side to null (unless already changed)
if ($sdsRequestsHistory->getEditedBy() === $this) {
$sdsRequestsHistory->setEditedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, SdsFormRequest>
*/
public function getCreatedRequests(): Collection
{
return $this->createdRequests;
}
public function addCreatedRequest(SdsFormRequest $createdRequest): self
{
if (!$this->createdRequests->contains($createdRequest)) {
$this->createdRequests->add($createdRequest);
$createdRequest->setCreatedBy($this);
}
return $this;
}
public function removeCreatedRequest(SdsFormRequest $createdRequest): self
{
if ($this->createdRequests->removeElement($createdRequest)) {
// set the owning side to null (unless already changed)
if ($createdRequest->getCreatedBy() === $this) {
$createdRequest->setCreatedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, Counterparty>
*/
public function getCounterparties(): Collection
{
return $this->counterparties;
}
public function addCounterparty(Counterparty $counterparty): self
{
if (!$this->counterparties->contains($counterparty)) {
$this->counterparties->add($counterparty);
$counterparty->addCptyUser($this);
}
return $this;
}
public function removeCounterparty(Counterparty $counterparty): self
{
if ($this->counterparties->removeElement($counterparty)) {
$counterparty->removeCptyUser($this);
}
return $this;
}
/**
* @return Collection<int, SdsFormRequest>
*/
public function getDeletedSdsFormRequests(): Collection
{
return $this->deletedSdsFormRequests;
}
public function addDeletedSdsFormRequest(SdsFormRequest $deletedSdsFormRequest): self
{
if (!$this->deletedSdsFormRequests->contains($deletedSdsFormRequest)) {
$this->deletedSdsFormRequests->add($deletedSdsFormRequest);
$deletedSdsFormRequest->setDeletedBy($this);
}
return $this;
}
public function removeDeletedSdsFormRequest(SdsFormRequest $deletedSdsFormRequest): self
{
if ($this->deletedSdsFormRequests->removeElement($deletedSdsFormRequest)) {
// set the owning side to null (unless already changed)
if ($deletedSdsFormRequest->getDeletedBy() === $this) {
$deletedSdsFormRequest->setDeletedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, ClientSsi>
*/
public function getSubmittedClientSsis(): Collection
{
return $this->submittedClientSsis;
}
public function addSubmittedClientSsi(ClientSsi $submittedClientSsi): self
{
if (!$this->submittedClientSsis->contains($submittedClientSsi)) {
$this->submittedClientSsis->add($submittedClientSsi);
$submittedClientSsi->setSubmittedBy($this);
}
return $this;
}
public function removeSubmittedClientSsi(ClientSsi $submittedClientSsi): self
{
if ($this->submittedClientSsis->removeElement($submittedClientSsi)) {
// set the owning side to null (unless already changed)
if ($submittedClientSsi->getSubmittedBy() === $this) {
$submittedClientSsi->setSubmittedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, ClientSsi>
*/
public function getEditedClientSsis(): Collection
{
return $this->editedClientSsis;
}
public function addEditedClientSsi(ClientSsi $editedClientSsi): self
{
if (!$this->editedClientSsis->contains($editedClientSsi)) {
$this->editedClientSsis->add($editedClientSsi);
$editedClientSsi->setEditedBy($this);
}
return $this;
}
public function removeEditedClientSsi(ClientSsi $editedClientSsi): self
{
if ($this->editedClientSsis->removeElement($editedClientSsi)) {
// set the owning side to null (unless already changed)
if ($editedClientSsi->getEditedBy() === $this) {
$editedClientSsi->setEditedBy(null);
}
}
return $this;
}
/**
* @return Collection<int, ClientSsi>
*/
public function getDeclinedClientSsis(): Collection
{
return $this->declinedClientSsis;
}
public function addDeclinedClientSsi(ClientSsi $declinedClientSsi): self
{
if (!$this->declinedClientSsis->contains($declinedClientSsi)) {
$this->declinedClientSsis->add($declinedClientSsi);
$declinedClientSsi->setDeclinedBy($this);
}
return $this;
}
public function removeDeclinedClientSsi(ClientSsi $declinedClientSsi): self
{
if ($this->declinedClientSsis->removeElement($declinedClientSsi)) {
// set the owning side to null (unless already changed)
if ($declinedClientSsi->getDeclinedBy() === $this) {
$declinedClientSsi->setDeclinedBy(null);
}
}
return $this;
}
}