fix: removes preference options db table

This commit is contained in:
2025-07-24 00:02:38 -05:00
parent 0988517bd0
commit 2a9bacea8c
6 changed files with 106 additions and 17 deletions

View File

@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250724042107 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
ALTER TABLE preference_option DROP FOREIGN KEY FK_607C52FD81022C0
SQL);
$this->addSql(<<<'SQL'
DROP TABLE preference_option
SQL);
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql(<<<'SQL'
CREATE TABLE preference_option (id INT AUTO_INCREMENT NOT NULL, preference_id VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, name VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, value VARCHAR(255) CHARACTER SET utf8mb4 DEFAULT NULL COLLATE `utf8mb4_unicode_ci`, enabled TINYINT(1) NOT NULL, INDEX IDX_607C52FD81022C0 (preference_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB COMMENT = ''
SQL);
$this->addSql(<<<'SQL'
ALTER TABLE preference_option ADD CONSTRAINT FK_607C52FD81022C0 FOREIGN KEY (preference_id) REFERENCES preference (id)
SQL);
}
}

View File

@@ -3,14 +3,20 @@
namespace App\Twig\Components;
use Aimeos\Map;
use App\User\Database\CodecList;
use App\User\Database\QualityList;
use App\User\Database\ResolutionList;
use App\User\Dto\PreferenceOptions;
use App\User\Dto\PreferenceOptionsFactory;
use App\User\Dto\UserPreferencesFactory;
use App\User\Framework\Repository\PreferencesRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\DefaultActionTrait;
#[AsLiveComponent]
final class Filter
final class Filter extends AbstractController
{
use DefaultActionTrait;
@@ -21,15 +27,20 @@ final class Filter
public array $reverseMappedQualities = [];
public function __construct(
private readonly PreferencesRepository $preferencesRepository,
private readonly Security $security,
) {
$this->preferences = Map::from($this->preferencesRepository->findEnabled())
->rekey(fn($element) => $element->getId())
->map(fn($element) => $element->getPreferenceOptions()->toArray())
->toArray();
$this->userPreferences = Map::from($this->security->getUser()->getUserPreferenceValues())
->toArray();
$this->preferences = (array) PreferenceOptionsFactory::createSelectOptions();
$this->userPreferences = (array) UserPreferencesFactory::createFromUser($security->getUser());
$this->reverseMappedQualities = QualityList::getAsReverseMap();
}
public function getResolutionOptions()
{
return ResolutionList::asSelectOptions();
}
public function getCodecOptions()
{
return CodecList::asSelectOptions();
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace App\User\Dto;
class PreferenceOptions
{
public function __construct(
public readonly array $resolutions,
public readonly array $codecs,
public readonly array $languages,
public readonly array $providers,
public readonly array $qualities,
) {}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace App\User\Dto;
use App\User\Database\CodecList;
use App\User\Database\CountryLanguages;
use App\User\Database\ProviderList;
use App\User\Database\QualityList;
use App\User\Database\ResolutionList;
class PreferenceOptionsFactory
{
public static function createSelectOptions(): PreferenceOptions
{
return new PreferenceOptions(
resolutions: ResolutionList::asSelectOptions(),
codecs: CodecList::asSelectOptions(),
languages: CountryLanguages::asSelectOptions(),
providers: ProviderList::asSelectOptions(),
qualities: QualityList::asSelectOptions(),
);
}
}

View File

@@ -15,10 +15,10 @@
value="{{ app.user.userPreferenceValues["resolution"] }}"
>
<option value="">n/a</option>
{% for option in this.preferences['resolution'] %}
<option value="{{ option.value }}"
{{ option.value == this.userPreferences['resolution'] ? 'selected' }}
>{{ option.name }}</option>
{% for name, value in this.resolutionOptions %}
<option value="{{ value }}"
{{ value == this.userPreferences['resolution'] ? 'selected' }}
>{{ name }}</option>
{% endfor %}
</select>
</label>
@@ -26,10 +26,10 @@
Codec
<select id="codec" data-result-filter-target="codec" class="px-1 py-0.5 bg-stone-100 text-sm text-gray-800 rounded-md">
<option value="">n/a</option>
{% for option in this.preferences['codec'] %}
<option value="{{ option.value }}"
{{ option.value == this.userPreferences['codec'] ? 'selected' }}
>{{ option.name }}</option>
{% for name, value in this.codecOptions %}
<option value="{{ value }}"
{{ value == this.userPreferences['codec'] ? 'selected' }}
>{{ name }}</option>
{% endfor %}
</select>
</label>