<?php
/**
* @author Leo BANNHOLTZER (contact@scaledev.fr)
* @copyright 2021 - ScaleDEV SAS, 12 RUE CHARLES MORET, 10120 ST ANDRE LES VERGERS
* @license commercial
*/
declare(strict_types=1);
namespace Bluue\CategoriesBundle\Entity;
use Symfony\Component\Uid\Uuid;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use App\DoctrineExtensions\IsDefaultEntity;
use Bluue\CategoriesBundle\Entity\Category;
use Bluue\ProductsBundle\Entity\ProductContext;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Bluue\CategoriesBundle\Repository\CategoryProductRepository;
use App\DoctrineExtensions\Timestampable\Traits\UserTimestampableEntity;
use App\DoctrineExtensions\SoftDeleteable\Traits\UserSoftDeleteableEntity;
/**
* @ORM\Entity(repositoryClass=CategoryProductRepository::class)
* @ORM\Table(name="categories_bundle__category_product", indexes={
* @ORM\Index(name="is_default", columns={"is_default"}),
* @ORM\Index(name="deleted_at", columns={"deleted_at"}),
* @ORM\Index(name="created_at", columns={"created_at"}),
* @ORM\Index(name="updated_at", columns={"updated_at"})
* })
* @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false, hardDelete=false)
* @UniqueEntity(
* fields={"category", "productContext"},
* errorPath="category",
* message="This association between this category and this product context already exists.",
* ignoreNull=false
* )
*/
class CategoryProduct
{
use UserTimestampableEntity;
use UserSoftDeleteableEntity;
use IsDefaultEntity;
/**
* @ORM\Id
* @ORM\Column(type="uuid")
* @ORM\GeneratedValue(strategy="CUSTOM")
* @ORM\CustomIdGenerator(class=UuidGenerator::class)
*/
private ?Uuid $id = null;
/**
* @ORM\ManyToOne(targetEntity=Category::class, inversedBy="categoryProducts")
* @ORM\JoinColumn(nullable=false)
*/
private Category $category;
/**
* @ORM\ManyToOne(targetEntity=ProductContext::class, inversedBy="categoryProducts")
* @ORM\JoinColumn(nullable=false)
*/
private ProductContext $productContext;
/**
* @return Uuid|null
*/
public function getId(): ?Uuid
{
return $this->id;
}
/**
* @return Category
*/
public function getCategory(): ?Category
{
return $this->category;
}
/**
* @param Category $category
* @return $this
*/
public function setCategory(Category $category): self
{
$this->category = $category;
return $this;
}
/**
* @return ProductContext
*/
public function getProductContext(): ?ProductContext
{
return $this->productContext;
}
/**
* @param ProductContext $productContext
* @return $this
*/
public function setProductContext(ProductContext $productContext): self
{
$this->productContext = $productContext;
return $this;
}
}