Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Entity;
- use Doctrine\Common\Collections\ArrayCollection;
- use Doctrine\Common\Collections\Collection;
- use Doctrine\DBAL\Types\Types;
- use Doctrine\ORM\Mapping as ORM;
- use Gedmo\Mapping\Annotation as Gedmo;
- use Gedmo\Tree\Entity\Repository\NestedTreeRepository;
- #[Gedmo\Tree(type: 'nested')]
- #[ORM\Entity(repositoryClass: NestedTreeRepository::class)]
- class Category
- {
- #[ORM\Id]
- #[ORM\GeneratedValue]
- #[ORM\Column(type: Types::INTEGER)]
- private $id;
- #[ORM\Column(name: 'name', type: Types::STRING, length: 80)]
- private $name;
- #[Gedmo\TreeLeft]
- #[ORM\Column(name: 'lft', type: Types::INTEGER)]
- private $lft;
- #[Gedmo\TreeLevel]
- #[ORM\Column(name: 'lvl', type: Types::INTEGER)]
- private $lvl;
- #[Gedmo\TreeRight]
- #[ORM\Column(name: 'rgt', type: Types::INTEGER)]
- private $rgt;
- #[Gedmo\TreeRoot]
- #[ORM\ManyToOne(targetEntity: Category::class)]
- #[ORM\JoinColumn(name: 'tree_root', referencedColumnName: 'id', onDelete: 'CASCADE')]
- private $root;
- #[Gedmo\TreeParent]
- #[ORM\ManyToOne(targetEntity: Category::class, inversedBy: 'children')]
- #[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
- private $parent;
- #[ORM\OneToMany(targetEntity: Category::class, mappedBy: 'parent')]
- #[ORM\OrderBy(['lft' => 'ASC'])]
- private $children;
- #[ORM\OneToMany(mappedBy: 'category', targetEntity: Product::class)]
- private Collection $products;
- #[ORM\ManyToMany(targetEntity: Property::class, mappedBy: 'category')]
- private Collection $properties;
- public function __construct()
- {
- $this->products = new ArrayCollection();
- $this->properties = new ArrayCollection();
- }
- public function getId(): ?int
- {
- return $this->id;
- }
- public function setName(?string $name): void
- {
- $this->name = $name;
- }
- public function getName(): ?string
- {
- return $this->name;
- }
- public function getRoot(): ?self
- {
- return $this->root;
- }
- public function setParent(self $parent = null): void
- {
- $this->parent = $parent;
- }
- public function getParent(): ?self
- {
- return $this->parent;
- }
- /**
- * @return Collection<int, Product>
- */
- public function getProducts(): Collection
- {
- return $this->products;
- }
- public function addProduct(Product $product): self
- {
- if (!$this->products->contains($product)) {
- $this->products->add($product);
- $product->setCategory($this);
- }
- return $this;
- }
- public function removeProduct(Product $product): self
- {
- if ($this->products->removeElement($product)) {
- // set the owning side to null (unless already changed)
- if ($product->getCategory() === $this) {
- $product->setCategory(null);
- }
- }
- return $this;
- }
- /**
- * @return Collection<int, Property>
- */
- public function getProperties(): Collection
- {
- return $this->properties;
- }
- public function addProperty(Property $property): self
- {
- if (!$this->properties->contains($property)) {
- $this->properties->add($property);
- $property->addCategory($this);
- }
- return $this;
- }
- public function removeProperty(Property $property): self
- {
- if ($this->properties->removeElement($property)) {
- $property->removeCategory($this);
- }
- return $this;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment