Config Variables - Model & Easyadmin.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin;
|
||||
|
||||
use App\Entity\ConfigVariable;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
|
||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
|
||||
|
||||
class ConfigVariableCrudController extends AbstractCrudController
|
||||
{
|
||||
public static function getEntityFqcn(): string
|
||||
{
|
||||
return ConfigVariable::class;
|
||||
}
|
||||
|
||||
|
||||
public function configureFields(string $pageName): iterable
|
||||
{
|
||||
yield TextField::new('section');
|
||||
yield TextField::new('key');
|
||||
yield TextField::new('value');
|
||||
}
|
||||
}
|
||||
@@ -28,7 +28,7 @@ class RoomCategoryCrudController extends AbstractCrudController
|
||||
{
|
||||
return [
|
||||
TextField::new('name'),
|
||||
TextEditorField::new('description'),
|
||||
TextField::new('description'),
|
||||
TextField::new('bedType'),
|
||||
IntegerField::new('maxGuestNum'),
|
||||
CollectionField::new('roomCategoryDetails')->useEntryCrudForm(),
|
||||
|
||||
@@ -10,6 +10,7 @@ use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
use App\Entity\RoomCategory;
|
||||
use App\Entity\User;
|
||||
use App\Entity\ConfigVariable;
|
||||
|
||||
class SomniaDashboardController extends AbstractDashboardController
|
||||
{
|
||||
@@ -33,6 +34,8 @@ class SomniaDashboardController extends AbstractDashboardController
|
||||
yield MenuItem::linkToCrud('Category', 'fas fa-list', RoomCategory::class);
|
||||
|
||||
yield MenuItem::Section('App Management');
|
||||
yield MenuItem::linkToCrud('Users', 'fas fa-user', User::class);
|
||||
yield MenuItem::linkToCrud('Config Vars', 'fas fa-gear', ConfigVariable::class);
|
||||
yield MenuItem::linkToCrud('Users', 'fas fa-user', User::class)
|
||||
->setPermission("ROLE_SUPERADMIN");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class UserCrudController extends AbstractCrudController
|
||||
yield TextField::new ('username');
|
||||
yield TextField::new ('username')->onlyWhenUpdating()->setDisabled(true);
|
||||
|
||||
$availableRoles = ['User' => 'ROLE_USER', 'Admin' => 'ROLE_ADMIN', 'Test' => 'ROLE_TEST'];
|
||||
$availableRoles = ['User' => 'ROLE_USER', 'Admin' => 'ROLE_ADMIN', 'Test' => 'ROLE_TEST', 'SuperAdmin' => 'ROLE_SUPERADMIN'];
|
||||
yield ChoiceField::new ('roles')
|
||||
->setChoices($availableRoles)
|
||||
->allowMultipleChoices(true);
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use App\Repository\ConfigVariableRepository;
|
||||
|
||||
class ConfigVariableController extends AbstractController
|
||||
{
|
||||
#[Route('/config', name: 'app_config_variable')]
|
||||
public function getAllVariables(ConfigVariableRepository $repo): Response
|
||||
{
|
||||
$varList = $repo->findAllVariables();
|
||||
|
||||
return $this->json(['results' => $varList]);
|
||||
}
|
||||
|
||||
#[Route('/config/section', name: 'app_config_sections')]
|
||||
public function getSections(ConfigVariableRepository $repo): Response
|
||||
{
|
||||
$sectionList = $repo->getAllSections();
|
||||
$returnList = [];
|
||||
foreach ($sectionList as $section) {
|
||||
$sectionValue = $section["section"];
|
||||
$returnList[] = $sectionValue;
|
||||
}
|
||||
|
||||
return $this->json(['results' => $returnList]);
|
||||
}
|
||||
|
||||
#[Route('/config/section/{section}', name: 'app_config_variableBySection')]
|
||||
public function getVariablesBySection(ConfigVariableRepository $repo, string $section): Response
|
||||
{
|
||||
if(\is_null($section) || $section == '') {
|
||||
return new Response("Invalid section value", 404);
|
||||
}
|
||||
|
||||
$varList = $repo->findAllBySection($section);
|
||||
|
||||
return $this->json(['results' => $varList]);
|
||||
}
|
||||
|
||||
#[Route('/config/var/{key}', name: 'app_config_variable')]
|
||||
public function getByKey(ConfigVariableRepository $repo, string $key): Response
|
||||
{
|
||||
$var = $repo->findVariableByKey($key);
|
||||
|
||||
return $this->json($var);
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ class RoomCategoryController extends AbstractController
|
||||
{
|
||||
|
||||
#[Route('/room/category', name: 'app_room_AllCategories')]
|
||||
public function getAll(RoomCategoryRepository $catRepo, SerializerInterface $serializer): Response
|
||||
public function getAll(RoomCategoryRepository $catRepo): Response
|
||||
{
|
||||
$catList = $catRepo->findAll();
|
||||
|
||||
@@ -26,7 +26,7 @@ class RoomCategoryController extends AbstractController
|
||||
}
|
||||
|
||||
#[Route('/room/category/{id}', name: 'app_room_category')]
|
||||
public function getById(RoomCategory $category, SerializerInterface $serializer): Response
|
||||
public function getById(RoomCategory $category): Response
|
||||
{
|
||||
return $this->json($category);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user