|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of the Doctrine Behavioral Extensions package. |
| 7 | + * (c) Gediminas Morkevicius <[email protected]> http://www.gediminasm.org |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Gedmo\Tests\Tree\Fixture\Issue2701; |
| 13 | + |
| 14 | +use Doctrine\Common\Collections\ArrayCollection; |
| 15 | +use Doctrine\Common\Collections\Collection; |
| 16 | +use Doctrine\DBAL\Types\Types; |
| 17 | +use Doctrine\ORM\Mapping as ORM; |
| 18 | +use Gedmo\Mapping\Annotation as Gedmo; |
| 19 | +use Gedmo\Tree\Entity\Repository\NestedTreeRepository; |
| 20 | +use Symfony\Bridge\Doctrine\Types\UlidType; |
| 21 | +use Symfony\Component\Uid\Ulid; |
| 22 | + |
| 23 | +/** |
| 24 | + * @Gedmo\Tree(type="nested") |
| 25 | + * |
| 26 | + * @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository") |
| 27 | + * @ORM\Table(indexes={@ORM\Index(columns={"lft", "rgt"}, name="idx_tree")}) |
| 28 | + */ |
| 29 | +#[Gedmo\Tree(type: 'nested')] |
| 30 | +#[ORM\Entity(repositoryClass: NestedTreeRepository::class)] |
| 31 | +#[ORM\Index(columns: ['lft', 'rgt'], name: 'idx_tree')] |
| 32 | +class Category |
| 33 | +{ |
| 34 | + /** |
| 35 | + * @ORM\Column(type="ulid", unique=true) |
| 36 | + * @ORM\Id |
| 37 | + * @ORM\GeneratedValue(strategy="CUSTOM") |
| 38 | + * @ORM\CustomIdGenerator(class="doctrine.ulid_generator") |
| 39 | + */ |
| 40 | + #[ORM\Id] |
| 41 | + #[ORM\Column(type: UlidType::NAME, unique: true)] |
| 42 | + #[ORM\GeneratedValue(strategy: 'CUSTOM')] |
| 43 | + #[ORM\CustomIdGenerator(class: 'doctrine.ulid_generator')] |
| 44 | + private ?Ulid $id = null; |
| 45 | + |
| 46 | + /** |
| 47 | + * @ORM\Column(length=255) |
| 48 | + */ |
| 49 | + #[ORM\Column(length: 255)] |
| 50 | + private ?string $name = null; |
| 51 | + |
| 52 | + /** |
| 53 | + * @Gedmo\TreeLeft |
| 54 | + * |
| 55 | + * @ORM\Column(name="lft", type="integer") |
| 56 | + */ |
| 57 | + #[Gedmo\TreeLeft] |
| 58 | + #[ORM\Column(name: 'lft', type: Types::INTEGER)] |
| 59 | + public ?int $lft; |
| 60 | + |
| 61 | + /** |
| 62 | + * @Gedmo\TreeLevel |
| 63 | + * |
| 64 | + * @ORM\Column(name="lvl", type="integer") |
| 65 | + */ |
| 66 | + #[Gedmo\TreeLevel] |
| 67 | + #[ORM\Column(name: 'lvl', type: Types::INTEGER)] |
| 68 | + private ?int $lvl; |
| 69 | + |
| 70 | + /** |
| 71 | + * @Gedmo\TreeRight |
| 72 | + * |
| 73 | + * @ORM\Column(name="rgt", type="integer") |
| 74 | + */ |
| 75 | + #[Gedmo\TreeRight] |
| 76 | + #[ORM\Column(name: 'rgt', type: Types::INTEGER)] |
| 77 | + public ?int $rgt; |
| 78 | + |
| 79 | + /** |
| 80 | + * @Gedmo\TreeRoot |
| 81 | + * |
| 82 | + * @ORM\ManyToOne(targetEntity="Gedmo\Tests\Tree\Fixture\Issue2701\Category") |
| 83 | + * @ORM\JoinColumn(name="tree_root", referencedColumnName="id", onDelete="CASCADE") |
| 84 | + */ |
| 85 | + #[Gedmo\TreeRoot] |
| 86 | + #[ORM\ManyToOne(targetEntity: self::class)] |
| 87 | + #[ORM\JoinColumn(name: 'tree_root', referencedColumnName: 'id', onDelete: 'CASCADE')] |
| 88 | + private ?self $root; |
| 89 | + |
| 90 | + /** |
| 91 | + * @Gedmo\TreeParent |
| 92 | + * |
| 93 | + * @ORM\ManyToOne(targetEntity="Gedmo\Tests\Tree\Fixture\Issue2701\Category", inversedBy="children") |
| 94 | + * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE") |
| 95 | + */ |
| 96 | + #[Gedmo\TreeParent] |
| 97 | + #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')] |
| 98 | + #[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', onDelete: 'CASCADE')] |
| 99 | + private ?self $parent; |
| 100 | + |
| 101 | + /** |
| 102 | + * @var Collection<int, self>|self[] |
| 103 | + * |
| 104 | + * @ORM\OneToMany(targetEntity="Gedmo\Tests\Tree\Fixture\Issue2701\Category", mappedBy="parent") |
| 105 | + * @ORM\OrderBy({"lft" = "ASC"}) |
| 106 | + */ |
| 107 | + #[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')] |
| 108 | + #[ORM\OrderBy(['lft' => 'ASC'])] |
| 109 | + private Collection $children; |
| 110 | + |
| 111 | + public function __construct() |
| 112 | + { |
| 113 | + $this->children = new ArrayCollection(); |
| 114 | + } |
| 115 | + |
| 116 | + public function getId(): ?Ulid |
| 117 | + { |
| 118 | + return $this->id; |
| 119 | + } |
| 120 | + |
| 121 | + public function getName(): ?string |
| 122 | + { |
| 123 | + return $this->name; |
| 124 | + } |
| 125 | + |
| 126 | + public function setName(string $name): static |
| 127 | + { |
| 128 | + $this->name = $name; |
| 129 | + |
| 130 | + return $this; |
| 131 | + } |
| 132 | + |
| 133 | + public function setTranslatableLocale(string $locale): void |
| 134 | + { |
| 135 | + $this->locale = $locale; |
| 136 | + } |
| 137 | + |
| 138 | + public function getRoot(): ?self |
| 139 | + { |
| 140 | + return $this->root; |
| 141 | + } |
| 142 | + |
| 143 | + public function setParent(?self $parent = null): void |
| 144 | + { |
| 145 | + $this->parent = $parent; |
| 146 | + } |
| 147 | + |
| 148 | + public function getParent(): ?self |
| 149 | + { |
| 150 | + return $this->parent; |
| 151 | + } |
| 152 | +} |
0 commit comments