Implement quantityUnits

This commit is contained in:
Tim 2021-12-30 23:34:29 +01:00
parent f271d2d6ac
commit 08c250a78b
6 changed files with 161 additions and 0 deletions

View File

@ -3,6 +3,7 @@
namespace App\Controller\Admin; namespace App\Controller\Admin;
use App\Entity\Product; use App\Entity\Product;
use App\Entity\QuantityUnit;
use App\Entity\User; use App\Entity\User;
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard; use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem; use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
@ -36,6 +37,7 @@ class DashboardController extends AbstractDashboardController
yield MenuItem::section('Products', 'fas fa-folder-open'); yield MenuItem::section('Products', 'fas fa-folder-open');
yield MenuItem::linkToDashboard('Dashboard', 'fa fa-home'); yield MenuItem::linkToDashboard('Dashboard', 'fa fa-home');
yield MenuItem::linkToCrud('Products', 'fas fa-list', Product::class); yield MenuItem::linkToCrud('Products', 'fas fa-list', Product::class);
yield MenuItem::linkToCrud('Quantity units', 'fas fa-list', QuantityUnit::class);
yield MenuItem::section('Administration', 'fas fa-folder-open'); yield MenuItem::section('Administration', 'fas fa-folder-open');
yield MenuItem::linkToCrud('User', 'fas fa-list', User::class); yield MenuItem::linkToCrud('User', 'fas fa-list', User::class);

View File

@ -5,6 +5,7 @@ namespace App\Controller\Admin;
use App\Entity\Product; use App\Entity\Product;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController; use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField; use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField; use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField; use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
@ -30,6 +31,7 @@ class ProductCrudController extends AbstractCrudController
$fields[] = BooleanField::new('enabled'); $fields[] = BooleanField::new('enabled');
$fields[] = TextField::new('name'); $fields[] = TextField::new('name');
$fields[] = TextEditorField::new('description'); $fields[] = TextEditorField::new('description');
$fields[] = AssociationField::new('quantityUnit');
return $fields; return $fields;
} }

View File

@ -0,0 +1,37 @@
<?php
namespace App\Controller\Admin;
use App\Entity\QuantityUnit;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
class QuantityUnitCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return QuantityUnit::class;
}
public function configureFields(string $pageName): iterable
{
$fields = [];
switch ($pageName) {
case Crud::PAGE_INDEX:
case Crud::PAGE_DETAIL:
$fields[] = IdField::new('id');
}
$fields[] = TextField::new('name');
$fields[] = TextEditorField::new('description');
return $fields;
}
}

View File

@ -22,6 +22,9 @@ class Product
#[ORM\Column(type: 'text', nullable: true)] #[ORM\Column(type: 'text', nullable: true)]
private $description; private $description;
#[ORM\ManyToOne(targetEntity: QuantityUnit::class)]
private $quantityUnit;
public function getId(): ?int public function getId(): ?int
{ {
return $this->id; return $this->id;
@ -50,4 +53,16 @@ class Product
return $this; return $this;
} }
public function getQuantityUnit(): ?QuantityUnit
{
return $this->quantityUnit;
}
public function setQuantityUnit(QuantityUnit $quantityUnit): self
{
$this->quantityUnit = $quantityUnit;
return $this;
}
} }

View File

@ -0,0 +1,55 @@
<?php
namespace App\Entity;
use App\Repository\QuantityUnitRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: QuantityUnitRepository::class)]
class QuantityUnit
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private $id;
#[ORM\Column(type: 'string', length: 255)]
private $name;
#[ORM\Column(type: 'text', nullable: true)]
private $description;
public function __toString(): string
{
return $this->name;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
}

View File

@ -0,0 +1,50 @@
<?php
namespace App\Repository;
use App\Entity\QuantityUnit;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @method QuantityUnit|null find($id, $lockMode = null, $lockVersion = null)
* @method QuantityUnit|null findOneBy(array $criteria, array $orderBy = null)
* @method QuantityUnit[] findAll()
* @method QuantityUnit[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
*/
class QuantityUnitRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, QuantityUnit::class);
}
// /**
// * @return QuantityUnit[] Returns an array of QuantityUnit objects
// */
/*
public function findByExampleField($value)
{
return $this->createQueryBuilder('q')
->andWhere('q.exampleField = :val')
->setParameter('val', $value)
->orderBy('q.id', 'ASC')
->setMaxResults(10)
->getQuery()
->getResult()
;
}
*/
/*
public function findOneBySomeField($value): ?QuantityUnit
{
return $this->createQueryBuilder('q')
->andWhere('q.exampleField = :val')
->setParameter('val', $value)
->getQuery()
->getOneOrNullResult()
;
}
*/
}