<?php
namespace App\Entity\Slave;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="eposm_s_product_model")
* @ORM\Entity(repositoryClass="App\Repository\Slave\ProductModelRepository")
*/
class ProductModel
{
public function __toString(){
return $this->getName().' ('.$this->getSku().')';
}
public function isPos(){
return $this->getSubcategory()->getCategory()->isPos();
}
public function getDisplaySuppliers()
{
$result = '';
$first = true;
foreach($this->suppliers as $jt){
if($first) $first = false; else $result .= '<br>';
$result .= $jt->getSupplier()->getName();
}
return $result;
}
public function getDisplayComponents()
{
$result = '';
$first = true;
foreach($this->components as $component){
if($first) $first = false; else $result .= '<br>';
$result .= $component->getName();
}
return $result;
}
public function getCanDelete(){
if(sizeof($this->products) > 0) return false;
return true;
}
/**
* @ORM\Column(name="id", type="bigint")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(name="name", type="string", length=191)
*/
protected $name;
/**
* @ORM\Column(name="sku", type="string", length=191, nullable=true)
*/
protected $sku;
/**
* @ORM\Column(name="part_number", type="string", length=191, nullable=true)
*/
protected $partNumber;
/**
* @ORM\Column(name="internal_code", type="string", length=191, nullable=true)
*/
protected $internalCode;
/**
* @ORM\Column(name="image_path", type="string", length=191, nullable=true)
*/
protected $imagePath;
/**
* @ORM\Column(name="is_with_sim", type="boolean")
*/
protected $withSim = false;
/**
* @ORM\Column(name="is_with_base", type="boolean")
*/
protected $withBase = false;
// ManyToOne
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Slave\ProductSubcategory", inversedBy="models")
* @ORM\JoinColumn(name="subcategory_id", referencedColumnName="id")
*/
private $subcategory;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\Slave\Producer", inversedBy="models")
* @ORM\JoinColumn(name="producer_id", referencedColumnName="id")
*/
private $producer;
//
// OneToMany
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\Product", mappedBy="model")
*/
private $products;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Slave\JoinTableProductModelSupplier", mappedBy="model")
*/
private $suppliers;
//
// ManyToMany
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Slave\ProductComponent", inversedBy="models")
* @ORM\JoinTable(name="eposm_s_join_table_product_model_component")
*/
private $components;
public function __construct()
{
$this->products = new ArrayCollection();
$this->suppliers = new ArrayCollection();
$this->components = new ArrayCollection();
}
//
public function getId(): ?string
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getSku(): ?string
{
return $this->sku;
}
public function setSku(?string $sku): static
{
$this->sku = $sku;
return $this;
}
public function getInternalCode(): ?string
{
return $this->internalCode;
}
public function setInternalCode(?string $internalCode): static
{
$this->internalCode = $internalCode;
return $this;
}
public function getImagePath(): ?string
{
return $this->imagePath;
}
public function setImagePath(?string $imagePath): static
{
$this->imagePath = $imagePath;
return $this;
}
public function isWithSim(): ?bool
{
return $this->withSim;
}
public function setWithSim(bool $withSim): static
{
$this->withSim = $withSim;
return $this;
}
public function isWithBase(): ?bool
{
return $this->withBase;
}
public function setWithBase(bool $withBase): static
{
$this->withBase = $withBase;
return $this;
}
public function getSubcategory(): ?ProductSubcategory
{
return $this->subcategory;
}
public function setSubcategory(?ProductSubcategory $subcategory): static
{
$this->subcategory = $subcategory;
return $this;
}
public function getProducer(): ?Producer
{
return $this->producer;
}
public function setProducer(?Producer $producer): static
{
$this->producer = $producer;
return $this;
}
/**
* @return Collection<int, Product>
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): static
{
if (!$this->products->contains($product)) {
$this->products->add($product);
$product->setModel($this);
}
return $this;
}
public function removeProduct(Product $product): static
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getModel() === $this) {
$product->setModel(null);
}
}
return $this;
}
/**
* @return Collection<int, JoinTableProductModelSupplier>
*/
public function getSuppliers(): Collection
{
return $this->suppliers;
}
public function addSupplier(JoinTableProductModelSupplier $supplier): static
{
if (!$this->suppliers->contains($supplier)) {
$this->suppliers->add($supplier);
$supplier->setModel($this);
}
return $this;
}
public function removeSupplier(JoinTableProductModelSupplier $supplier): static
{
if ($this->suppliers->removeElement($supplier)) {
// set the owning side to null (unless already changed)
if ($supplier->getModel() === $this) {
$supplier->setModel(null);
}
}
return $this;
}
/**
* @return Collection<int, ProductComponent>
*/
public function getComponents(): Collection
{
return $this->components;
}
public function addComponent(ProductComponent $component): static
{
if (!$this->components->contains($component)) {
$this->components->add($component);
}
return $this;
}
public function removeComponent(ProductComponent $component): static
{
$this->components->removeElement($component);
return $this;
}
public function getPartNumber(): ?string
{
return $this->partNumber;
}
public function setPartNumber(?string $partNumber): static
{
$this->partNumber = $partNumber;
return $this;
}
}