src/Entity/Option.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\OptionRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=OptionRepository::class)
  9.  */
  10. class Option
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private ?int $id null;
  18.     public function getId(): ?int
  19.     {
  20.         return $this->id;
  21.     }
  22.     /**
  23.      * @ORM\ManyToOne(targetEntity=Category::class, inversedBy="options")
  24.      */
  25.     private $category;
  26.     /**
  27.      * @ORM\ManyToOne(targetEntity=Attribute::class, inversedBy="options")
  28.      */
  29.     private $attribute;
  30.     /**
  31.      * @ORM\Column(type="string", length=255, nullable=true)
  32.      */
  33.     private $attributeValue;
  34.     /**
  35.      * @ORM\Column(type="string", length=255)
  36.      */
  37.     private $name;
  38.     /**
  39.      * @ORM\Column(type="string", length=128)
  40.      */
  41.     private $price;
  42.     /**
  43.      * @ORM\Column(type="string", length=128, nullable=true)
  44.      */
  45.     private $target;
  46.     /**
  47.      * @ORM\ManyToMany(targetEntity=Shop::class, inversedBy="options", cascade={"persist"})
  48.      * @ORM\JoinColumn(nullable=false)
  49.      */
  50.     private $shops;
  51.     /**
  52.      * @ORM\ManyToMany(targetEntity=Cart::class, inversedBy="options", cascade={"persist"})
  53.      * @ORM\JoinColumn(nullable=false)
  54.      */
  55.     private $cart;
  56.     /**
  57.      * @ORM\ManyToMany(targetEntity=Stock::class, inversedBy="options", cascade={"persist"})
  58.      * @ORM\JoinColumn(nullable=false)
  59.      */
  60.     private $stock;
  61.     /**
  62.      * @ORM\ManyToMany(targetEntity=Order::class, inversedBy="options", cascade={"persist"})
  63.      * @ORM\JoinColumn(nullable=false)
  64.      */
  65.     private $order;
  66.     private $fullName;
  67.     public function __construct()
  68.     {
  69.         $this->cart = new ArrayCollection();
  70.         $this->stock = new ArrayCollection();
  71.         $this->order = new ArrayCollection();
  72.         $this->shops = new ArrayCollection();
  73.     }
  74.     public function __toString() {
  75.         return $this->name."(".$this->id.")";
  76.     }
  77.     public function getFullName(): ?string
  78.     {
  79.         return $this->category." " .$this->name" (".(preg_match('/%/',$this->price)?$this->price:($this->price/100).' €').")";
  80.     }
  81.     public function getName(): ?string
  82.     {
  83.         return $this->name;
  84.     }
  85.     public function setName(string $name): static
  86.     {
  87.         $this->name $name;
  88.         return $this;
  89.     }
  90.     public function getPrice(): ?string
  91.     {
  92.         return $this->price;
  93.     }
  94.     public function setPrice(string $price): static
  95.     {
  96.         $this->price $price;
  97.         return $this;
  98.     }
  99.     public function getCategory(): ?Category
  100.     {
  101.         return $this->category;
  102.     }
  103.     public function setCategory(?Category $category): static
  104.     {
  105.         $this->category $category;
  106.         return $this;
  107.     }
  108.     public function getAttribute(): ?Attribute
  109.     {
  110.         return $this->attribute;
  111.     }
  112.     public function setAttribute(?Attribute $attribute): static
  113.     {
  114.         $this->attribute $attribute;
  115.         return $this;
  116.     }
  117.     public function getAttributeValue(): ?string
  118.     {
  119.         return $this->attributeValue;
  120.     }
  121.     public function setAttributeValue(?string $attributeValue): static
  122.     {
  123.         $this->attributeValue $attributeValue;
  124.         return $this;
  125.     }
  126.     /**
  127.      * @return Collection<int, Shop>
  128.      */
  129.     public function getShops(): ?Collection
  130.     {
  131.         return $this->shops;
  132.     }
  133.     public function addShop(Shop $shop): static
  134.     {
  135.         if (!$this->shops->contains($shop)) {
  136.             $this->shops->add($shop);
  137.         }
  138.         return $this;
  139.     }
  140.     public function removeShop(Shop $shop): static
  141.     {
  142.         $this->shops->removeElement($shop);
  143.         return $this;
  144.     }
  145.     /**
  146.      * @return Collection<int, Cart>
  147.      */
  148.     public function getCart(): Collection
  149.     {
  150.         return $this->cart;
  151.     }
  152.     public function addCart(Cart $cart): static
  153.     {
  154.         if (!$this->cart->contains($cart)) {
  155.             $this->cart->add($cart);
  156.         }
  157.         return $this;
  158.     }
  159.     public function removeCart(Cart $cart): static
  160.     {
  161.         $this->cart->removeElement($cart);
  162.         return $this;
  163.     }
  164.     /**
  165.      * @return Collection<int, Stock>
  166.      */
  167.     public function getStock(): Collection
  168.     {
  169.         return $this->stock;
  170.     }
  171.     public function addStock(Stock $stock): static
  172.     {
  173.         if (!$this->stock->contains($stock)) {
  174.             $this->stock->add($stock);
  175.         }
  176.         return $this;
  177.     }
  178.     public function removeStock(Stock $stock): static
  179.     {
  180.         $this->stock->removeElement($stock);
  181.         return $this;
  182.     }
  183.     public function getOptionPrice($price):int {
  184.         if(str_contains($this->getPrice(),'%')) {
  185.             $price=$price + (($price*(int)$this->getPrice())/100);
  186.         }
  187.         else {
  188.             $price=$price +(int)$this->getPrice();
  189.         }
  190.         return (int)$price;
  191.     }
  192.     public function getTarget(): ?string
  193.     {
  194.         return $this->target;
  195.     }
  196.     public function setTarget(string $target): static
  197.     {
  198.         $this->target $target;
  199.         return $this;
  200.     }
  201.     /**
  202.      * @return Collection<int, Order>
  203.      */
  204.     public function getOrder(): Collection
  205.     {
  206.         return $this->order;
  207.     }
  208.     public function addOrder(Order $order): static
  209.     {
  210.         if (!$this->order->contains($order)) {
  211.             $this->order->add($order);
  212.         }
  213.         return $this;
  214.     }
  215.     public function removeOrder(Order $order): static
  216.     {
  217.         $this->order->removeElement($order);
  218.         return $this;
  219.     }
  220. }