Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
1 change: 0 additions & 1 deletion src/Form/InclusionUpdate/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '',
])
Expand Down
15 changes: 9 additions & 6 deletions src/Repository/CreatorRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/Service/DataService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down