hesabixSite/src/Entity/Tree.php

126 lines
2.3 KiB
PHP

<?php
namespace App\Entity;
use App\Repository\TreeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: TreeRepository::class)]
class Tree
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'trees')]
#[ORM\JoinColumn(nullable: false)]
private ?Cat $cat = null;
#[ORM\Column(length: 255)]
private ?string $label = null;
#[ORM\Column(length: 255)]
private ?string $code = null;
#[ORM\Column(length: 50, nullable: true)]
private ?string $sort = null;
/**
* @var Collection<int, Post>
*/
#[ORM\ManyToMany(targetEntity: Post::class, mappedBy: 'tree')]
private Collection $posts;
public function __construct()
{
$this->posts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCat(): ?Cat
{
return $this->cat;
}
public function setCat(?Cat $cat): static
{
$this->cat = $cat;
return $this;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): static
{
$this->label = $label;
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): static
{
$this->code = $code;
return $this;
}
public function getSort(): ?string
{
return $this->sort;
}
public function setSort(?string $sort): static
{
$this->sort = $sort;
return $this;
}
/**
* @return Collection<int, Post>
*/
public function getPosts(): Collection
{
return $this->posts;
}
public function addPost(Post $post): static
{
if (!$this->posts->contains($post)) {
$this->posts->add($post);
$post->addTree($this);
}
return $this;
}
public function removePost(Post $post): static
{
if ($this->posts->removeElement($post)) {
$post->removeTree($this);
}
return $this;
}
public function __toString(): string
{
return $this->getLabel();
}
}