src/Entity/ProductColor.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Knp\DoctrineBehaviors\Contract\Entity\SoftDeletableInterface;
  4. use Knp\DoctrineBehaviors\Model\SoftDeletable\SoftDeletableTrait;
  5. use Knp\DoctrineBehaviors\Model\Blameable\BlameableTrait;
  6. use Knp\DoctrineBehaviors\Contract\Entity\BlameableInterface;
  7. use Knp\DoctrineBehaviors\Model\Timestampable\TimestampableTrait;
  8. use Knp\DoctrineBehaviors\Contract\Entity\TimestampableInterface;
  9. use Knp\DoctrineBehaviors\Model\Translatable\TranslatableTrait;
  10. use Knp\DoctrineBehaviors\Contract\Entity\TranslatableInterface;
  11. use App\Model\LangParamInterface;
  12. use App\Model\LangParamRelationInterface;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use Doctrine\Common\Collections\Collection;
  15. use Symfony\Contracts\Translation\TranslatorInterface;
  16. use Doctrine\ORM\Mapping as ORM;
  17. /**
  18.  *
  19.  * https://stackoverflow.com/questions/24322599/why-cannot-change-checkbox-color-whatever-i-do
  20.  * https://stackoverflow.com/questions/66383850/checkbox-css-cannot-change-background-color-for-the-checkbox
  21.  *
  22.  * @Doctrine\ORM\Mapping\Entity
  23.  * @Doctrine\ORM\Mapping\Table(name="product_color")
  24.  */
  25. class ProductColor implements TranslatableInterfaceBlameableInterfaceTimestampableInterfaceSoftDeletableInterface  {
  26.     use BlameableTrait;
  27.     use TimestampableTrait;
  28.     use TranslatableTrait;
  29.     use SoftDeletableTrait;
  30.     
  31.     
  32.     
  33.     /**
  34.      * @Doctrine\ORM\Mapping\Id
  35.      * @Doctrine\ORM\Mapping\Column(type="integer")
  36.      * @Doctrine\ORM\Mapping\GeneratedValue(strategy="AUTO")
  37.      */
  38.     protected $id;
  39.     /**
  40.      * @var string
  41.      *
  42.      * @Doctrine\ORM\Mapping\Column(name="group_name", type="text", nullable=true)
  43.      */
  44.     private $color;
  45.     /**
  46.      * Many colors have many products
  47.      * @Doctrine\ORM\Mapping\ManyToMany(targetEntity="App\Entity\Product", mappedBy="colors")
  48.      */
  49.     private $products;
  50.     public function __construct()
  51.     {
  52.         $this->products = new ArrayCollection();
  53.     }
  54.     /**
  55.      * Obsługa tłumaczeń
  56.      * @param $method
  57.      * @param $arguments
  58.      * @return mixed
  59.      */
  60.     public function __call($method$arguments)
  61.     {
  62.         return $this->proxyCurrentLocaleTranslation($method$arguments);
  63.     }
  64.     public function getName()
  65.     {
  66.         return $this->translate()->getName();
  67.     }
  68.     
  69.     public function getId(): ?int
  70.     {
  71.         return $this->id;
  72.     }
  73.     /**
  74.      * @return string
  75.      */
  76.     public function getColor()
  77.     {
  78.         return $this->color;
  79.     }
  80.     /**
  81.      * @param string $color
  82.      */
  83.     public function setColor($color)
  84.     {
  85.         $this->color $color;
  86.     }
  87.     /**
  88.      * @return Collection|Product[]
  89.      */
  90.     public function getProducts(): Collection
  91.     {
  92.         return $this->products;
  93.     }
  94.     public function addProduct(Product $product): self
  95.     {
  96.         if (!$this->products->contains($product)) {
  97.             $this->products[] = $product;
  98.             $product->addColor($this);
  99.         }
  100.         return $this;
  101.     }
  102.     public function removeProduct(Product $product): self
  103.     {
  104.         if ($this->products->removeElement($product)) {
  105.             $product->removeColor($this);
  106.         }
  107.         return $this;
  108.     }
  109. }