|
| 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\Issue2517; |
| 13 | + |
| 14 | +use Doctrine\Common\Collections\Collection; |
| 15 | +use Doctrine\DBAL\Types\Types; |
| 16 | +use Doctrine\ORM\Mapping as ORM; |
| 17 | +use Gedmo\Mapping\Annotation as Gedmo; |
| 18 | +use Gedmo\Tree\Entity\Repository\NestedTreeRepository; |
| 19 | + |
| 20 | +/** |
| 21 | + * @Gedmo\Tree(type="nested") |
| 22 | + * @ORM\Table(name="categories") |
| 23 | + * @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository") |
| 24 | + */ |
| 25 | +#[Gedmo\Tree(type: 'nested')] |
| 26 | +#[ORM\Table(name: 'categories')] |
| 27 | +#[ORM\Entity(repositoryClass: NestedTreeRepository::class)] |
| 28 | +class Category |
| 29 | +{ |
| 30 | + /** |
| 31 | + * @var int|null |
| 32 | + * |
| 33 | + * @ORM\Column(name="id", type="integer") |
| 34 | + * @ORM\Id |
| 35 | + * @ORM\GeneratedValue |
| 36 | + */ |
| 37 | + #[ORM\Id] |
| 38 | + #[ORM\GeneratedValue] |
| 39 | + #[ORM\Column(type: Types::INTEGER)] |
| 40 | + private $id; |
| 41 | + |
| 42 | + /** |
| 43 | + * @var string|null |
| 44 | + * |
| 45 | + * @ORM\Column(name="title", type="string", length=64) |
| 46 | + */ |
| 47 | + #[ORM\Column(name: 'title', type: Types::STRING, length: 64)] |
| 48 | + private $title; |
| 49 | + |
| 50 | + /** |
| 51 | + * @var int|null |
| 52 | + * |
| 53 | + * @Gedmo\TreeLeft |
| 54 | + * @ORM\Column(name="lft", type="integer") |
| 55 | + */ |
| 56 | + #[ORM\Column(name: 'lft', type: Types::INTEGER)] |
| 57 | + #[Gedmo\TreeLeft] |
| 58 | + private $lft; |
| 59 | + |
| 60 | + /** |
| 61 | + * @var int|null |
| 62 | + * |
| 63 | + * @Gedmo\TreeRight |
| 64 | + * @ORM\Column(name="rgt", type="integer") |
| 65 | + */ |
| 66 | + #[ORM\Column(name: 'rgt', type: Types::INTEGER)] |
| 67 | + #[Gedmo\TreeRight] |
| 68 | + private $rgt; |
| 69 | + |
| 70 | + /** |
| 71 | + * @var int|null |
| 72 | + * |
| 73 | + * @Gedmo\TreeLevel |
| 74 | + * @ORM\Column(name="lvl", type="integer") |
| 75 | + */ |
| 76 | + #[ORM\Column(name: 'lvl', type: Types::INTEGER)] |
| 77 | + #[Gedmo\TreeLevel] |
| 78 | + private $lvl; |
| 79 | + |
| 80 | + /** |
| 81 | + * @var self|null |
| 82 | + * |
| 83 | + * @Gedmo\TreeRoot |
| 84 | + * @ORM\ManyToOne(targetEntity="Category") |
| 85 | + * @ORM\JoinColumn(name="tree_root", referencedColumnName="id", onDelete="CASCADE") |
| 86 | + */ |
| 87 | + #[Gedmo\TreeRoot] |
| 88 | + #[ORM\ManyToOne(targetEntity: self::class)] |
| 89 | + #[ORM\JoinColumn(name: 'tree_root', referencedColumnName: 'id', onDelete: 'CASCADE')] |
| 90 | + private $root; |
| 91 | + |
| 92 | + /** |
| 93 | + * @var self|null |
| 94 | + * |
| 95 | + * @Gedmo\TreeParent |
| 96 | + * @ORM\ManyToOne(targetEntity="Category", inversedBy="children") |
| 97 | + * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE") |
| 98 | + */ |
| 99 | + #[Gedmo\TreeParent] |
| 100 | + #[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')] |
| 101 | + #[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', onDelete: 'CASCADE')] |
| 102 | + private $parent; |
| 103 | + |
| 104 | + /** |
| 105 | + * @var Collection<int, Category> |
| 106 | + * |
| 107 | + * @ORM\OneToMany(targetEntity="Category", mappedBy="parent") |
| 108 | + * @ORM\OrderBy({"lft" = "ASC"}) |
| 109 | + */ |
| 110 | + #[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')] |
| 111 | + #[ORM\OrderBy(['lft' => 'ASC'])] |
| 112 | + private $children; |
| 113 | + |
| 114 | + public function getId(): ?int |
| 115 | + { |
| 116 | + return $this->id; |
| 117 | + } |
| 118 | + |
| 119 | + public function setTitle(?string $title): void |
| 120 | + { |
| 121 | + $this->title = $title; |
| 122 | + } |
| 123 | + |
| 124 | + public function getTitle(): ?string |
| 125 | + { |
| 126 | + return $this->title; |
| 127 | + } |
| 128 | + |
| 129 | + public function getRoot(): ?self |
| 130 | + { |
| 131 | + return $this->root; |
| 132 | + } |
| 133 | + |
| 134 | + public function setParent(?self $parent): void |
| 135 | + { |
| 136 | + $this->parent = $parent; |
| 137 | + } |
| 138 | + |
| 139 | + public function getParent(): ?self |
| 140 | + { |
| 141 | + return $this->parent; |
| 142 | + } |
| 143 | +} |
0 commit comments