src/Entity/User.php line 16

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\UserRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
  9. use Symfony\Component\Security\Core\User\UserInterface;
  10. #[ORM\Entity(repositoryClassUserRepository::class)]
  11. #[ORM\Table(name'`user`')]
  12. #[UniqueEntity(fields: ['email'], message'An account with this email already exists. Please log in instead.')]
  13. class User implements UserInterfacePasswordAuthenticatedUserInterface
  14. {
  15.     const ROLE_USER 'ROLE_USER';
  16.     const ROLE_ADMIN 'ROLE_ADMIN';
  17.     const VALIDITY_IN_DAYS 730;
  18.     const REJECT_REASON_INVALID_IDENTITY 'II';
  19.     const REJECT_REASON_MEMBERSHIP_FEE_NOT_RECEIVED 'MN';
  20.     #[ORM\Id]
  21.     #[ORM\GeneratedValue]
  22.     #[ORM\Column]
  23.     private ?int $id null;
  24.     #[ORM\Column(length180uniquetrue)]
  25.     private ?string $email null;
  26.     #[ORM\Column]
  27.     private array $roles = [];
  28.     /**
  29.      * @var string The hashed password
  30.      */
  31.     #[ORM\Column]
  32.     private ?string $password null;
  33.     #[ORM\Column(length255)]
  34.     private ?string $firstName null;
  35.     #[ORM\Column(length255nullabletrue)]
  36.     private ?string $lastName null;
  37.     #[ORM\Column(length255nullabletrue)]
  38.     private ?string $address null;
  39.     #[ORM\Column(length255nullabletrue)]
  40.     private ?string $phoneNo null;
  41.     #[ORM\OneToMany(mappedBy'user'targetEntityUserImage::class, orphanRemovaltrue)]
  42.     #@ORM\JoinColumn(name="id", referencedColumnName="user_id")
  43.     private Collection $userImages;
  44.     #[ORM\ManyToOne(inversedBy'users'fetch:"EAGER")]
  45.     #[ORM\JoinColumn(name:"user_status_code"referencedColumnName"user_status_code"nullablefalse)]
  46.     private ?UserStatus $userStatus null;
  47.     #[ORM\Column(length2nullabletrue)]
  48.     private ?string $gender null;
  49.     #[ORM\OneToOne(mappedBy'user'fetch:"EAGER"cascade: ['persist''remove'])]
  50.     private ?UserDetail $userDetail null;
  51.     #[ORM\OneToMany(mappedBy'user'targetEntityTeamMember::class)]
  52.     private Collection $teamMembers;
  53.     #[ORM\OneToMany(mappedBy'user'targetEntityUserInvoice::class)]
  54.     private Collection $userInvoices;
  55.     #[ORM\Column(type:"datetime"nullable:true)]
  56.     private $createdAt;
  57.     #[ORM\Column(type:"datetime"nullable:true)]
  58.     private $approvedAt;
  59.     #[ORM\Column(type:"datetime"nullable:true)]
  60.     private $validAt;
  61.     #[ORM\OneToMany(mappedBy'user'targetEntityEmailArchive::class)]
  62.     private Collection $emailArchives;
  63.     #[ORM\OneToMany(mappedBy'user'targetEntityPayment::class)]
  64.     private Collection $payments;
  65.     #[ORM\OneToMany(mappedBy'user'targetEntityPartyPillar::class)]
  66.     private Collection $partyPillars;
  67.     #[ORM\OneToMany(mappedBy'user'targetEntityDonation::class)]
  68.     private Collection $donations;
  69.     public function __construct()
  70.     {
  71.         $this->userImages = new ArrayCollection();
  72.         $this->teamMembers = new ArrayCollection();
  73.         $this->userInvoices = new ArrayCollection();
  74.         $this->emailArchives = new ArrayCollection();
  75.         $this->payments = new ArrayCollection();
  76.         $this->partyPillars = new ArrayCollection();
  77.         $this->donations = new ArrayCollection();
  78.     }
  79.     public function getId(): ?int
  80.     {
  81.         return $this->id;
  82.     }
  83.     public function getEmail(): ?string
  84.     {
  85.         return $this->email;
  86.     }
  87.     public function setEmail(string $email): self
  88.     {
  89.         $this->email $email;
  90.         return $this;
  91.     }
  92.     /**
  93.      * A visual identifier that represents this user.
  94.      *
  95.      * @see UserInterface
  96.      */
  97.     public function getUserIdentifier(): string
  98.     {
  99.         return (string) $this->email;
  100.     }
  101.     /**
  102.      * @see UserInterface
  103.      */
  104.     public function getRoles(): array
  105.     {
  106.         $roles $this->roles;
  107.         // guarantee every user at least has ROLE_USER
  108.         $roles[] = 'ROLE_USER';
  109.         return array_unique($roles);
  110.     }
  111.     public function setRoles(array $roles): self
  112.     {
  113.         $this->roles = (!empty($roles)) ?? self::ROLE_USER ;
  114.         return $this;
  115.     }
  116.     /**
  117.      * @see PasswordAuthenticatedUserInterface
  118.      */
  119.     public function getPassword(): string
  120.     {
  121.         return $this->password;
  122.     }
  123.     public function setPassword(string $password): self
  124.     {
  125.         $this->password $password;
  126.         return $this;
  127.     }
  128.     /**
  129.      * @see UserInterface
  130.      */
  131.     public function eraseCredentials()
  132.     {
  133.         // If you store any temporary, sensitive data on the user, clear it here
  134.         // $this->plainPassword = null;
  135.     }
  136.     public function getFirstName(): ?string
  137.     {
  138.         return $this->firstName;
  139.     }
  140.     public function setFirstName(string $firstName): self
  141.     {
  142.         $this->firstName $firstName;
  143.         return $this;
  144.     }
  145.     public function getLastName(): ?string
  146.     {
  147.         return $this->lastName;
  148.     }
  149.     public function setLastName(?string $lastName): self
  150.     {
  151.         $this->lastName $lastName;
  152.         return $this;
  153.     }
  154.     public function getAddress(): ?string
  155.     {
  156.         return $this->address;
  157.     }
  158.     public function setAddress(?string $address): self
  159.     {
  160.         $this->address $address;
  161.         return $this;
  162.     }
  163.     public function getPhoneNo(): ?string
  164.     {
  165.         return $this->phoneNo;
  166.     }
  167.     public function setPhoneNo(?string $phoneNo): self
  168.     {
  169.         $this->phoneNo $phoneNo;
  170.         return $this;
  171.     }
  172.     /**
  173.      * @return Collection<int, UserImage>
  174.      */
  175.     public function getUserImages(): Collection
  176.     {
  177.         return $this->userImages;
  178.     }
  179.     public function getUserImagesByuserImageTypeCode(string $userImageTypeCode){
  180.         if (!empty($this->userImages)){
  181.             foreach($this->getUserImages() as $userImage){
  182.                 if($userImage->getUserImageType()->getUserImageTypeCode() != $userImageTypeCode){
  183.                     continue;
  184.                 }
  185.                 return $userImage;
  186.             }
  187.         }
  188.         return null;
  189.     }
  190.     public function getUserInvoiceByImageMetadata(?ImageMetadata $imageMetadata){
  191.         if (!empty($this->userInvoices)){
  192.             foreach($this->getUserInvoices() as $userInvoice){
  193.                 if($userInvoice->getInvoice()->getImageMetadata()->getImageMetadataUid() != $imageMetadata->getImageMetadataUid()){
  194.                     continue;
  195.                 }
  196.                 return $userInvoice;
  197.             }
  198.         }
  199.         return null;
  200.     }
  201. //    public function addUserImageTypeCode(UserImage $userImageTypeCode): self
  202. //    {
  203. //        if (!$this->userImages->contains($userImageTypeCode)) {
  204. //            $this->userImages->add($userImageTypeCode);
  205. //            $userImageTypeCode->setUser($this);
  206. //        }
  207. //
  208. //        return $this;
  209. //    }
  210. //
  211. //    public function removeUserImageTypeCode(UserImage $userImageTypeCode): self
  212. //    {
  213. //        if ($this->userImages->removeElement($userImageTypeCode)) {
  214. //            // set the owning side to null (unless already changed)
  215. //            if ($userImageTypeCode->getUser() === $this) {
  216. //                $userImageTypeCode->setUser(null);
  217. //            }
  218. //        }
  219. //
  220. //        return $this;
  221. //    }
  222.     public function getUserStatus(): ?UserStatus
  223.     {
  224.         return $this->userStatus;
  225.     }
  226.     public function setUserStatus(?UserStatus $userStatus): static
  227.     {
  228.         $this->userStatus $userStatus;
  229.         return $this;
  230.     }
  231.     public function getGender(): ?string
  232.     {
  233.         return $this->gender;
  234.     }
  235.     public function setGender(?string $gender): static
  236.     {
  237.         $this->gender $gender;
  238.         return $this;
  239.     }
  240.     public function getUserDetail(): ?UserDetail
  241.     {
  242.         return $this->userDetail;
  243.     }
  244.     public function setUserDetail(?UserDetail $userDetail): static
  245.     {
  246.         // unset the owning side of the relation if necessary
  247.         if ($userDetail === null && $this->userDetail !== null) {
  248.             $this->userDetail->setUser(null);
  249.         }
  250.         // set the owning side of the relation if necessary
  251.         if ($userDetail !== null && $userDetail->getUser() !== $this) {
  252.             $userDetail->setUser($this);
  253.         }
  254.         $this->userDetail $userDetail;
  255.         return $this;
  256.     }
  257.     /**
  258.      * @return Collection<int, TeamMember>
  259.      */
  260.     public function getTeamMembers(): Collection
  261.     {
  262.         return $this->teamMembers;
  263.     }
  264.     public function getDisplayTeamMember():string {
  265.         foreach ($this->teamMembers as $teamMember){
  266.             return $teamMember->getDesignation()->getName(); //Fixme: TBD designation priority order
  267.         }
  268.         return "General Member";
  269.     }
  270.     public function addTeamMember(TeamMember $teamMember): static
  271.     {
  272.         if (!$this->teamMembers->contains($teamMember)) {
  273.             $this->teamMembers->add($teamMember);
  274.             $teamMember->setUser($this);
  275.         }
  276.         return $this;
  277.     }
  278.     public function removeTeamMember(TeamMember $teamMember): static
  279.     {
  280.         if ($this->teamMembers->removeElement($teamMember)) {
  281.             // set the owning side to null (unless already changed)
  282.             if ($teamMember->getUser() === $this) {
  283.                 $teamMember->setUser(null);
  284.             }
  285.         }
  286.         return $this;
  287.     }
  288.     /**
  289.      * @return Collection<int, UserInvoice>
  290.      */
  291.     public function getUserInvoices(): Collection
  292.     {
  293.         return $this->userInvoices;
  294.     }
  295.     public function addUserInvoice(UserInvoice $userInvoice): static
  296.     {
  297.         if (!$this->userInvoices->contains($userInvoice)) {
  298.             $this->userInvoices->add($userInvoice);
  299.             $userInvoice->setUser($this);
  300.         }
  301.         return $this;
  302.     }
  303.     public function removeUserInvoice(UserInvoice $userInvoice): static
  304.     {
  305.         if ($this->userInvoices->removeElement($userInvoice)) {
  306.             // set the owning side to null (unless already changed)
  307.             if ($userInvoice->getUser() === $this) {
  308.                 $userInvoice->setUser(null);
  309.             }
  310.         }
  311.         return $this;
  312.     }
  313.     /**
  314.      * @return \DateTimeInterface
  315.      */
  316.     public function getCreatedAt(): ?\DateTimeInterface
  317.     {
  318.         return $this->createdAt;
  319.     }
  320.     /**
  321.      * @param mixed $createdAt
  322.      */
  323.     public function setCreatedAt(? \DateTimeInterface $createdAt): self
  324.     {
  325.         $this->createdAt $createdAt;
  326.         return $this;
  327.     }
  328.     /**
  329.      * @return mixed
  330.      */
  331.     public function getApprovedAt(): ?\DateTimeInterface
  332.     {
  333.         return $this->approvedAt;
  334.     }
  335.     /**
  336.      * @param mixed $approvedAt
  337.      */
  338.     public function setApprovedAt(?\DateTimeInterface $approvedAt): self
  339.     {
  340.         $this->approvedAt $approvedAt;
  341.         return $this;
  342.     }
  343.     /**
  344.      * @return mixed
  345.      */
  346.     public function getValidAt(): ?\DateTimeInterface
  347.     {
  348.         return $this->validAt;
  349.     }
  350.     /**
  351.      * @param mixed $validAt
  352.      */
  353.     public function setValidAt($validAt): self
  354.     {
  355.         $this->validAt $validAt;
  356.         return $this;
  357.     }
  358.     /**
  359.      * @return Collection<int, EmailArchive>
  360.      */
  361.     public function getEmailArchives(): Collection
  362.     {
  363.         return $this->emailArchives;
  364.     }
  365.     public function addEmailArchive(EmailArchive $emailArchive): static
  366.     {
  367.         if (!$this->emailArchives->contains($emailArchive)) {
  368.             $this->emailArchives->add($emailArchive);
  369.             $emailArchive->setUser($this);
  370.         }
  371.         return $this;
  372.     }
  373.     public function removeEmailArchive(EmailArchive $emailArchive): static
  374.     {
  375.         if ($this->emailArchives->removeElement($emailArchive)) {
  376.             // set the owning side to null (unless already changed)
  377.             if ($emailArchive->getUser() === $this) {
  378.                 $emailArchive->setUser(null);
  379.             }
  380.         }
  381.         return $this;
  382.     }
  383.     /**
  384.      * @return Collection<int, Payment>
  385.      */
  386.     public function getPayments(): Collection
  387.     {
  388.         return $this->payments;
  389.     }
  390.     public function addPayment(Payment $payment): static
  391.     {
  392.         if (!$this->payments->contains($payment)) {
  393.             $this->payments->add($payment);
  394.             $payment->setUser($this);
  395.         }
  396.         return $this;
  397.     }
  398.     public function removePayment(Payment $payment): static
  399.     {
  400.         if ($this->payments->removeElement($payment)) {
  401.             // set the owning side to null (unless already changed)
  402.             if ($payment->getUser() === $this) {
  403.                 $payment->setUser(null);
  404.             }
  405.         }
  406.         return $this;
  407.     }
  408.     /**
  409.      * @return Collection<int, PartyPillar>
  410.      */
  411.     public function getPartyPillars(): Collection
  412.     {
  413.         return $this->partyPillars;
  414.     }
  415.     public function addPartyPillar(PartyPillar $partyPillar): static
  416.     {
  417.         if (!$this->partyPillars->contains($partyPillar)) {
  418.             $this->partyPillars->add($partyPillar);
  419.             $partyPillar->setUser($this);
  420.         }
  421.         return $this;
  422.     }
  423.     public function removePartyPillar(PartyPillar $partyPillar): static
  424.     {
  425.         if ($this->partyPillars->removeElement($partyPillar)) {
  426.             // set the owning side to null (unless already changed)
  427.             if ($partyPillar->getUser() === $this) {
  428.                 $partyPillar->setUser(null);
  429.             }
  430.         }
  431.         return $this;
  432.     }
  433.     public function isPaidstring $paymentType):?int {
  434.         foreach($this->getPayments() as $payment){
  435.             if(
  436.                 $payment->getPaymentType()->getPaymentTypeCode() == $paymentType
  437.                 && $payment->getPaymentStatus()->getPaymentStatusCode() == PaymentStatus::STATUS_PAID
  438.             ){
  439.                 return $payment->getPaymentId();
  440.             }
  441.         }
  442.         return null;
  443.     }
  444.     /**
  445.      * @return Collection<int, Donation>
  446.      */
  447.     public function getDonations(): Collection
  448.     {
  449.         return $this->donations;
  450.     }
  451.     public function addDonation(Donation $donation): static
  452.     {
  453.         if (!$this->donations->contains($donation)) {
  454.             $this->donations->add($donation);
  455.             $donation->setUser($this);
  456.         }
  457.         return $this;
  458.     }
  459.     public function removeDonation(Donation $donation): static
  460.     {
  461.         if ($this->donations->removeElement($donation)) {
  462.             // set the owning side to null (unless already changed)
  463.             if ($donation->getUser() === $this) {
  464.                 $donation->setUser(null);
  465.             }
  466.         }
  467.         return $this;
  468.     }
  469. }