src/Entity/Slave/ProductComponent.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Slave;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Table(name="eposm_s_product_component")
  9.  * @ORM\Entity(repositoryClass="App\Repository\Slave\ProductComponentRepository")
  10.  */
  11. class ProductComponent
  12. {       
  13.     public function __toString(){
  14.         return $this->getName();
  15.     }
  16.     
  17.     public function getCanDelete(){
  18.         if(sizeof($this->models) > 0) return false;
  19.         return true;
  20.     }
  21.     /**
  22.      * @ORM\Column(name="id", type="bigint")
  23.      * @ORM\Id
  24.      * @ORM\GeneratedValue(strategy="AUTO")
  25.      */
  26.     protected $id;
  27.     
  28.     /**
  29.      * @ORM\Column(name="name", type="string", length=191)
  30.      */
  31.     protected $name;
  32.     // ManyToMany
  33.         /**
  34.          * @ORM\ManyToMany(targetEntity="App\Entity\Slave\ProductModel", mappedBy="components")
  35.          */
  36.         private $models;
  37.         public function __construct()
  38.         {
  39.             $this->models = new ArrayCollection();
  40.         }
  41.         public function getId(): ?string
  42.         {
  43.             return $this->id;
  44.         }
  45.         public function getName(): ?string
  46.         {
  47.             return $this->name;
  48.         }
  49.         public function setName(string $name): static
  50.         {
  51.             $this->name $name;
  52.             return $this;
  53.         }
  54.         /**
  55.          * @return Collection<int, ProductModel>
  56.          */
  57.         public function getModels(): Collection
  58.         {
  59.             return $this->models;
  60.         }
  61.         public function addModel(ProductModel $model): static
  62.         {
  63.             if (!$this->models->contains($model)) {
  64.                 $this->models->add($model);
  65.                 $model->addComponent($this);
  66.             }
  67.             return $this;
  68.         }
  69.         public function removeModel(ProductModel $model): static
  70.         {
  71.             if ($this->models->removeElement($model)) {
  72.                 $model->removeComponent($this);
  73.             }
  74.             return $this;
  75.         }
  76. }