src/Entity/Category.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8. * @ORM\Entity(repositoryClass=CategoryRepository::class)
  9. */
  10. class Category
  11. {
  12. /**
  13. * @ORM\Id
  14. * @ORM\GeneratedValue
  15. * @ORM\Column(type="integer")
  16. */
  17. private $id;
  18. /**
  19. * @ORM\Column(type="string", length=255)
  20. */
  21. private $name;
  22. /**
  23. * @ORM\OneToMany(targetEntity=ProductType::class, mappedBy="category")
  24. */
  25. private $productTypes;
  26. public function __construct()
  27. {
  28. $this->productTypes = new ArrayCollection();
  29. }
  30. public function __toString() {
  31. return $this->name;
  32. }
  33. public function getId(): ?int
  34. {
  35. return $this->id;
  36. }
  37. public function getName(): ?string
  38. {
  39. return $this->name;
  40. }
  41. public function setName(string $name): self
  42. {
  43. $this->name = $name;
  44. return $this;
  45. }
  46. /**
  47. * @return Collection<int, ProductType>
  48. */
  49. public function getProductTypes(): Collection
  50. {
  51. return $this->productTypes;
  52. }
  53. public function addProductType(ProductType $productType): self
  54. {
  55. if (!$this->productTypes->contains($productType)) {
  56. $this->productTypes[] = $productType;
  57. $productType->setCategory($this);
  58. }
  59. return $this;
  60. }
  61. public function removeProductType(ProductType $productType): self
  62. {
  63. if ($this->productTypes->removeElement($productType)) {
  64. // set the owning side to null (unless already changed)
  65. if ($productType->getCategory() === $this) {
  66. $productType->setCategory(null);
  67. }
  68. }
  69. return $this;
  70. }
  71. }