From 91ec009afa7b82fc0bf0b984974d9350d1cbde16 Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Wed, 18 Dec 2024 15:51:17 +0100 Subject: [PATCH] Add match call entity --- src/Entity/Accounting/Accounting.php | 25 ++++ src/Entity/Matchfunding/MatchCall.php | 129 ++++++++++++++++++ .../MatchStrategy/MatchStrategyLocator.php | 7 + .../Matchfunding/MatchCallRepository.php | 43 ++++++ 4 files changed, 204 insertions(+) create mode 100644 src/Entity/Matchfunding/MatchCall.php create mode 100644 src/Repository/Matchfunding/MatchCallRepository.php diff --git a/src/Entity/Accounting/Accounting.php b/src/Entity/Accounting/Accounting.php index 241069d..a4fb6d0 100644 --- a/src/Entity/Accounting/Accounting.php +++ b/src/Entity/Accounting/Accounting.php @@ -3,6 +3,7 @@ namespace App\Entity\Accounting; use App\Entity\Interface\AccountingOwnerInterface; +use App\Entity\Matchfunding\MatchCall; use App\Entity\Project\Project; use App\Entity\Tipjar; use App\Entity\User\User; @@ -43,6 +44,9 @@ class Accounting #[ORM\OneToOne(mappedBy: 'accounting', cascade: ['persist'])] private ?Tipjar $tipjar = null; + #[ORM\OneToOne(mappedBy: 'accounting', cascade: ['persist'])] + private ?MatchCall $matchCall = null; + /** * Create a new Accounting entity instance for the given owner. */ @@ -101,6 +105,8 @@ class Accounting return $this->getProject(); case Tipjar::class: return $this->getTipjar(); + case MatchCall::class: + return $this->getMatchCall(); } return null; @@ -121,6 +127,8 @@ class Accounting return $this->setProject($owner); case Tipjar::class: return $this->setTipjar($owner); + case MatchCall::class: + return $this->setMatchCall($owner); } return $this; @@ -191,4 +199,21 @@ class Accounting return $this; } + + public function getMatchCall(): ?MatchCall + { + return $this->matchCall; + } + + public function setMatchCall(MatchCall $matchCall): static + { + // set the owning side of the relation if necessary + if ($matchCall->getAccounting() !== $this) { + $matchCall->setAccounting($this); + } + + $this->matchCall = $matchCall; + + return $this; + } } diff --git a/src/Entity/Matchfunding/MatchCall.php b/src/Entity/Matchfunding/MatchCall.php new file mode 100644 index 0000000..dd770df --- /dev/null +++ b/src/Entity/Matchfunding/MatchCall.php @@ -0,0 +1,129 @@ + + */ + #[ORM\ManyToMany(targetEntity: User::class)] + private Collection $managers; + + /** + * @var Collection + */ + #[ORM\OneToMany(mappedBy: 'matchCall', targetEntity: MatchSubmission::class)] + private Collection $matchSubmissions; + + #[ORM\Column(length: 255)] + private ?string $strategyName = null; + + public function __construct() + { + $this->accounting = Accounting::of($this); + $this->managers = new ArrayCollection(); + $this->matchSubmissions = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getAccounting(): ?Accounting + { + return $this->accounting; + } + + public function setAccounting(Accounting $accounting): static + { + $this->accounting = $accounting; + + return $this; + } + + /** + * @return Collection + */ + public function getManagers(): Collection + { + return $this->managers; + } + + public function addManager(User $manager): static + { + if (!$this->managers->contains($manager)) { + $this->managers->add($manager); + } + + return $this; + } + + public function removeManager(User $manager): static + { + $this->managers->removeElement($manager); + + return $this; + } + + /** + * @return Collection + */ + public function getMatchSubmissions(): Collection + { + return $this->matchSubmissions; + } + + public function addMatchSubmission(MatchSubmission $submission): static + { + if (!$this->matchSubmissions->contains($submission)) { + $this->matchSubmissions->add($submission); + $submission->setMatchCall($this); + } + + return $this; + } + + public function removeMatchSubmission(MatchSubmission $submission): static + { + if ($this->matchSubmissions->removeElement($submission)) { + // set the owning side to null (unless already changed) + if ($submission->getMatchCall() === $this) { + $submission->setMatchCall(null); + } + } + + return $this; + } + + public function getStrategyName(): ?string + { + return $this->strategyName; + } + + public function setStrategyName(string $strategyName): static + { + $this->strategyName = $strategyName; + + return $this; + } +} diff --git a/src/Matchfunding/MatchStrategy/MatchStrategyLocator.php b/src/Matchfunding/MatchStrategy/MatchStrategyLocator.php index 34a7d3b..bda41f9 100644 --- a/src/Matchfunding/MatchStrategy/MatchStrategyLocator.php +++ b/src/Matchfunding/MatchStrategy/MatchStrategyLocator.php @@ -2,6 +2,8 @@ namespace App\Matchfunding\MatchStrategy; +use App\Entity\Matchfunding\MatchCall; + class MatchStrategyLocator { /** @var array */ @@ -36,4 +38,9 @@ class MatchStrategyLocator return $this->strategiesByName[$strategyName]; } + + public function getForCall(MatchCall $call): ?MatchStrategyInterface + { + return $this->get($call->getStrategyName()); + } } diff --git a/src/Repository/Matchfunding/MatchCallRepository.php b/src/Repository/Matchfunding/MatchCallRepository.php new file mode 100644 index 0000000..15534cf --- /dev/null +++ b/src/Repository/Matchfunding/MatchCallRepository.php @@ -0,0 +1,43 @@ + + */ +class MatchCallRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, MatchCall::class); + } + +// /** +// * @return MatchCall[] Returns an array of MatchCall objects +// */ +// public function findByExampleField($value): array +// { +// return $this->createQueryBuilder('m') +// ->andWhere('m.exampleField = :val') +// ->setParameter('val', $value) +// ->orderBy('m.id', 'ASC') +// ->setMaxResults(10) +// ->getQuery() +// ->getResult() +// ; +// } + +// public function findOneBySomeField($value): ?MatchCall +// { +// return $this->createQueryBuilder('m') +// ->andWhere('m.exampleField = :val') +// ->setParameter('val', $value) +// ->getQuery() +// ->getOneOrNullResult() +// ; +// } +}