diff --git a/src/Filtering/RequestsHandling/FiltersValidChoicesFilter.php b/src/Filtering/RequestsHandling/FiltersValidChoicesFilter.php index 12dd5c6f..f9ac21bb 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 a80251e2..98d793b4 100644 --- a/src/Form/InclusionUpdate/Data.php +++ b/src/Form/InclusionUpdate/Data.php @@ -80,7 +80,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 5729f436..1eb46e11 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 20928ecb..b00c3735 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