wip: adds preference & preference_option tables
This commit is contained in:
16
src/User/Action/Command/SaveUserMediaPreferencesCommand.php
Normal file
16
src/User/Action/Command/SaveUserMediaPreferencesCommand.php
Normal file
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\User\Action\Command;
|
||||
|
||||
use OneToMany\RichBundle\Contract\CommandInterface;
|
||||
|
||||
/** @implements CommandInterface<SaveUserMediaPreferencesCommand> */
|
||||
class SaveUserMediaPreferencesCommand implements CommandInterface
|
||||
{
|
||||
public function __construct(
|
||||
public string $resolution,
|
||||
public string $codec,
|
||||
public string $language,
|
||||
public string $provider,
|
||||
) {}
|
||||
}
|
||||
18
src/User/Action/Handler/SaveUserMediaPreferencesHandler.php
Normal file
18
src/User/Action/Handler/SaveUserMediaPreferencesHandler.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\User\Action\Handler;
|
||||
|
||||
use App\User\Action\Command\SaveUserMediaPreferencesCommand;
|
||||
use App\User\Action\Result\SaveUserMediaPreferencesResult;
|
||||
use OneToMany\RichBundle\Contract\CommandInterface as C;
|
||||
use OneToMany\RichBundle\Contract\HandlerInterface;
|
||||
use OneToMany\RichBundle\Contract\ResultInterface as R;
|
||||
|
||||
/** @implements HandlerInterface<SaveUserMediaPreferencesCommand> */
|
||||
class SaveUserMediaPreferencesHandler implements HandlerInterface
|
||||
{
|
||||
public function handle(C $command): R
|
||||
{
|
||||
return new SaveUserMediaPreferencesResult('Success');
|
||||
}
|
||||
}
|
||||
36
src/User/Action/Input/SaveUserMediaPreferencesInput.php
Normal file
36
src/User/Action/Input/SaveUserMediaPreferencesInput.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\User\Action\Input;
|
||||
|
||||
use App\User\Action\Command\SaveUserMediaPreferencesCommand;
|
||||
use OneToMany\RichBundle\Attribute\SourceRequest;
|
||||
use OneToMany\RichBundle\Contract\CommandInterface as C;
|
||||
use OneToMany\RichBundle\Contract\InputInterface;
|
||||
|
||||
/** @implements InputInterface<SaveUserMediaPreferencesInput, SaveUserMediaPreferencesCommand> */
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
13
src/User/Action/Result/SaveUserMediaPreferencesResult.php
Normal file
13
src/User/Action/Result/SaveUserMediaPreferencesResult.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\User\Action\Result;
|
||||
|
||||
use OneToMany\RichBundle\Contract\ResultInterface;
|
||||
|
||||
/** @implements ResultInterface */
|
||||
class SaveUserMediaPreferencesResult implements ResultInterface
|
||||
{
|
||||
public function __construct(
|
||||
public string $status,
|
||||
) {}
|
||||
}
|
||||
45
src/User/Framework/Controller/Web/PreferencesController.php
Normal file
45
src/User/Framework/Controller/Web/PreferencesController.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\User\Framework\Controller\Web;
|
||||
|
||||
use App\User\Action\Input\SaveUserMediaPreferencesInput;
|
||||
use App\User\Framework\Repository\PreferencesRepository;
|
||||
use App\Util\CountryCodes;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class PreferencesController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly PreferencesRepository $preferencesRepository,
|
||||
) {}
|
||||
#[Route('/media/preferences', 'app_media_preferences', methods: ['GET'])]
|
||||
public function mediaPreferences(): Response
|
||||
{
|
||||
return $this->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(),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
107
src/User/Framework/Entity/Preference.php
Normal file
107
src/User/Framework/Entity/Preference.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\User\Framework\Entity;
|
||||
|
||||
use App\User\Framework\Repository\PreferencesRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: PreferencesRepository::class)]
|
||||
class Preference
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\Column]
|
||||
private ?string $id = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $name = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $description = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?bool $enabled = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, PreferenceOption>
|
||||
*/
|
||||
#[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<int, PreferenceOption>
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
80
src/User/Framework/Entity/PreferenceOption.php
Normal file
80
src/User/Framework/Entity/PreferenceOption.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace App\User\Framework\Entity;
|
||||
|
||||
use App\User\Framework\Repository\PreferenceOptionRepository;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: PreferenceOptionRepository::class)]
|
||||
class PreferenceOption
|
||||
{
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $name = null;
|
||||
|
||||
#[ORM\Column(length: 255, nullable: true)]
|
||||
private ?string $value = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'preferenceOptions')]
|
||||
private ?Preference $preference = null;
|
||||
|
||||
#[ORM\Column]
|
||||
private ?bool $enabled = null;
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->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;
|
||||
}
|
||||
}
|
||||
43
src/User/Framework/Repository/PreferenceOptionRepository.php
Normal file
43
src/User/Framework/Repository/PreferenceOptionRepository.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\User\Framework\Repository;
|
||||
|
||||
use App\User\Framework\Entity\PreferenceOption;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<PreferenceOption>
|
||||
*/
|
||||
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()
|
||||
// ;
|
||||
// }
|
||||
}
|
||||
28
src/User/Framework/Repository/PreferencesRepository.php
Normal file
28
src/User/Framework/Repository/PreferencesRepository.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\User\Framework\Repository;
|
||||
|
||||
use App\User\Framework\Entity\Preference;
|
||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||
use Doctrine\Persistence\ManagerRegistry;
|
||||
|
||||
/**
|
||||
* @extends ServiceEntityRepository<Preference>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user