<?php
namespace App\Entity;
use App\Repository\ModelRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ModelRepository::class)
*/
class Model
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=128)
*/
private $name;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $image;
/**
* @ORM\Column(type="string", length=2048, nullable=true)
*/
private $description;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $label;
/**
* @ORM\Column(type="integer")
*/
private $wttId;
/**
* @ORM\OneToMany(targetEntity=Product::class, mappedBy="model")
*/
private $products;
/**
* @ORM\ManyToOne(targetEntity=Manufacturer::class, inversedBy="models")
*/
private $manufacturer;
/**
* @ORM\OneToMany(targetEntity=Stock::class, mappedBy="model")
*/
private $stocks;
/**
* @ORM\ManyToOne(targetEntity=Category::class, inversedBy="models")
*/
private $category;
/**
* @ORM\OneToMany(targetEntity=Attribute::class, mappedBy="model")
*/
private $attributes;
public function __construct()
{
$this->products = new ArrayCollection();
$this->stocks = new ArrayCollection();
$this->attributes = new ArrayCollection();
}
public function __toString()
{
return $this->getManufacturer()->getName()." ".$this->getName();
}
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 getImage(): ?string
{
return $this->image;
}
public function setImage(string $image): self
{
$this->image = $image;
return $this;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): self
{
$this->label = $label;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getWttId(): ?int
{
return $this->wttId;
}
public function setWttId(int $wttId): self
{
$this->wttId = $wttId;
return $this;
}
/**
* @return Collection<int, Product>
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): self
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
$product->setModel($this);
}
return $this;
}
public function removeProduct(Product $product): self
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getModel() === $this) {
$product->setModel(null);
}
}
return $this;
}
public function getManufacturer(): ?Manufacturer
{
return $this->manufacturer;
}
public function setManufacturer(?Manufacturer $manufacturer): self
{
$this->manufacturer = $manufacturer;
return $this;
}
/**
* @return Collection<int, Stock>
*/
public function getStocks(): Collection
{
return $this->stocks;
}
public function addStock(Stock $stock): self
{
if (!$this->stocks->contains($stock)) {
$this->stocks[] = $stock;
$stock->setModel($this);
}
return $this;
}
public function removeStock(Stock $stock): self
{
if ($this->stocks->removeElement($stock)) {
// set the owning side to null (unless already changed)
if ($stock->getModel() === $this) {
$stock->setModel(null);
}
}
return $this;
}
public function getCategory(): ?Category
{
return $this->category;
}
public function setCategory(?Category $category): self
{
$this->category = $category;
return $this;
}
public function getMainReference() {
$name=$this->getName();
if (preg_match("/\ (?:1|2|3|4|5|8|16|32|64|128|256|512)(?:GO|GB|TB|TO)/", $name, $matches)) {
if ((int)$matches[0] > 0) {
$name = trim(preg_replace("/ ".trim($matches[0])."/", '', $name));
}
}
// $pattern = '/-GB$/i';
// $name = preg_replace($pattern, 'aaa', $name);
$str="W-".$this->getManufacturer()->getName()."-".$name;
return preg_replace('/ /','-', $str);
}
/**
* @return Collection<int, Attribute>
*/
public function getAttributes(): Collection
{
return $this->attributes;
}
public function addAttribute(Attribute $attribute): static
{
if (!$this->attributes->contains($attribute)) {
$this->attributes->add($attribute);
$attribute->setModel($this);
}
return $this;
}
public function removeAttribute(Attribute $attribute): static
{
if ($this->attributes->removeElement($attribute)) {
// set the owning side to null (unless already changed)
if ($attribute->getModel() === $this) {
$attribute->setModel(null);
}
}
return $this;
}
}