From 827126b02bf441b8819ca98088b15f80d2183290 Mon Sep 17 00:00:00 2001 From: Veelkoov Date: Sun, 12 Apr 2026 11:59:01 +0200 Subject: [PATCH] WIP --- .../FiltersValidChoicesFilter.php | 2 +- src/Form/InclusionUpdate/Data.php | 1 - src/Repository/CreatorRepository.php | 15 +++++++++------ src/Service/DataService.php | 5 +++-- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/Filtering/RequestsHandling/FiltersValidChoicesFilter.php b/src/Filtering/RequestsHandling/FiltersValidChoicesFilter.php index 12dd5c6fc..f9ac21bbe 100644 --- a/src/Filtering/RequestsHandling/FiltersValidChoicesFilter.php +++ b/src/Filtering/RequestsHandling/FiltersValidChoicesFilter.php @@ -26,7 +26,7 @@ public function getOnlyValidChoices(Choices $choices): Choices $countries = self::onlyValidValues($choices->countries, $this->dataService->getCountries(), Consts::FILTER_VALUE_UNKNOWN); $states = self::onlyValidValues($choices->states, - $this->dataService->getStates(), Consts::FILTER_VALUE_UNKNOWN); + $this->dataService->getStates(), Consts::FILTER_VALUE_UNKNOWN); // FIXME: Allow Other which will match anything outside US/CA $languages = self::onlyValidValues($choices->languages, $this->dataService->getLanguages(), Consts::FILTER_VALUE_UNKNOWN); diff --git a/src/Form/InclusionUpdate/Data.php b/src/Form/InclusionUpdate/Data.php index 9a0f70056..2361a159f 100644 --- a/src/Form/InclusionUpdate/Data.php +++ b/src/Form/InclusionUpdate/Data.php @@ -81,7 +81,6 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ]) ->add('state', TextType::class, [ 'label' => 'State', - 'help' => 'Only for the US and Canada, otherwise please leave empty.', 'required' => false, 'empty_data' => '', ]) diff --git a/src/Repository/CreatorRepository.php b/src/Repository/CreatorRepository.php index 1c1611857..4c589cf65 100644 --- a/src/Repository/CreatorRepository.php +++ b/src/Repository/CreatorRepository.php @@ -196,14 +196,17 @@ public function getDistinctCountries(): StringSet return new StringSet($result); // @phpstan-ignore argument.type (Lack of skill to fix this) } - public function getDistinctStates(): StringSet + public function getDistinctStates(StringSet $fromCountries = new StringSet()): StringSet { - $result = $this->createQueryBuilder('d_c') - ->select('DISTINCT d_c.state') - ->getQuery() - ->getSingleColumnResult(); + $builder = $this->createQueryBuilder('d_c')->select('DISTINCT d_c.state'); - return new StringSet($result); // @phpstan-ignore argument.type (Lack of skill to fix this) + if ($fromCountries->isNotEmpty()) { + $builder->where('d_c.country IN (:countries)')->setParameter('countries', $fromCountries); + } + + $result = $builder->getQuery()->getSingleColumnResult(); + + return new StringSet($result); } public function getActiveOffersPaymentPlansStats(): NullBoolToInt diff --git a/src/Service/DataService.php b/src/Service/DataService.php index 20928ecb9..b00c37351 100644 --- a/src/Service/DataService.php +++ b/src/Service/DataService.php @@ -76,9 +76,10 @@ public function getCountries(): StringSet return $this->cache->get(fn () => $this->creatorRepository->getDistinctCountries(), CacheTags::CREATORS, __METHOD__); } - public function getStates(): StringSet + public function getStates(): StringSet // FIXME: Parametrize (and improve cache keys) or rename { - return $this->cache->get(fn () => $this->creatorRepository->getDistinctStates(), CacheTags::CREATORS, __METHOD__); + return $this->cache->get(fn () => $this->creatorRepository->getDistinctStates(StringSet::of('CA', 'US')), + CacheTags::CREATORS, __METHOD__); } public function getOpenFor(): StringSet