diff --git a/config/packages/doctrine.yaml b/config/packages/doctrine.yaml index 816f367..24a64ab 100644 --- a/config/packages/doctrine.yaml +++ b/config/packages/doctrine.yaml @@ -18,18 +18,18 @@ doctrine: Doctrine\DBAL\Platforms\PostgreSQLPlatform: identity auto_mapping: true mappings: -# App: -# type: attribute -# is_bundle: false -# dir: '%kernel.project_dir%/src/Entity' -# prefix: 'App\Entity' -# alias: App Download: type: attribute is_bundle: false dir: '%kernel.project_dir%/src/Download/Framework/Entity' prefix: 'App\Download\Framework\Entity' alias: Download + User: + type: attribute + is_bundle: false + dir: '%kernel.project_dir%/src/User/Framework/Entity' + prefix: 'App\User\Framework\Entity' + alias: User controller_resolver: auto_mapping: false diff --git a/config/routes.yaml b/config/routes.yaml index eba546d..29a70ce 100644 --- a/config/routes.yaml +++ b/config/routes.yaml @@ -6,3 +6,10 @@ controllersIndex: defaults: schemes: [ 'https' ] +controllersUser: + resource: + path: ../src/User/Framework/Controller + namespace: App\User\Framework\Controller + type: attribute + defaults: + schemes: ['https'] diff --git a/migrations/Version20250428133608.php b/migrations/Version20250428133608.php new file mode 100644 index 0000000..d2c4d61 --- /dev/null +++ b/migrations/Version20250428133608.php @@ -0,0 +1,46 @@ +addSql(<<<'SQL' + CREATE TABLE preference (id VARCHAR(255) NOT NULL, name VARCHAR(255) DEFAULT NULL, description VARCHAR(255) DEFAULT NULL, enabled TINYINT(1) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB + SQL); + $this->addSql(<<<'SQL' + CREATE TABLE preference_option (id INT AUTO_INCREMENT NOT NULL, preference_id VARCHAR(255) DEFAULT NULL, name VARCHAR(255) DEFAULT NULL, value VARCHAR(255) DEFAULT NULL, enabled TINYINT(1) NOT NULL, INDEX IDX_607C52FD81022C0 (preference_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB + SQL); + $this->addSql(<<<'SQL' + ALTER TABLE preference_option ADD CONSTRAINT FK_607C52FD81022C0 FOREIGN KEY (preference_id) REFERENCES preference (id) + SQL); + } + + public function down(Schema $schema): void + { + // this down() 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 + SQL); + $this->addSql(<<<'SQL' + DROP TABLE preference_option + SQL); + } +} diff --git a/src/User/Action/Command/SaveUserMediaPreferencesCommand.php b/src/User/Action/Command/SaveUserMediaPreferencesCommand.php new file mode 100644 index 0000000..19878b4 --- /dev/null +++ b/src/User/Action/Command/SaveUserMediaPreferencesCommand.php @@ -0,0 +1,16 @@ + */ +class SaveUserMediaPreferencesCommand implements CommandInterface +{ + public function __construct( + public string $resolution, + public string $codec, + public string $language, + public string $provider, + ) {} +} \ No newline at end of file diff --git a/src/User/Action/Handler/SaveUserMediaPreferencesHandler.php b/src/User/Action/Handler/SaveUserMediaPreferencesHandler.php new file mode 100644 index 0000000..b39b6b8 --- /dev/null +++ b/src/User/Action/Handler/SaveUserMediaPreferencesHandler.php @@ -0,0 +1,18 @@ + */ +class SaveUserMediaPreferencesHandler implements HandlerInterface +{ + public function handle(C $command): R + { + return new SaveUserMediaPreferencesResult('Success'); + } +} diff --git a/src/User/Action/Input/SaveUserMediaPreferencesInput.php b/src/User/Action/Input/SaveUserMediaPreferencesInput.php new file mode 100644 index 0000000..f6e80c9 --- /dev/null +++ b/src/User/Action/Input/SaveUserMediaPreferencesInput.php @@ -0,0 +1,36 @@ + */ +class SaveUserMediaPreferencesInput implements InputInterface +{ + public function __construct( + #[SourceRequest('resolution')] + public string $resolution, + + #[SourceRequest('codec')] + public string $codec, + + #[SourceRequest('language')] + public string $language, + + #[SourceRequest('provider')] + public string $provider, + ) {} + + public function toCommand(): C + { + return new SaveUserMediaPreferencesCommand( + $this->resolution, + $this->codec, + $this->language, + $this->provider, + ); + } +} diff --git a/src/User/Action/Result/SaveUserMediaPreferencesResult.php b/src/User/Action/Result/SaveUserMediaPreferencesResult.php new file mode 100644 index 0000000..a8b36ab --- /dev/null +++ b/src/User/Action/Result/SaveUserMediaPreferencesResult.php @@ -0,0 +1,13 @@ +render( + 'user/preferences.html.twig', + [ + 'preferences' => $this->preferencesRepository->findEnabled(), + 'languages' => CountryCodes::$countries, + 'providers' => ['test' => 'Test'], + ] + ); + } + + #[Route('/media/preferences', 'app_save_media_preferences', methods: ['POST'])] + public function saveMediaPreferences( + SaveUserMediaPreferencesInput $input, + ): Response + { + dd($input); + return $this->render( + 'user/preferences.html.twig', + [ + 'preferences' => $this->preferencesRepository->findEnabled(), + ] + ); + } +} diff --git a/src/User/Framework/Entity/Preference.php b/src/User/Framework/Entity/Preference.php new file mode 100644 index 0000000..ed5bf0b --- /dev/null +++ b/src/User/Framework/Entity/Preference.php @@ -0,0 +1,107 @@ + + */ + #[ORM\OneToMany(targetEntity: PreferenceOption::class, mappedBy: 'preference')] + private Collection $preferenceOptions; + + public function __construct() + { + $this->preferenceOptions = new ArrayCollection(); + } + + public function getId(): ?string + { + return $this->id; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(?string $name): static + { + $this->name = $name; + + return $this; + } + + public function getDescription(): ?string + { + return $this->description; + } + + public function setDescription(?string $description): static + { + $this->description = $description; + + return $this; + } + + public function isEnabled(): ?bool + { + return $this->enabled; + } + + public function setEnabled(bool $enabled): static + { + $this->enabled = $enabled; + + return $this; + } + + /** + * @return Collection + */ + public function getPreferenceOptions(): Collection + { + return $this->preferenceOptions; + } + + public function addPreferenceOption(PreferenceOption $preferenceOption): static + { + if (!$this->preferenceOptions->contains($preferenceOption)) { + $this->preferenceOptions->add($preferenceOption); + $preferenceOption->setPreference($this); + } + + return $this; + } + + public function removePreferenceOption(PreferenceOption $preferenceOption): static + { + if ($this->preferenceOptions->removeElement($preferenceOption)) { + // set the owning side to null (unless already changed) + if ($preferenceOption->getPreference() === $this) { + $preferenceOption->setPreference(null); + } + } + + return $this; + } +} diff --git a/src/User/Framework/Entity/PreferenceOption.php b/src/User/Framework/Entity/PreferenceOption.php new file mode 100644 index 0000000..d9fd8ca --- /dev/null +++ b/src/User/Framework/Entity/PreferenceOption.php @@ -0,0 +1,80 @@ +id; + } + + public function getName(): ?string + { + return $this->name; + } + + public function setName(?string $name): static + { + $this->name = $name; + + return $this; + } + + public function getValue(): ?string + { + return $this->value; + } + + public function setValue(?string $value): static + { + $this->value = $value; + + return $this; + } + + public function getPreference(): ?Preference + { + return $this->preference; + } + + public function setPreference(?Preference $preference): static + { + $this->preference = $preference; + + return $this; + } + + public function isEnabled(): ?bool + { + return $this->enabled; + } + + public function setEnabled(bool $enabled): static + { + $this->enabled = $enabled; + + return $this; + } +} diff --git a/src/User/Framework/Repository/PreferenceOptionRepository.php b/src/User/Framework/Repository/PreferenceOptionRepository.php new file mode 100644 index 0000000..3ed6ce5 --- /dev/null +++ b/src/User/Framework/Repository/PreferenceOptionRepository.php @@ -0,0 +1,43 @@ + + */ +class PreferenceOptionRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, PreferenceOption::class); + } + + // /** + // * @return PreferenceOption[] Returns an array of PreferenceOption objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('p') + // ->andWhere('p.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('p.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?PreferenceOption + // { + // return $this->createQueryBuilder('p') + // ->andWhere('p.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +} diff --git a/src/User/Framework/Repository/PreferencesRepository.php b/src/User/Framework/Repository/PreferencesRepository.php new file mode 100644 index 0000000..66c41f2 --- /dev/null +++ b/src/User/Framework/Repository/PreferencesRepository.php @@ -0,0 +1,28 @@ + + */ +class PreferencesRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Preference::class); + } + + /** @return Preference[] Returns an array of Preferences objects */ + public function findEnabled(): array + { + return $this->createQueryBuilder('p') + ->andWhere('p.enabled = :val') + ->setParameter('val', true) + ->getQuery() + ->getResult(); + } +} diff --git a/templates/base.html.twig b/templates/base.html.twig index 3b00bce..08ba0fd 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -20,6 +20,7 @@
+

{% block h2 %}{% endblock %}

{% block body %}{% endblock %}
diff --git a/templates/user/preferences.html.twig b/templates/user/preferences.html.twig new file mode 100644 index 0000000..e95b0eb --- /dev/null +++ b/templates/user/preferences.html.twig @@ -0,0 +1,37 @@ +{% extends 'base.html.twig' %} +{% block title %}Preferences{% endblock %} +{% block h2 %}Preferences{% endblock %} + +{% block body %} +
+ +

Define a set of filters to apply to your media download option results.

+
+ {% for preference in preferences %} + + + {% if preference.name|lower == "language" %} + + {% elseif preference.name|lower == "provider" %} + + {% else %} + + {% endif %} + {% endfor %} + +
+
+
+{% endblock %} \ No newline at end of file