fix: working multi-choice filtering

This commit is contained in:
2025-07-26 10:20:37 -05:00
parent 87e72ec55e
commit f9ec089f8b
10 changed files with 216 additions and 75 deletions

View File

@@ -19,11 +19,11 @@ class SaveUserMediaPreferencesCommand implements CommandInterface
public static function fromUserMediaPreferencesForm(FormInterface $form): self
{
return new static(
resolution: $form->get('resolution')->getData(),
codec: $form->get('codec')->getData(),
quality: $form->get('quality')->getData(),
language: $form->get('language')->getData(),
provider: $form->get('provider')->getData(),
resolution: \implode(',', $form->get('resolution')->getData()),
codec: \implode(',', $form->get('codec')->getData()),
quality: \implode(',', $form->get('quality')->getData()),
language: \implode(',', $form->get('language')->getData()),
provider: \implode(',', $form->get('provider')->getData()),
);
}
}

View File

@@ -6,10 +6,10 @@ class UserPreferences
{
public function __construct(
public readonly ?string $resolution,
public readonly ?string $codec,
public readonly ?string $language,
public readonly ?string $provider,
public readonly ?string $quality,
public readonly ?array $resolution,
public readonly ?array $codec,
public readonly ?array $language,
public readonly ?array $provider,
public readonly ?array $quality,
) {}
}

View File

@@ -27,6 +27,7 @@ class UserPreferencesFactory
if ($value === "") {
return null;
}
$value = explode(',', $value);
return $value;
}
}

View File

@@ -52,8 +52,7 @@ class PreferencesController extends AbstractController
): Response
{
$downloadPreferences = $this->getUser()->getDownloadPreferences();
$formData = (array) UserPreferencesFactory::createFromUser($this->getUser());
$form = $this->createForm(UserMediaPreferencesForm::class, $formData);
$form = $this->createForm(UserMediaPreferencesForm::class);
$form->handleRequest($request);

View File

@@ -10,8 +10,11 @@ use App\User\Database\QualityList;
use App\User\Database\ResolutionList;
use App\User\Framework\Repository\PreferenceOptionRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Event\PreSetDataEvent;
use Symfony\Component\Form\Event\PreSubmitEvent;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Routing\Generator\UrlGenerator;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
@@ -38,6 +41,7 @@ class UserMediaPreferencesForm extends AbstractType
'label_attr' => ['class' => 'w-64 text-white block font-semibold mb-2'],
'choices' => $this->addDefaultChoice($choices),
'required' => false,
'multiple' => true,
];
$builder->add($fieldName, ChoiceType::class, $question);
}