Changed Config Variables database and other entities.

This commit is contained in:
2024-09-09 12:11:24 +02:00
parent 8c6a70b0be
commit 82bd51e6f0
7 changed files with 135 additions and 23 deletions
+44
View File
@@ -0,0 +1,44 @@
<?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 Version20240604185317 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('DROP SEQUENCE config_variable_id_seq CASCADE');
$this->addSql('DROP INDEX uniq_718569538a90aba9');
$this->addSql('ALTER TABLE config_variable DROP CONSTRAINT config_variable_pkey');
$this->addSql('ALTER TABLE config_variable DROP id');
$this->addSql('ALTER TABLE config_variable ALTER section SET NOT NULL');
$this->addSql('ALTER TABLE config_variable ALTER section TYPE VARCHAR(255)');
$this->addSql('ALTER TABLE config_variable ADD PRIMARY KEY (key)');
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE SCHEMA public');
$this->addSql('CREATE SEQUENCE config_variable_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('DROP INDEX config_variable_pkey');
$this->addSql('ALTER TABLE config_variable ADD id INT NOT NULL');
$this->addSql('ALTER TABLE config_variable ALTER section DROP NOT NULL');
$this->addSql('ALTER TABLE config_variable ALTER section TYPE VARCHAR(64)');
$this->addSql('CREATE UNIQUE INDEX uniq_718569538a90aba9 ON config_variable (key)');
$this->addSql('ALTER TABLE config_variable ADD PRIMARY KEY (id)');
}
}
@@ -3,9 +3,11 @@
namespace App\Controller\Admin; namespace App\Controller\Admin;
use App\Entity\ConfigVariable; use App\Entity\ConfigVariable;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController; use App\Enum\ConfigSectionType;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
class ConfigVariableCrudController extends AbstractCrudController class ConfigVariableCrudController extends AbstractCrudController
{ {
@@ -14,10 +16,14 @@ class ConfigVariableCrudController extends AbstractCrudController
return ConfigVariable::class; return ConfigVariable::class;
} }
public function configureCrud(Crud $crud): Crud
{
return $crud;
}
public function configureFields(string $pageName): iterable public function configureFields(string $pageName): iterable
{ {
yield TextField::new('section'); yield ChoiceField::new ('section')->setChoices(ConfigSectionType::cases());
yield TextField::new ('key'); yield TextField::new ('key');
yield TextField::new ('value'); yield TextField::new ('value');
} }
@@ -20,7 +20,8 @@ class RoomFareCrudController extends AbstractCrudController
public function configureFields(string $pageName): iterable public function configureFields(string $pageName): iterable
{ {
$fieldFareTable = AssociationField::new ('fareTable')->setRequired(true); $fieldFareTable = AssociationField::new('fareTable')->setRequired(true)
->formatValue(fn ($value) => $value->getComment() . " (" . $value->getRoomCategory() . ")");
if ($pageName == Crud::PAGE_EDIT) { if ($pageName == Crud::PAGE_EDIT) {
$fieldFareTable->setDisabled(true); $fieldFareTable->setDisabled(true);
} }
+14 -15
View File
@@ -3,31 +3,25 @@
namespace App\Entity; namespace App\Entity;
use App\Repository\ConfigVariableRepository; use App\Repository\ConfigVariableRepository;
use App\Enum\ConfigSectionType;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ConfigVariableRepository::class)] #[ORM\Entity(repositoryClass: ConfigVariableRepository::class)]
class ConfigVariable class ConfigVariable
{ {
#[ORM\Id] #[ORM\Id]
#[ORM\GeneratedValue] #[ORM\GeneratedValue("NONE")]
#[ORM\Column] #[ORM\Column(length: 32, unique: true, nullable: false)]
private ?int $id = null; private string $key = "";
#[ORM\Column(length: 32, unique: true)]
private ?string $key = null;
#[ORM\Column(length: 255)] #[ORM\Column(length: 255)]
private ?string $value = null; private ?string $value = null;
#[ORM\Column(length: 64, nullable: true)] #[ORM\Column(type: 'string', enumType: ConfigSectionType::class, nullable: false)]
private ?string $section = null; private ConfigSectionType $section = ConfigSectionType::General;
public function getId(): ?int
{
return $this->id;
}
public function getKey(): ?string public function getKey(): string
{ {
return $this->key; return $this->key;
} }
@@ -51,15 +45,20 @@ class ConfigVariable
return $this; return $this;
} }
public function getSection(): ?string public function getSection(): ConfigSectionType
{ {
return $this->section; return $this->section;
} }
public function setSection(?string $section): static public function setSection(ConfigSectionType $section): static
{ {
$this->section = $section; $this->section = $section;
return $this; return $this;
} }
function __toString(): string
{
return $this->getKey();
}
} }
+6 -2
View File
@@ -125,10 +125,14 @@ class FareTable
public function __toString(): string public function __toString(): string
{ {
$str = $this->id;
if (!\is_null($this->comment)) { if (!\is_null($this->comment)) {
return $this->comment; $str = $this->comment;
} }
return $this->id; $str . "(" . $this->roomCategory . ")";
if (!\is_null($this->roomCategory)) {
}
return $str;
} }
/** /**
+12
View File
@@ -0,0 +1,12 @@
<?php
namespace App\Enum;
enum ConfigSectionType: string {
case General = 'GENERAL';
case Internal = 'INTERNAL';
case Company = 'COMPANY';
case Backend = 'BACK';
case Frontend = 'FRONT';
case Test = 'TEST';
}
+46
View File
@@ -0,0 +1,46 @@
<?php
namespace App\Service;
use App\Entity\ConfigVariable;
use App\Repository\ConfigVariableRepository;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Service to manage config variables.
*/
class ConfigVariableService
{
public function __construct(
private ConfigVariableRepository $repoVariables
) {}
public function getVariable(string $key) {
$var = $this->repoVariables->findVariableByKey($key);
}
/**
* Create and init all variables.
* To be used during Setup process.
*/
public function InitVariablesOnSetup(): void {
$entityManager = $this->repoVariables->getEntityManager();
$entityManager->beginTransaction();
try {
}
catch (\Throwable $th) {
$entityManager->rollback();
throw $th;
}
}
private function AddConfigVariable(string $key, string $value, string $section) : Returntype {
}
}