From 7e7526ffdd742ad51f54cdf2eaadfe65aec70a20 Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Tue, 11 Mar 2025 10:47:03 +0100 Subject: [PATCH] Added support entity --- src/Entity/Gateway/Charge.php | 16 +++ src/Entity/Project/Project.php | 37 ++++++ src/Entity/Project/Support.php | 127 +++++++++++++++++++ src/Entity/User/User.php | 38 ++++++ src/Repository/Project/SupportRepository.php | 43 +++++++ 5 files changed, 261 insertions(+) create mode 100644 src/Entity/Project/Support.php create mode 100644 src/Repository/Project/SupportRepository.php diff --git a/src/Entity/Gateway/Charge.php b/src/Entity/Gateway/Charge.php index 131465a..a441bca 100644 --- a/src/Entity/Gateway/Charge.php +++ b/src/Entity/Gateway/Charge.php @@ -5,6 +5,7 @@ namespace App\Entity\Gateway; use App\Entity\Accounting\Accounting; use App\Entity\Accounting\Transaction; use App\Entity\Money; +use App\Entity\Project\Support; use App\Gateway\ChargeType; use App\Mapping\Provider\EntityMapProvider; use App\Repository\Gateway\ChargeRepository; @@ -73,6 +74,9 @@ class Charge #[ORM\ManyToMany(targetEntity: Transaction::class, cascade: ['persist'])] private Collection $transactions; + #[ORM\ManyToOne(inversedBy: 'charges')] + private ?Support $support = null; + public function __construct() { $this->transactions = new ArrayCollection(); @@ -178,4 +182,16 @@ class Charge return $this; } + + public function getSupport(): ?Support + { + return $this->support; + } + + public function setSupport(?Support $support): static + { + $this->support = $support; + + return $this; + } } diff --git a/src/Entity/Project/Project.php b/src/Entity/Project/Project.php index 201f4ba..21a6c90 100644 --- a/src/Entity/Project/Project.php +++ b/src/Entity/Project/Project.php @@ -116,12 +116,19 @@ class Project implements UserOwnedInterface, AccountingOwnerInterface, Localized #[ORM\OneToMany(targetEntity: Update::class, mappedBy: 'project', cascade: ['persist'])] private Collection $updates; + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: Support::class, mappedBy: 'project')] + private Collection $supports; + public function __construct() { $this->accounting = Accounting::of($this); $this->rewards = new ArrayCollection(); $this->budgetItems = new ArrayCollection(); $this->updates = new ArrayCollection(); + $this->supports = new ArrayCollection(); } public function getId(): ?int @@ -345,4 +352,34 @@ class Project implements UserOwnedInterface, AccountingOwnerInterface, Localized return $this; } + + /** + * @return Collection + */ + public function getSupports(): Collection + { + return $this->supports; + } + + public function addSupport(Support $support): static + { + if (!$this->supports->contains($support)) { + $this->supports->add($support); + $support->setProject($this); + } + + return $this; + } + + public function removeSupport(Support $support): static + { + if ($this->supports->removeElement($support)) { + // set the owning side to null (unless already changed) + if ($support->getProject() === $this) { + $support->setProject(null); + } + } + + return $this; + } } diff --git a/src/Entity/Project/Support.php b/src/Entity/Project/Support.php new file mode 100644 index 0000000..ace2d74 --- /dev/null +++ b/src/Entity/Project/Support.php @@ -0,0 +1,127 @@ + + */ + #[ORM\OneToMany(targetEntity: Charge::class, mappedBy: 'support')] + private Collection $charges; + + #[ORM\Column(length: 255, nullable: true)] + private ?string $message = null; + + #[ORM\Column] + private ?bool $anonymours = null; + + public function __construct() + { + $this->charges = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getOwner(): ?User + { + return $this->owner; + } + + public function setOwner(?User $owner): static + { + $this->owner = $owner; + + return $this; + } + + public function getProject(): ?Project + { + return $this->project; + } + + public function setProject(?Project $project): static + { + $this->project = $project; + + return $this; + } + + /** + * @return Collection + */ + public function getCharges(): Collection + { + return $this->charges; + } + + public function addCharge(Charge $charge): static + { + if (!$this->charges->contains($charge)) { + $this->charges->add($charge); + $charge->setSupport($this); + } + + return $this; + } + + public function removeCharge(Charge $charge): static + { + if ($this->charges->removeElement($charge)) { + // set the owning side to null (unless already changed) + if ($charge->getSupport() === $this) { + $charge->setSupport(null); + } + } + + return $this; + } + + public function getMessage(): ?string + { + return $this->message; + } + + public function setMessage(?string $message): static + { + $this->message = $message; + + return $this; + } + + public function isAnonymours(): ?bool + { + return $this->anonymours; + } + + public function setAnonymours(bool $anonymours): static + { + $this->anonymours = $anonymours; + + return $this; + } +} diff --git a/src/Entity/User/User.php b/src/Entity/User/User.php index 3e12ccc..34c03f9 100644 --- a/src/Entity/User/User.php +++ b/src/Entity/User/User.php @@ -5,6 +5,7 @@ namespace App\Entity\User; use App\Entity\Accounting\Accounting; use App\Entity\Interface\AccountingOwnerInterface; use App\Entity\Project\Project; +use App\Entity\Project\Support; use App\Entity\Trait\MigratedEntity; use App\Entity\Trait\TimestampedCreationEntity; use App\Entity\Trait\TimestampedUpdationEntity; @@ -111,6 +112,12 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, Account #[ORM\Column(type: Types::TEXT, nullable: true)] private ?string $avatar = null; + /** + * @var Collection + */ + #[ORM\OneToMany(targetEntity: Support::class, mappedBy: 'owner')] + private Collection $supports; + public function __construct() { $this->accounting = Accounting::of($this); @@ -121,6 +128,7 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, Account $this->emailConfirmed = false; $this->active = false; + $this->supports = new ArrayCollection(); } public function getId(): ?int @@ -369,4 +377,34 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface, Account return $this; } + + /** + * @return Collection + */ + public function getSupports(): Collection + { + return $this->supports; + } + + public function addSupport(Support $support): static + { + if (!$this->supports->contains($support)) { + $this->supports->add($support); + $support->setOwner($this); + } + + return $this; + } + + public function removeSupport(Support $support): static + { + if ($this->supports->removeElement($support)) { + // set the owning side to null (unless already changed) + if ($support->getOwner() === $this) { + $support->setOwner(null); + } + } + + return $this; + } } diff --git a/src/Repository/Project/SupportRepository.php b/src/Repository/Project/SupportRepository.php new file mode 100644 index 0000000..0013a04 --- /dev/null +++ b/src/Repository/Project/SupportRepository.php @@ -0,0 +1,43 @@ + + */ +class SupportRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Support::class); + } + + // /** + // * @return Support[] Returns an array of Support objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('s') + // ->andWhere('s.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('s.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Support + // { + // return $this->createQueryBuilder('s') + // ->andWhere('s.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +}