src/Entity/User.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use App\String\Constant;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use PhpParser\Node\Expr\BinaryOp\BooleanOr;
  9. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  10. use Symfony\Component\Security\Core\User\UserInterface;
  11. #[ORM\Entity(repositoryClassUserRepository::class)]
  12. class User implements UserInterfacePasswordAuthenticatedUserInterface
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column(type'integer')]
  17.     private $id;
  18.     #[ORM\Column(type'string'length180uniquetrue)]
  19.     private $email;
  20.     #[ORM\Column(type'json')]
  21.     private $roles = [];
  22.     #[ORM\Column(type'string')]
  23.     private $password;
  24.     #[ORM\OneToOne(mappedBy'user'targetEntityUserProfile::class, cascade: ['persist''remove'])]
  25.     private $userProfile;
  26.     #[ORM\OneToOne(mappedBy'user'targetEntityUserAddress::class, cascade: ['persist''remove'])]
  27.     private $userAddress;
  28.     #[ORM\OneToOne(mappedBy'user'targetEntityUserInformation::class, cascade: ['persist''remove'])]
  29.     private $userInformation;
  30.     #[ORM\Column(type'string'length255nullabletrue)]
  31.     private $firstName;
  32.     #[ORM\Column(type'string'length255nullabletrue)]
  33.     private $lastName;
  34.     #[ORM\Column(type'string'length255nullabletrue)]
  35.     private $phone;
  36.     #[ORM\Column(type'string'length255nullabletrue)]
  37.     private $gender;
  38.     #[ORM\Column(type'string'length255nullabletrue)]
  39.     private $isDiverse;
  40.     #[ORM\OneToMany(mappedBy'user'targetEntityOrderDetails::class)]
  41.     private $orderDetails;
  42.     #[ORM\OneToMany(mappedBy'owner'targetEntityFilmProject::class)]
  43.     private $filmProjects;
  44.     #[ORM\OneToMany(mappedBy'user'targetEntityUserBilling::class)]
  45.     private $userBillings;
  46.     #[ORM\Column(type'string'length255nullabletrue)]
  47.     private $organisation;
  48.     #[ORM\Column(type'array'nullabletrue)]
  49.     private $areaInterest = [];
  50.     #[ORM\ManyToMany(targetEntityUserCategory::class, inversedBy'users')]
  51.     private $categories;
  52.     #[ORM\ManyToMany(targetEntityFilmProject::class, inversedBy'users')]
  53.     private $followedFilmProjects;
  54.     #[ORM\Column(type'string'length255nullabletrue)]
  55.     private $accountSalesforceId;
  56.     #[ORM\ManyToMany(targetEntityProjectNotification::class, mappedBy'user')]
  57.     private Collection $projectNotifications;
  58.     #[ORM\Column(length255nullabletrue)]
  59.     private ?string $isAborigin null;
  60.     #[ORM\Column(nullabletrue)]
  61.     private ?bool $isSuccess null;
  62.     #[ORM\Column(nullabletrue)]
  63.     private ?bool $isGuest null;
  64.     private ?bool $isAdmin;
  65.     // Honeypot fields
  66.     private ?string $emailAddress null;
  67.     private ?string $fullName null;
  68.     public function __construct()
  69.     {
  70.         $this->orderDetails = new ArrayCollection();
  71.         $this->filmProjects = new ArrayCollection();
  72.         $this->userBillings = new ArrayCollection();
  73.         $this->categories = new ArrayCollection();
  74.         $this->followedFilmProjects = new ArrayCollection();
  75.         $this->projectNotifications = new ArrayCollection();
  76.     }
  77.     public function getId(): ?int
  78.     {
  79.         return $this->id;
  80.     }
  81.     public function getEmail(): ?string
  82.     {
  83.         return $this->email;
  84.     }
  85.     public function setEmail(string $email): self
  86.     {
  87.         $this->email $email;
  88.         return $this;
  89.     }
  90.     /**
  91.      * A visual identifier that represents this user.
  92.      *
  93.      * @see UserInterface
  94.      */
  95.     public function getUserIdentifier(): string
  96.     {
  97.         return (string) $this->email;
  98.     }
  99.     /**
  100.      * @see UserInterface
  101.      */
  102.     public function getRoles(): array
  103.     {
  104.         $roles $this->roles;
  105.         // guarantee every user at least has ROLE_USER
  106.         $roles[] = 'ROLE_USER';
  107.         return array_unique($roles);
  108.     }
  109.     public function setRoles(array $roles): self
  110.     {
  111.         // ALWAYS SET USERPORTAL ROLE
  112.         $roles array_merge($roles, ['ROLE_PORTALUSER']);
  113.         $this->roles $roles;
  114.         
  115.         return $this;
  116.     }
  117.     
  118.     public function setSpecificRoles(array $roles): self
  119.     {
  120.         $this->roles $roles;
  121.         
  122.         return $this;
  123.     }
  124.     
  125.     public function getFullRoles(): ?string
  126.     {
  127.         $roles $this->roles;
  128.         $roles[] = 'ROLE_USER';
  129.         $newRoles = [];
  130.         foreach ($roles as $role) {
  131.             switch ($role) {
  132.                 case 'ROLE_PARTNER'
  133.                     array_push($newRoles'Filmmaker'); break;
  134.                 case 'ROLE_FUNDER':
  135.                     array_push($newRoles'Sponsor'); break; // impact partner
  136.                 case 'ROLE_DONOR':
  137.                     array_push($newRoles'Donor'); break;
  138.                 case 'ROLE_ADMIN':
  139.                     array_push($newRoles'Administrator'); break;
  140.                 case 'ROLE_FIN_ADMIN':
  141.                     array_push($newRoles'Finance Admin'); break;
  142.                 case 'ROLE_DOCUMENTARY_LOVER':
  143.                     array_push($newRoles'Documentary Lover'); break;
  144.             }
  145.         }
  146.         $newRoles array_unique($newRoles);
  147.         return implode(', '$newRoles);
  148.     }
  149.     /**
  150.      * @see PasswordAuthenticatedUserInterface
  151.      */
  152.     public function getPassword(): string
  153.     {
  154.         return $this->password;
  155.     }
  156.     public function setPassword(string $password): self
  157.     {
  158.         $this->password $password;
  159.         return $this;
  160.     }
  161.     /**
  162.      * @see UserInterface
  163.      */
  164.     public function eraseCredentials()
  165.     {
  166.         // If you store any temporary, sensitive data on the user, clear it here
  167.         // $this->plainPassword = null;
  168.     }
  169.     public function getUserProfile(): ?UserProfile
  170.     {
  171.         return $this->userProfile;
  172.     }
  173.     public function setUserProfile(?UserProfile $userProfile): self
  174.     {
  175.         // unset the owning side of the relation if necessary
  176.         if ($userProfile === null && $this->userProfile !== null) {
  177.             $this->userProfile->setUser(null);
  178.         }
  179.         // set the owning side of the relation if necessary
  180.         if ($userProfile !== null && $userProfile->getUser() !== $this) {
  181.             $userProfile->setUser($this);
  182.         }
  183.         $this->userProfile $userProfile;
  184.         return $this;
  185.     }
  186.     public function getUserAddress(): ?UserAddress
  187.     {
  188.         return $this->userAddress;
  189.     }
  190.     public function setUserAddress(?UserAddress $userAddress): self
  191.     {
  192.         // unset the owning side of the relation if necessary
  193.         if ($userAddress === null && $this->userAddress !== null) {
  194.             $this->userAddress->setUser(null);
  195.         }
  196.         // set the owning side of the relation if necessary
  197.         if ($userAddress !== null && $userAddress->getUser() !== $this) {
  198.             $userAddress->setUser($this);
  199.         }
  200.         $this->userAddress $userAddress;
  201.         return $this;
  202.     }
  203.     public function getUserInformation(): ?UserInformation
  204.     {
  205.         return $this->userInformation;
  206.     }
  207.     public function setUserInformation(?UserInformation $userInformation): self
  208.     {
  209.         // unset the owning side of the relation if necessary
  210.         if ($userInformation === null && $this->userInformation !== null) {
  211.             $this->userInformation->setUser(null);
  212.         }
  213.         // set the owning side of the relation if necessary
  214.         if ($userInformation !== null && $userInformation->getUser() !== $this) {
  215.             $userInformation->setUser($this);
  216.         }
  217.         $this->userInformation $userInformation;
  218.         return $this;
  219.     }
  220.     public function getFirstName(): ?string
  221.     {
  222.         return $this->firstName;
  223.     }
  224.     public function setFirstName(?string $firstName): self
  225.     {
  226.         $this->firstName $firstName;
  227.         return $this;
  228.     }
  229.     public function getLastName(): ?string
  230.     {
  231.         return $this->lastName;
  232.     }
  233.     public function setLastName(?string $lastName): self
  234.     {
  235.         $this->lastName $lastName;
  236.         return $this;
  237.     }
  238.     public function getFullName(): ?string
  239.     {
  240.         return $this->firstName ' ' $this->lastName;
  241.     }
  242.     public function getPhone(): ?string
  243.     {
  244.         return $this->phone;
  245.     }
  246.     public function setPhone(?string $phone): self
  247.     {
  248.         $this->phone $phone;
  249.         return $this;
  250.     }
  251.     public function getGender(): ?string
  252.     {
  253.         return $this->gender;
  254.     }
  255.     public function setGender(?string $gender): self
  256.     {
  257.         $this->gender $gender;
  258.         return $this;
  259.     }
  260.     // public function isIsDiverse(): ?bool
  261.     // {
  262.     //     return $this->isDiverse;
  263.     // }
  264.     // public function setIsDiverse(?bool $isDiverse): self
  265.     // {
  266.     //     $this->isDiverse = $isDiverse;
  267.     //     return $this;
  268.     // }
  269.     public function getIsDiverse(): ?string
  270.     {
  271.         return $this->isDiverse;
  272.     }
  273.     public function setIsDiverse(?string $isDiverse): self
  274.     {
  275.         $this->isDiverse $isDiverse;
  276.         return $this;
  277.     }
  278.     /**
  279.      * @return Collection<int, OrderDetails>
  280.      */
  281.     public function getOrderDetails(): Collection
  282.     {
  283.         return $this->orderDetails;
  284.     }
  285.     public function addOrderDetail(OrderDetails $orderDetail): self
  286.     {
  287.         if (!$this->orderDetails->contains($orderDetail)) {
  288.             $this->orderDetails[] = $orderDetail;
  289.             $orderDetail->setUser($this);
  290.         }
  291.         return $this;
  292.     }
  293.     public function removeOrderDetail(OrderDetails $orderDetail): self
  294.     {
  295.         if ($this->orderDetails->removeElement($orderDetail)) {
  296.             // set the owning side to null (unless already changed)
  297.             if ($orderDetail->getUser() === $this) {
  298.                 $orderDetail->setUser(null);
  299.             }
  300.         }
  301.         return $this;
  302.     }
  303.     /**
  304.      * @return Collection<int, FilmProject>
  305.      */
  306.     public function getFilmProjects(): Collection
  307.     {
  308.         return $this->filmProjects;
  309.     }
  310.     public function addFilmProject(FilmProject $filmProject): self
  311.     {
  312.         if (!$this->filmProjects->contains($filmProject)) {
  313.             $this->filmProjects[] = $filmProject;
  314.             $filmProject->setOwner($this);
  315.         }
  316.         return $this;
  317.     }
  318.     public function removeFilmProject(FilmProject $filmProject): self
  319.     {
  320.         if ($this->filmProjects->removeElement($filmProject)) {
  321.             // set the owning side to null (unless already changed)
  322.             if ($filmProject->getOwner() === $this) {
  323.                 $filmProject->setOwner(null);
  324.             }
  325.         }
  326.         return $this;
  327.     }
  328.     public function isAdmin(): bool
  329.     {
  330.         $isAdmin false;
  331.         foreach ($this->roles as $role) {
  332.             if ($role == 'ROLE_ADMIN') {
  333.                 $isAdmin true;
  334.                 break;
  335.             }
  336.         }
  337.         return $isAdmin;
  338.     }
  339.     public function isFinanceAdmin(): bool
  340.     {
  341.         $isFinanceAdmin false;
  342.         foreach ($this->roles as $role) {
  343.             if ($role == 'ROLE_FIN_ADMIN') {
  344.                 $isFinanceAdmin true;
  345.                 break;
  346.             }
  347.         }
  348.         return $isFinanceAdmin;
  349.     }
  350.     public function isFilmmaker(): bool
  351.     {
  352.         $isFilmmaker false;
  353.         foreach ($this->roles as $role) {
  354.             if ($role == Constant::ROLE_FILMMAKER) {
  355.                 $isFilmmaker true;
  356.                 break;
  357.             }
  358.         }
  359.         return $isFilmmaker;
  360.     }
  361.     /**
  362.      * @return Collection<int, UserBilling>
  363.      */
  364.     public function getUserBillings(): Collection
  365.     {
  366.         return $this->userBillings;
  367.     }
  368.     public function addUserBilling(UserBilling $userBilling): self
  369.     {
  370.         if (!$this->userBillings->contains($userBilling)) {
  371.             $this->userBillings[] = $userBilling;
  372.             $userBilling->setUser($this);
  373.         }
  374.         return $this;
  375.     }
  376.     public function removeUserBilling(UserBilling $userBilling): self
  377.     {
  378.         if ($this->userBillings->removeElement($userBilling)) {
  379.             // set the owning side to null (unless already changed)
  380.             if ($userBilling->getUser() === $this) {
  381.                 $userBilling->setUser(null);
  382.             }
  383.         }
  384.         return $this;
  385.     }
  386.     public function getOrganisation(): ?string
  387.     {
  388.         return $this->organisation;
  389.     }
  390.     public function setOrganisation(?string $organisation): self
  391.     {
  392.         $this->organisation $organisation;
  393.         return $this;
  394.     }
  395.     public function getAreaInterest(): ?array
  396.     {
  397.         return $this->areaInterest;
  398.     }
  399.     public function setAreaInterest(?array $areaInterest): self
  400.     {
  401.         $this->areaInterest $areaInterest;
  402.         return $this;
  403.     }
  404.     /**
  405.      * @return Collection<int, UserCategory>
  406.      */
  407.     public function getCategories(): Collection
  408.     {
  409.         return $this->categories;
  410.     }
  411.     public function addCategory(UserCategory $category): self
  412.     {
  413.         if (!$this->categories->contains($category)) {
  414.             $this->categories[] = $category;
  415.         }
  416.         return $this;
  417.     }
  418.     public function removeCategory(UserCategory $category): self
  419.     {
  420.         $this->categories->removeElement($category);
  421.         return $this;
  422.     }
  423.     /**
  424.      * @return Collection<int, FilmProject>
  425.      */
  426.     public function getFollowedFilmProjects(): Collection
  427.     {
  428.         return $this->followedFilmProjects;
  429.     }
  430.     public function addFollowedFilmProject(FilmProject $followedFilmProject): self
  431.     {
  432.         if (!$this->followedFilmProjects->contains($followedFilmProject)) {
  433.             $this->followedFilmProjects[] = $followedFilmProject;
  434.         }
  435.         return $this;
  436.     }
  437.     public function removeFollowedFilmProject(FilmProject $followedFilmProject): self
  438.     {
  439.         $this->followedFilmProjects->removeElement($followedFilmProject);
  440.         return $this;
  441.     }
  442.     public function getAccountSalesforceId(): ?string
  443.     {
  444.         return $this->accountSalesforceId;
  445.     }
  446.     public function setAccountSalesforceId(?string $accountSalesforceId): self
  447.     {
  448.         $this->accountSalesforceId $accountSalesforceId;
  449.         return $this;
  450.     }
  451.     /**
  452.      * @return Collection<int, ProjectNotification>
  453.      */
  454.     public function getProjectNotifications(): Collection
  455.     {
  456.         return $this->projectNotifications;
  457.     }
  458.     public function addProjectNotification(ProjectNotification $projectNotification): self
  459.     {
  460.         if (!$this->projectNotifications->contains($projectNotification)) {
  461.             $this->projectNotifications->add($projectNotification);
  462.             $projectNotification->addUser($this);
  463.         }
  464.         return $this;
  465.     }
  466.     public function removeProjectNotification(ProjectNotification $projectNotification): self
  467.     {
  468.         if ($this->projectNotifications->removeElement($projectNotification)) {
  469.             $projectNotification->removeUser($this);
  470.         }
  471.         return $this;
  472.     }
  473.     public function getIsAborigin(): ?string
  474.     {
  475.         return $this->isAborigin;
  476.     }
  477.     public function setIsAborigin(?string $isAborigin): self
  478.     {
  479.         $this->isAborigin $isAborigin;
  480.         return $this;
  481.     }
  482.     public function isIsSuccess(): ?bool
  483.     {
  484.         return $this->isSuccess;
  485.     }
  486.     public function setIsSuccess(?bool $isSuccess): self
  487.     {
  488.         $this->isSuccess $isSuccess;
  489.         return $this;
  490.     }
  491.     public function isIsGuest(): ?bool
  492.     {
  493.         return $this->isGuest;
  494.     }
  495.     public function setIsGuest(?bool $isGuest): self
  496.     {
  497.         $this->isGuest $isGuest;
  498.         return $this;
  499.     }
  500.     public function getEmailAddress(): ?string
  501.     {
  502.         return $this->emailAddress;
  503.     }
  504.     public function setEmailAddress(?string $emailAddress): self
  505.     {
  506.         $this->emailAddress $emailAddress;
  507.         return $this;
  508.     }
  509.     public function setFullName(?string $fullName): self
  510.     {
  511.         $this->fullName $fullName;
  512.         return $this;
  513.     }
  514.     public function toString() {
  515.         if ($this->email) {
  516.             return $this->email;
  517.         }
  518.         return '';
  519.     }
  520.     public function __toString() {
  521.         return $this->toString();
  522.     }
  523. }