|
|
@ -4,68 +4,115 @@ namespace App\Entity;
|
|
|
|
|
|
|
|
|
|
|
|
use App\Repository\TagRepository;
|
|
|
|
use App\Repository\TagRepository;
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
|
use Doctrine\Common\Collections\Collection;
|
|
|
|
use Doctrine\DBAL\Types\Types;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
|
|
|
|
use Gedmo\Mapping\Annotation as Gedmo;
|
|
|
|
|
|
|
|
use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* A tag
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Tags are by user and a “materialized path” tree structure
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @link https://github.com/doctrine-extensions/DoctrineExtensions/blob/main/doc/tree.md#materialized-path
|
|
|
|
|
|
|
|
*/
|
|
|
|
#[ORM\Entity(repositoryClass: TagRepository::class)]
|
|
|
|
#[ORM\Entity(repositoryClass: TagRepository::class)]
|
|
|
|
class Tag
|
|
|
|
#[Gedmo\Tree(type: 'materializedPath')]
|
|
|
|
{
|
|
|
|
class Tag {
|
|
|
|
#[ORM\Id]
|
|
|
|
use TEntityBase;
|
|
|
|
#[ORM\GeneratedValue]
|
|
|
|
|
|
|
|
#[ORM\Column]
|
|
|
|
|
|
|
|
private ?int $id = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @var User|null The owner
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#[ORM\ManyToOne(inversedBy: 'tags')]
|
|
|
|
|
|
|
|
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
|
|
|
|
|
|
|
|
#[Assert\Valid]
|
|
|
|
|
|
|
|
private ?User $owner = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @var string|null The name
|
|
|
|
|
|
|
|
*/
|
|
|
|
#[ORM\Column(length: 50)]
|
|
|
|
#[ORM\Column(length: 50)]
|
|
|
|
|
|
|
|
#[Gedmo\TreePathSource]
|
|
|
|
|
|
|
|
#[Assert\NotBlank]
|
|
|
|
private ?string $name = null;
|
|
|
|
private ?string $name = null;
|
|
|
|
|
|
|
|
|
|
|
|
#[ORM\ManyToMany(targetEntity: Document::class, mappedBy: 'tags')]
|
|
|
|
/**
|
|
|
|
private Collection $documents;
|
|
|
|
* @var string|null The path (complete name)
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#[ORM\Column(type: Types::TEXT)]
|
|
|
|
|
|
|
|
#[Gedmo\TreePath]
|
|
|
|
|
|
|
|
#[Assert\NotBlank]
|
|
|
|
|
|
|
|
private ?string $path = null;
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
/**
|
|
|
|
{
|
|
|
|
* Initialization
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function __construct () {
|
|
|
|
$this->documents = new ArrayCollection();
|
|
|
|
$this->documents = new ArrayCollection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getId(): ?int
|
|
|
|
/**
|
|
|
|
{
|
|
|
|
* The owner
|
|
|
|
return $this->id;
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return User|null The owner
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function getOwner (): ?User {
|
|
|
|
|
|
|
|
return $this->owner;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Change the owner
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param User $owner The new owner
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return $this
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function setOwner (User $owner): static {
|
|
|
|
|
|
|
|
$this->owner = $owner;
|
|
|
|
|
|
|
|
|
|
|
|
public function getName(): ?string
|
|
|
|
return $this;
|
|
|
|
{
|
|
|
|
|
|
|
|
return $this->name;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function setName(string $name): self
|
|
|
|
/**
|
|
|
|
{
|
|
|
|
* The name
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return string|null The name
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function getName (): ?string {
|
|
|
|
|
|
|
|
return $this->name;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Change the name
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param string $name The new name
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return $this
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function setName (string $name): self {
|
|
|
|
$this->name = $name;
|
|
|
|
$this->name = $name;
|
|
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @return Collection<int, Document>
|
|
|
|
* The path (complete name)
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return string|null The path (complete name)
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function getDocuments(): Collection
|
|
|
|
public function getPath (): ?string
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return $this->documents;
|
|
|
|
return $this->path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
public function addDocument(Document $document): self
|
|
|
|
* Change the path (complete name)
|
|
|
|
{
|
|
|
|
*
|
|
|
|
if (!$this->documents->contains($document)) {
|
|
|
|
* @param string $path The new path (complete name)
|
|
|
|
$this->documents->add($document);
|
|
|
|
*
|
|
|
|
$document->addTag($this);
|
|
|
|
* @return $this
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
public function setPath (string $path): static
|
|
|
|
return $this;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function removeDocument(Document $document): self
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if ($this->documents->removeElement($document)) {
|
|
|
|
$this->path = $path;
|
|
|
|
$document->removeTag($this);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|