<?php
namespace App\Entity;
use App\Repository\UserRepository;
use App\String\Constant;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use PhpParser\Node\Expr\BinaryOp\BooleanOr;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;
#[ORM\Entity(repositoryClass: UserRepository::class)]
class User implements UserInterface, PasswordAuthenticatedUserInterface
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 180, unique: true)]
private $email;
#[ORM\Column(type: 'json')]
private $roles = [];
#[ORM\Column(type: 'string')]
private $password;
#[ORM\OneToOne(mappedBy: 'user', targetEntity: UserProfile::class, cascade: ['persist', 'remove'])]
private $userProfile;
#[ORM\OneToOne(mappedBy: 'user', targetEntity: UserAddress::class, cascade: ['persist', 'remove'])]
private $userAddress;
#[ORM\OneToOne(mappedBy: 'user', targetEntity: UserInformation::class, cascade: ['persist', 'remove'])]
private $userInformation;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $firstName;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $lastName;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $phone;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $gender;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $isDiverse;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: OrderDetails::class)]
private $orderDetails;
#[ORM\OneToMany(mappedBy: 'owner', targetEntity: FilmProject::class)]
private $filmProjects;
#[ORM\OneToMany(mappedBy: 'user', targetEntity: UserBilling::class)]
private $userBillings;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $organisation;
#[ORM\Column(type: 'array', nullable: true)]
private $areaInterest = [];
#[ORM\ManyToMany(targetEntity: UserCategory::class, inversedBy: 'users')]
private $categories;
#[ORM\ManyToMany(targetEntity: FilmProject::class, inversedBy: 'users')]
private $followedFilmProjects;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private $accountSalesforceId;
#[ORM\ManyToMany(targetEntity: ProjectNotification::class, mappedBy: 'user')]
private Collection $projectNotifications;
#[ORM\Column(length: 255, nullable: true)]
private ?string $isAborigin = null;
#[ORM\Column(nullable: true)]
private ?bool $isSuccess = null;
#[ORM\Column(nullable: true)]
private ?bool $isGuest = null;
private ?bool $isAdmin;
// Honeypot fields
private ?string $emailAddress = null;
private ?string $fullName = null;
public function __construct()
{
$this->orderDetails = new ArrayCollection();
$this->filmProjects = new ArrayCollection();
$this->userBillings = new ArrayCollection();
$this->categories = new ArrayCollection();
$this->followedFilmProjects = new ArrayCollection();
$this->projectNotifications = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getEmail(): ?string
{
return $this->email;
}
public function setEmail(string $email): self
{
$this->email = $email;
return $this;
}
/**
* A visual identifier that represents this user.
*
* @see UserInterface
*/
public function getUserIdentifier(): string
{
return (string) $this->email;
}
/**
* @see UserInterface
*/
public function getRoles(): array
{
$roles = $this->roles;
// guarantee every user at least has ROLE_USER
$roles[] = 'ROLE_USER';
return array_unique($roles);
}
public function setRoles(array $roles): self
{
// ALWAYS SET USERPORTAL ROLE
$roles = array_merge($roles, ['ROLE_PORTALUSER']);
$this->roles = $roles;
return $this;
}
public function setSpecificRoles(array $roles): self
{
$this->roles = $roles;
return $this;
}
public function getFullRoles(): ?string
{
$roles = $this->roles;
$roles[] = 'ROLE_USER';
$newRoles = [];
foreach ($roles as $role) {
switch ($role) {
case 'ROLE_PARTNER':
array_push($newRoles, 'Filmmaker'); break;
case 'ROLE_FUNDER':
array_push($newRoles, 'Sponsor'); break; // impact partner
case 'ROLE_DONOR':
array_push($newRoles, 'Donor'); break;
case 'ROLE_ADMIN':
array_push($newRoles, 'Administrator'); break;
case 'ROLE_FIN_ADMIN':
array_push($newRoles, 'Finance Admin'); break;
}
}
$newRoles = array_unique($newRoles);
return implode(', ', $newRoles);
}
/**
* @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()
{
// If you store any temporary, sensitive data on the user, clear it here
// $this->plainPassword = null;
}
public function getUserProfile(): ?UserProfile
{
return $this->userProfile;
}
public function setUserProfile(?UserProfile $userProfile): self
{
// unset the owning side of the relation if necessary
if ($userProfile === null && $this->userProfile !== null) {
$this->userProfile->setUser(null);
}
// set the owning side of the relation if necessary
if ($userProfile !== null && $userProfile->getUser() !== $this) {
$userProfile->setUser($this);
}
$this->userProfile = $userProfile;
return $this;
}
public function getUserAddress(): ?UserAddress
{
return $this->userAddress;
}
public function setUserAddress(?UserAddress $userAddress): self
{
// unset the owning side of the relation if necessary
if ($userAddress === null && $this->userAddress !== null) {
$this->userAddress->setUser(null);
}
// set the owning side of the relation if necessary
if ($userAddress !== null && $userAddress->getUser() !== $this) {
$userAddress->setUser($this);
}
$this->userAddress = $userAddress;
return $this;
}
public function getUserInformation(): ?UserInformation
{
return $this->userInformation;
}
public function setUserInformation(?UserInformation $userInformation): self
{
// unset the owning side of the relation if necessary
if ($userInformation === null && $this->userInformation !== null) {
$this->userInformation->setUser(null);
}
// set the owning side of the relation if necessary
if ($userInformation !== null && $userInformation->getUser() !== $this) {
$userInformation->setUser($this);
}
$this->userInformation = $userInformation;
return $this;
}
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 getFullName(): ?string
{
return $this->firstName . ' ' . $this->lastName;
}
public function getPhone(): ?string
{
return $this->phone;
}
public function setPhone(?string $phone): self
{
$this->phone = $phone;
return $this;
}
public function getGender(): ?string
{
return $this->gender;
}
public function setGender(?string $gender): self
{
$this->gender = $gender;
return $this;
}
// public function isIsDiverse(): ?bool
// {
// return $this->isDiverse;
// }
// public function setIsDiverse(?bool $isDiverse): self
// {
// $this->isDiverse = $isDiverse;
// return $this;
// }
public function getIsDiverse(): ?string
{
return $this->isDiverse;
}
public function setIsDiverse(?string $isDiverse): self
{
$this->isDiverse = $isDiverse;
return $this;
}
/**
* @return Collection<int, OrderDetails>
*/
public function getOrderDetails(): Collection
{
return $this->orderDetails;
}
public function addOrderDetail(OrderDetails $orderDetail): self
{
if (!$this->orderDetails->contains($orderDetail)) {
$this->orderDetails[] = $orderDetail;
$orderDetail->setUser($this);
}
return $this;
}
public function removeOrderDetail(OrderDetails $orderDetail): self
{
if ($this->orderDetails->removeElement($orderDetail)) {
// set the owning side to null (unless already changed)
if ($orderDetail->getUser() === $this) {
$orderDetail->setUser(null);
}
}
return $this;
}
/**
* @return Collection<int, FilmProject>
*/
public function getFilmProjects(): Collection
{
return $this->filmProjects;
}
public function addFilmProject(FilmProject $filmProject): self
{
if (!$this->filmProjects->contains($filmProject)) {
$this->filmProjects[] = $filmProject;
$filmProject->setOwner($this);
}
return $this;
}
public function removeFilmProject(FilmProject $filmProject): self
{
if ($this->filmProjects->removeElement($filmProject)) {
// set the owning side to null (unless already changed)
if ($filmProject->getOwner() === $this) {
$filmProject->setOwner(null);
}
}
return $this;
}
public function isAdmin(): bool
{
$isAdmin = false;
foreach ($this->roles as $role) {
if ($role == 'ROLE_ADMIN') {
$isAdmin = true;
break;
}
}
return $isAdmin;
}
public function isFinanceAdmin(): bool
{
$isFinanceAdmin = false;
foreach ($this->roles as $role) {
if ($role == 'ROLE_FIN_ADMIN') {
$isFinanceAdmin = true;
break;
}
}
return $isFinanceAdmin;
}
public function isFilmmaker(): bool
{
$isFilmmaker = false;
foreach ($this->roles as $role) {
if ($role == Constant::ROLE_FILMMAKER) {
$isFilmmaker = true;
break;
}
}
return $isFilmmaker;
}
/**
* @return Collection<int, UserBilling>
*/
public function getUserBillings(): Collection
{
return $this->userBillings;
}
public function addUserBilling(UserBilling $userBilling): self
{
if (!$this->userBillings->contains($userBilling)) {
$this->userBillings[] = $userBilling;
$userBilling->setUser($this);
}
return $this;
}
public function removeUserBilling(UserBilling $userBilling): self
{
if ($this->userBillings->removeElement($userBilling)) {
// set the owning side to null (unless already changed)
if ($userBilling->getUser() === $this) {
$userBilling->setUser(null);
}
}
return $this;
}
public function getOrganisation(): ?string
{
return $this->organisation;
}
public function setOrganisation(?string $organisation): self
{
$this->organisation = $organisation;
return $this;
}
public function getAreaInterest(): ?array
{
return $this->areaInterest;
}
public function setAreaInterest(?array $areaInterest): self
{
$this->areaInterest = $areaInterest;
return $this;
}
/**
* @return Collection<int, UserCategory>
*/
public function getCategories(): Collection
{
return $this->categories;
}
public function addCategory(UserCategory $category): self
{
if (!$this->categories->contains($category)) {
$this->categories[] = $category;
}
return $this;
}
public function removeCategory(UserCategory $category): self
{
$this->categories->removeElement($category);
return $this;
}
/**
* @return Collection<int, FilmProject>
*/
public function getFollowedFilmProjects(): Collection
{
return $this->followedFilmProjects;
}
public function addFollowedFilmProject(FilmProject $followedFilmProject): self
{
if (!$this->followedFilmProjects->contains($followedFilmProject)) {
$this->followedFilmProjects[] = $followedFilmProject;
}
return $this;
}
public function removeFollowedFilmProject(FilmProject $followedFilmProject): self
{
$this->followedFilmProjects->removeElement($followedFilmProject);
return $this;
}
public function getAccountSalesforceId(): ?string
{
return $this->accountSalesforceId;
}
public function setAccountSalesforceId(?string $accountSalesforceId): self
{
$this->accountSalesforceId = $accountSalesforceId;
return $this;
}
/**
* @return Collection<int, ProjectNotification>
*/
public function getProjectNotifications(): Collection
{
return $this->projectNotifications;
}
public function addProjectNotification(ProjectNotification $projectNotification): self
{
if (!$this->projectNotifications->contains($projectNotification)) {
$this->projectNotifications->add($projectNotification);
$projectNotification->addUser($this);
}
return $this;
}
public function removeProjectNotification(ProjectNotification $projectNotification): self
{
if ($this->projectNotifications->removeElement($projectNotification)) {
$projectNotification->removeUser($this);
}
return $this;
}
public function getIsAborigin(): ?string
{
return $this->isAborigin;
}
public function setIsAborigin(?string $isAborigin): self
{
$this->isAborigin = $isAborigin;
return $this;
}
public function isIsSuccess(): ?bool
{
return $this->isSuccess;
}
public function setIsSuccess(?bool $isSuccess): self
{
$this->isSuccess = $isSuccess;
return $this;
}
public function isIsGuest(): ?bool
{
return $this->isGuest;
}
public function setIsGuest(?bool $isGuest): self
{
$this->isGuest = $isGuest;
return $this;
}
public function getEmailAddress(): ?string
{
return $this->emailAddress;
}
public function setEmailAddress(?string $emailAddress): self
{
$this->emailAddress = $emailAddress;
return $this;
}
public function setFullName(?string $fullName): self
{
$this->fullName = $fullName;
return $this;
}
public function toString() {
if ($this->email) {
return $this->email;
}
return '';
}
public function __toString() {
return $this->toString();
}
}