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
@@ -3,9 +3,11 @@
namespace App\Controller\Admin;
use App\Entity\ConfigVariable;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use App\Enum\ConfigSectionType;
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
{
@@ -14,11 +16,15 @@ class ConfigVariableCrudController extends AbstractCrudController
return ConfigVariable::class;
}
public function configureCrud(Crud $crud): Crud
{
return $crud;
}
public function configureFields(string $pageName): iterable
{
yield TextField::new('section');
yield TextField::new('key');
yield TextField::new('value');
yield ChoiceField::new ('section')->setChoices(ConfigSectionType::cases());
yield TextField::new ('key');
yield TextField::new ('value');
}
}
@@ -20,7 +20,8 @@ class RoomFareCrudController extends AbstractCrudController
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) {
$fieldFareTable->setDisabled(true);
}
+14 -15
View File
@@ -3,31 +3,25 @@
namespace App\Entity;
use App\Repository\ConfigVariableRepository;
use App\Enum\ConfigSectionType;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ConfigVariableRepository::class)]
class ConfigVariable
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 32, unique: true)]
private ?string $key = null;
#[ORM\GeneratedValue("NONE")]
#[ORM\Column(length: 32, unique: true, nullable: false)]
private string $key = "";
#[ORM\Column(length: 255)]
private ?string $value = null;
#[ORM\Column(length: 64, nullable: true)]
private ?string $section = null;
#[ORM\Column(type: 'string', enumType: ConfigSectionType::class, nullable: false)]
private ConfigSectionType $section = ConfigSectionType::General;
public function getId(): ?int
{
return $this->id;
}
public function getKey(): ?string
public function getKey(): string
{
return $this->key;
}
@@ -51,15 +45,20 @@ class ConfigVariable
return $this;
}
public function getSection(): ?string
public function getSection(): ConfigSectionType
{
return $this->section;
}
public function setSection(?string $section): static
public function setSection(ConfigSectionType $section): static
{
$this->section = $section;
return $this;
}
function __toString(): string
{
return $this->getKey();
}
}
+6 -2
View File
@@ -125,10 +125,14 @@ class FareTable
public function __toString(): string
{
$str = $this->id;
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 {
}
}