Implement quantityUnits
This commit is contained in:
		| @@ -3,6 +3,7 @@ | ||||
| namespace App\Controller\Admin; | ||||
|  | ||||
| use App\Entity\Product; | ||||
| use App\Entity\QuantityUnit; | ||||
| use App\Entity\User; | ||||
| use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard; | ||||
| use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem; | ||||
| @@ -36,6 +37,7 @@ class DashboardController extends AbstractDashboardController | ||||
|         yield MenuItem::section('Products', 'fas fa-folder-open'); | ||||
|         yield MenuItem::linkToDashboard('Dashboard', 'fa fa-home'); | ||||
|         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::linkToCrud('User', 'fas fa-list', User::class); | ||||
|   | ||||
| @@ -5,6 +5,7 @@ namespace App\Controller\Admin; | ||||
| use App\Entity\Product; | ||||
| 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; | ||||
| @@ -30,6 +31,7 @@ class ProductCrudController extends AbstractCrudController | ||||
|         $fields[] = BooleanField::new('enabled'); | ||||
|         $fields[] = TextField::new('name'); | ||||
|         $fields[] = TextEditorField::new('description'); | ||||
|         $fields[] = AssociationField::new('quantityUnit'); | ||||
|  | ||||
|         return $fields; | ||||
|     } | ||||
|   | ||||
							
								
								
									
										37
									
								
								src/Controller/Admin/QuantityUnitCrudController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/Controller/Admin/QuantityUnitCrudController.php
									
									
									
									
									
										Normal 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; | ||||
|     } | ||||
|  | ||||
| } | ||||
| @@ -22,6 +22,9 @@ class Product | ||||
|     #[ORM\Column(type: 'text', nullable: true)] | ||||
|     private $description; | ||||
|  | ||||
|     #[ORM\ManyToOne(targetEntity: QuantityUnit::class)] | ||||
|     private $quantityUnit; | ||||
|  | ||||
|     public function getId(): ?int | ||||
|     { | ||||
|         return $this->id; | ||||
| @@ -50,4 +53,16 @@ class Product | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
|  | ||||
|     public function getQuantityUnit(): ?QuantityUnit | ||||
|     { | ||||
|         return $this->quantityUnit; | ||||
|     } | ||||
|  | ||||
|     public function setQuantityUnit(QuantityUnit $quantityUnit): self | ||||
|     { | ||||
|         $this->quantityUnit = $quantityUnit; | ||||
|  | ||||
|         return $this; | ||||
|     } | ||||
| } | ||||
|   | ||||
							
								
								
									
										55
									
								
								src/Entity/QuantityUnit.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								src/Entity/QuantityUnit.php
									
									
									
									
									
										Normal 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; | ||||
|     } | ||||
| } | ||||
							
								
								
									
										50
									
								
								src/Repository/QuantityUnitRepository.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								src/Repository/QuantityUnitRepository.php
									
									
									
									
									
										Normal 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() | ||||
|         ; | ||||
|     } | ||||
|     */ | ||||
| } | ||||
		Reference in New Issue
	
	Block a user