src/Entity/Slave/ProductSubcategory.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_subcategory")
  9.  * @ORM\Entity(repositoryClass="App\Repository\Slave\ProductSubcategoryRepository")
  10.  */
  11. class ProductSubcategory
  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.     // ManyToOne
  33.         /**
  34.          * @ORM\ManyToOne(targetEntity="App\Entity\Slave\ProductCategory", inversedBy="subcategories")
  35.          * @ORM\JoinColumn(name="category_id", referencedColumnName="id")
  36.          */
  37.         private $category;
  38.     //
  39.     // OneToMany
  40.         /**
  41.          * @ORM\OneToMany(targetEntity="App\Entity\Slave\ProductModel", mappedBy="subcategory")
  42.          */
  43.         private $models;
  44.     //
  45.     public function __construct()
  46.     {
  47.         $this->models = new ArrayCollection();
  48.     }
  49.     public function getId(): ?string
  50.     {
  51.         return $this->id;
  52.     }
  53.     public function getName(): ?string
  54.     {
  55.         return $this->name;
  56.     }
  57.     public function setName(string $name): self
  58.     {
  59.         $this->name $name;
  60.         return $this;
  61.     }
  62.     public function getCategory(): ?ProductCategory
  63.     {
  64.         return $this->category;
  65.     }
  66.     public function setCategory(?ProductCategory $category): self
  67.     {
  68.         $this->category $category;
  69.         return $this;
  70.     }
  71.     /**
  72.      * @return Collection<int, ProductModel>
  73.      */
  74.     public function getModels(): Collection
  75.     {
  76.         return $this->models;
  77.     }
  78.     public function addModel(ProductModel $model): self
  79.     {
  80.         if (!$this->models->contains($model)) {
  81.             $this->models->add($model);
  82.             $model->setSubcategory($this);
  83.         }
  84.         return $this;
  85.     }
  86.     public function removeModel(ProductModel $model): self
  87.     {
  88.         if ($this->models->removeElement($model)) {
  89.             // set the owning side to null (unless already changed)
  90.             if ($model->getSubcategory() === $this) {
  91.                 $model->setSubcategory(null);
  92.             }
  93.         }
  94.         return $this;
  95.     }
  96. }