<?php
namespace App\Entity;
use App\Entity\Trait\CreatedAtTrait;
use App\Entity\Trait\SlugTrait;
use App\Repository\CategoriesRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: CategoriesRepository::class)]
class Categories
{
use CreatedAtTrait;
use SlugTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 100)]
private ?string $name = null;
#[ORM\Column(type: 'integer')]
private $categoryOrder;
// #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'categories')]
// #[ORM\JoinColumn(onDelete: 'CASCADE')]
// private ?self $parent = null;
// #[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
// private Collection $categories;
#[ORM\OneToMany(mappedBy: 'categories', targetEntity: Products::class)]
private Collection $products;
#[ORM\Column(length: 255)]
private ?string $description = null;
/**** #[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $createdAt = null; ***/
public function __construct()
{
// $this->categories = new ArrayCollection();
$this->products = new ArrayCollection();
$this->created_at = new \DateTimeImmutable();
//// $this->createdAt = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getCategoryOrder(): ?int
{
return $this->categoryOrder;
}
public function setCategoryOrder(int $categoryOrder): self
{
$this->categoryOrder = $categoryOrder;
return $this;
}
/*****
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): static
{
$this->parent = $parent;
return $this;
} ****/
/*
/**
* @return Collection<int, self>
*/
/********
public function getCategories(): Collection
{
return $this->categories;
}
public function addCategory(self $category): static
{
if (!$this->categories->contains($category)) {
$this->categories->add($category);
$category->setParent($this);
}
return $this;
}
public function removeCategory(self $category): static
{
if ($this->categories->removeElement($category)) {
// set the owning side to null (unless already changed)
if ($category->getParent() === $this) {
$category->setParent(null);
}
}
return $this;
} *******/
/**
* @return Collection<int, Products>
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Products $product): static
{
if (!$this->products->contains($product)) {
$this->products->add($product);
$product->setCategories($this);
}
return $this;
}
public function removeProduct(Products $product): static
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getCategories() === $this) {
$product->setCategories(null);
}
}
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): static
{
$this->description = $description;
return $this;
}
/*****
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(?\DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
*****/
}