Create product entity

This commit is contained in:
Tim 2021-12-29 00:16:57 +01:00
parent f2bd6cac79
commit e990ddbc25
5 changed files with 127 additions and 0 deletions

View File

View File

@ -0,0 +1,24 @@
<?php
namespace App\Entity\Helpers;
use Doctrine\ORM\Mapping as ORM;
trait EnabledTrait
{
#[ORM\Column(type: 'boolean')]
private bool $enabled = true;
public function isEnabled(): bool
{
return $this->enabled;
}
public function setEnabled(bool $enabled)
{
$this->enabled = $enabled;
return $this;
}
}

53
src/Entity/Product.php Normal file
View File

@ -0,0 +1,53 @@
<?php
namespace App\Entity;
use App\Entity\Helpers\EnabledTrait;
use App\Repository\ProductRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: ProductRepository::class)]
class Product
{
use EnabledTrait;
#[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 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

View File

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