src/Entity/Model.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ModelRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=ModelRepository::class)
  9.  */
  10. class Model
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=128)
  20.      */
  21.     private $name;
  22.     /**
  23.      * @ORM\Column(type="string", length=255, nullable=true)
  24.      */
  25.     private $image;
  26.     /**
  27.      * @ORM\Column(type="string", length=2048, nullable=true)
  28.      */
  29.     private $description;
  30.     /**
  31.      * @ORM\Column(type="string", length=255, nullable=true)
  32.      */
  33.     private $label;
  34.     /**
  35.      * @ORM\Column(type="integer")
  36.      */
  37.     private $wttId;
  38.     /**
  39.      * @ORM\OneToMany(targetEntity=Product::class, mappedBy="model")
  40.      */
  41.     private $products;
  42.     /**
  43.      * @ORM\ManyToOne(targetEntity=Manufacturer::class, inversedBy="models")
  44.      */
  45.     private $manufacturer;
  46.     /**
  47.      * @ORM\OneToMany(targetEntity=Stock::class, mappedBy="model")
  48.      */
  49.     private $stocks;
  50.     /**
  51.      * @ORM\ManyToOne(targetEntity=Category::class, inversedBy="models")
  52.      */
  53.     private $category;
  54.     /**
  55.      * @ORM\OneToMany(targetEntity=Attribute::class, mappedBy="model")
  56.      */
  57.     private $attributes;
  58.     public function __construct()
  59.     {
  60.         $this->products = new ArrayCollection();
  61.         $this->stocks = new ArrayCollection();
  62.         $this->attributes = new ArrayCollection();
  63.     }
  64.     public function __toString()
  65.     {
  66.         return $this->getManufacturer()->getName()." ".$this->getName();
  67.     }
  68.     public function getId(): ?int
  69.     {
  70.         return $this->id;
  71.     }
  72.     public function getName(): ?string
  73.     {
  74.         return $this->name;
  75.     }
  76.     public function setName(string $name): self
  77.     {
  78.         $this->name $name;
  79.         return $this;
  80.     }
  81.     public function getImage(): ?string
  82.     {
  83.         return $this->image;
  84.     }
  85.     public function setImage(string $image): self
  86.     {
  87.         $this->image $image;
  88.         return $this;
  89.     }
  90.     public function getLabel(): ?string
  91.     {
  92.         return $this->label;
  93.     }
  94.     public function setLabel(string $label): self
  95.     {
  96.         $this->label $label;
  97.         return $this;
  98.     }
  99.     public function getDescription(): ?string
  100.     {
  101.         return $this->description;
  102.     }
  103.     public function setDescription(string $description): self
  104.     {
  105.         $this->description $description;
  106.         return $this;
  107.     }
  108.     public function getWttId(): ?int
  109.     {
  110.         return $this->wttId;
  111.     }
  112.     public function setWttId(int $wttId): self
  113.     {
  114.         $this->wttId $wttId;
  115.         return $this;
  116.     }
  117.     /**
  118.      * @return Collection<int, Product>
  119.      */
  120.     public function getProducts(): Collection
  121.     {
  122.         return $this->products;
  123.     }
  124.     public function addProduct(Product $product): self
  125.     {
  126.         if (!$this->products->contains($product)) {
  127.             $this->products[] = $product;
  128.             $product->setModel($this);
  129.         }
  130.         return $this;
  131.     }
  132.     public function removeProduct(Product $product): self
  133.     {
  134.         if ($this->products->removeElement($product)) {
  135.             // set the owning side to null (unless already changed)
  136.             if ($product->getModel() === $this) {
  137.                 $product->setModel(null);
  138.             }
  139.         }
  140.         return $this;
  141.     }
  142.     public function getManufacturer(): ?Manufacturer
  143.     {
  144.         return $this->manufacturer;
  145.     }
  146.     public function setManufacturer(?Manufacturer $manufacturer): self
  147.     {
  148.         $this->manufacturer $manufacturer;
  149.         return $this;
  150.     }
  151.     /**
  152.      * @return Collection<int, Stock>
  153.      */
  154.     public function getStocks(): Collection
  155.     {
  156.         return $this->stocks;
  157.     }
  158.     public function addStock(Stock $stock): self
  159.     {
  160.         if (!$this->stocks->contains($stock)) {
  161.             $this->stocks[] = $stock;
  162.             $stock->setModel($this);
  163.         }
  164.         return $this;
  165.     }
  166.     public function removeStock(Stock $stock): self
  167.     {
  168.         if ($this->stocks->removeElement($stock)) {
  169.             // set the owning side to null (unless already changed)
  170.             if ($stock->getModel() === $this) {
  171.                 $stock->setModel(null);
  172.             }
  173.         }
  174.         return $this;
  175.     }
  176.     public function getCategory(): ?Category
  177.     {
  178.         return $this->category;
  179.     }
  180.     public function setCategory(?Category $category): self
  181.     {
  182.         $this->category $category;
  183.         return $this;
  184.     }
  185.     public function getMainReference() {
  186.         $name=$this->getName();
  187.         if (preg_match("/\ (?:1|2|3|4|5|8|16|32|64|128|256|512)(?:GO|GB|TB|TO)/"$name$matches)) {
  188.             if ((int)$matches[0] > 0) {
  189.                 $name trim(preg_replace("/ ".trim($matches[0])."/"''$name));
  190.             }
  191.         }
  192.        // $pattern = '/-GB$/i';
  193.        // $name = preg_replace($pattern, 'aaa', $name);
  194.         $str="W-".$this->getManufacturer()->getName()."-".$name;
  195.         return preg_replace('/ /','-'$str);
  196.     }
  197.     /**
  198.      * @return Collection<int, Attribute>
  199.      */
  200.     public function getAttributes(): Collection
  201.     {
  202.         return $this->attributes;
  203.     }
  204.     public function addAttribute(Attribute $attribute): static
  205.     {
  206.         if (!$this->attributes->contains($attribute)) {
  207.             $this->attributes->add($attribute);
  208.             $attribute->setModel($this);
  209.         }
  210.         return $this;
  211.     }
  212.     public function removeAttribute(Attribute $attribute): static
  213.     {
  214.         if ($this->attributes->removeElement($attribute)) {
  215.             // set the owning side to null (unless already changed)
  216.             if ($attribute->getModel() === $this) {
  217.                 $attribute->setModel(null);
  218.             }
  219.         }
  220.         return $this;
  221.     }
  222. }