<?php
namespace App\Entity;
use App\Repository\OptionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=OptionRepository::class)
*/
class Option
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private ?int $id = null;
public function getId(): ?int
{
return $this->id;
}
/**
* @ORM\ManyToOne(targetEntity=Category::class, inversedBy="options")
*/
private $category;
/**
* @ORM\ManyToOne(targetEntity=Attribute::class, inversedBy="options")
*/
private $attribute;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $attributeValue;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=128)
*/
private $price;
/**
* @ORM\Column(type="string", length=128, nullable=true)
*/
private $target;
/**
* @ORM\ManyToMany(targetEntity=Shop::class, inversedBy="options", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
*/
private $shops;
/**
* @ORM\ManyToMany(targetEntity=Cart::class, inversedBy="options", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
*/
private $cart;
/**
* @ORM\ManyToMany(targetEntity=Stock::class, inversedBy="options", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
*/
private $stock;
/**
* @ORM\ManyToMany(targetEntity=Order::class, inversedBy="options", cascade={"persist"})
* @ORM\JoinColumn(nullable=false)
*/
private $order;
private $fullName;
public function __construct()
{
$this->cart = new ArrayCollection();
$this->stock = new ArrayCollection();
$this->order = new ArrayCollection();
$this->shops = new ArrayCollection();
}
public function __toString() {
return $this->name."(".$this->id.")";
}
public function getFullName(): ?string
{
return $this->category." " .$this->name. " (".(preg_match('/%/',$this->price)?$this->price:($this->price/100).' €').")";
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getPrice(): ?string
{
return $this->price;
}
public function setPrice(string $price): static
{
$this->price = $price;
return $this;
}
public function getCategory(): ?Category
{
return $this->category;
}
public function setCategory(?Category $category): static
{
$this->category = $category;
return $this;
}
public function getAttribute(): ?Attribute
{
return $this->attribute;
}
public function setAttribute(?Attribute $attribute): static
{
$this->attribute = $attribute;
return $this;
}
public function getAttributeValue(): ?string
{
return $this->attributeValue;
}
public function setAttributeValue(?string $attributeValue): static
{
$this->attributeValue = $attributeValue;
return $this;
}
/**
* @return Collection<int, Shop>
*/
public function getShops(): ?Collection
{
return $this->shops;
}
public function addShop(Shop $shop): static
{
if (!$this->shops->contains($shop)) {
$this->shops->add($shop);
}
return $this;
}
public function removeShop(Shop $shop): static
{
$this->shops->removeElement($shop);
return $this;
}
/**
* @return Collection<int, Cart>
*/
public function getCart(): Collection
{
return $this->cart;
}
public function addCart(Cart $cart): static
{
if (!$this->cart->contains($cart)) {
$this->cart->add($cart);
}
return $this;
}
public function removeCart(Cart $cart): static
{
$this->cart->removeElement($cart);
return $this;
}
/**
* @return Collection<int, Stock>
*/
public function getStock(): Collection
{
return $this->stock;
}
public function addStock(Stock $stock): static
{
if (!$this->stock->contains($stock)) {
$this->stock->add($stock);
}
return $this;
}
public function removeStock(Stock $stock): static
{
$this->stock->removeElement($stock);
return $this;
}
public function getOptionPrice($price):int {
if(str_contains($this->getPrice(),'%')) {
$price=$price + (($price*(int)$this->getPrice())/100);
}
else {
$price=$price +(int)$this->getPrice();
}
return (int)$price;
}
public function getTarget(): ?string
{
return $this->target;
}
public function setTarget(string $target): static
{
$this->target = $target;
return $this;
}
/**
* @return Collection<int, Order>
*/
public function getOrder(): Collection
{
return $this->order;
}
public function addOrder(Order $order): static
{
if (!$this->order->contains($order)) {
$this->order->add($order);
}
return $this;
}
public function removeOrder(Order $order): static
{
$this->order->removeElement($order);
return $this;
}
}