diff --git a/README.md b/README.md index 00e74a1..0e12a12 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,13 @@ The elasticsearch index must be build: The import from rebrickable may complete with the message "Done with X errors.". This is normal. Most probably some parts/sets are faulty and haven't be imported. +## Added Features +app/config/config.yml + +`app.show_only_themes_containing_sets: true` + +If this is set to true, only themes are visible in the drop down, that have sets in it. + --- From this point on, the original Readme text: diff --git a/app/config/services.yml b/app/config/services.yml index 9987126..aea4f89 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -36,6 +36,9 @@ services: arguments: $cache: '@app.brickset.cache_provider' + FrontBundle\Form\Search\SetSearchType: + arguments: + $showOnlyThemesContainingSets: %app.show_only_themes_containing_sets% # Filesystem diff --git a/src/AppBundle/Repository/Rebrickable/ThemeRepository.php b/src/AppBundle/Repository/Rebrickable/ThemeRepository.php index 11b0d88..5fbae88 100644 --- a/src/AppBundle/Repository/Rebrickable/ThemeRepository.php +++ b/src/AppBundle/Repository/Rebrickable/ThemeRepository.php @@ -6,4 +6,8 @@ use AppBundle\Repository\BaseRepository; class ThemeRepository extends BaseRepository { + public function findAll() + { + return $this->findBy(array(), array('name' => 'ASC')); + } } diff --git a/src/FrontBundle/Form/Search/SetSearchType.php b/src/FrontBundle/Form/Search/SetSearchType.php index 9dcf960..cabeac3 100644 --- a/src/FrontBundle/Form/Search/SetSearchType.php +++ b/src/FrontBundle/Form/Search/SetSearchType.php @@ -23,19 +23,32 @@ class SetSearchType extends AbstractType /** @var SetRepository */ private $setRepository; + private $showOnlyThemesContainingSets; + /** * SetSearchType constructor. * * @param EntityManagerInterface $em */ - public function __construct(EntityManagerInterface $em) + public function __construct(EntityManagerInterface $em, bool $showOnlyThemesContainingSets) { $this->themeRepository = $em->getRepository(Theme::class); $this->setRepository = $em->getRepository(Set::class); + $this->showOnlyThemesContainingSets = $showOnlyThemesContainingSets; } public function buildForm(FormBuilderInterface $builder, array $options) { + $themes = $this->themeRepository->findAll(); + if($this->showOnlyThemesContainingSets) { + $tmp = $themes; + foreach($tmp as $k => $theme) { + if($theme->getSets()->count() == 0) { + unset($themes[$k]); + } + } + } + $builder ->add('query', TextType::class, [ 'required' => false, @@ -64,7 +77,7 @@ class SetSearchType extends AbstractType ]) ->add('theme', ChoiceType::class, [ 'label' => 'set.form.theme', - 'choices' => $this->themeRepository->findAll(), + 'choices' => $themes, 'choice_label' => 'fullName', 'choice_translation_domain' => false, 'group_by' => function ($theme, $key, $index) {