|
| 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 <gediminas.morkevicius@gmail.com> 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\Sluggable\Fixture\Handler\People; |
| 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\Sluggable\Handler\InversedRelativeSlugHandler; |
| 20 | +use Gedmo\Sluggable\Handler\TreeSlugHandler; |
| 21 | +use Gedmo\Tree\Entity\Repository\NestedTreeRepository; |
| 22 | + |
| 23 | +/** |
| 24 | + * @Gedmo\Tree(type="nested") |
| 25 | + * |
| 26 | + * @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository") |
| 27 | + */ |
| 28 | +#[ORM\Entity(repositoryClass: NestedTreeRepository::class)] |
| 29 | +#[Gedmo\Tree(type: 'nested')] |
| 30 | +class UrilizedOccupation |
| 31 | +{ |
| 32 | + /** |
| 33 | + * @ORM\Id |
| 34 | + * @ORM\GeneratedValue |
| 35 | + * @ORM\Column(type="integer") |
| 36 | + */ |
| 37 | + #[ORM\Id] |
| 38 | + #[ORM\GeneratedValue] |
| 39 | + #[ORM\Column(type: Types::INTEGER)] |
| 40 | + private ?int $id = null; |
| 41 | + |
| 42 | + /** |
| 43 | + * @ORM\Column(length=64) |
| 44 | + */ |
| 45 | + #[ORM\Column(length: 64)] |
| 46 | + private ?string $title = null; |
| 47 | + |
| 48 | + /** |
| 49 | + * @Gedmo\Slug(handlers={ |
| 50 | + * @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\TreeSlugHandler", options={ |
| 51 | + * @Gedmo\SlugHandlerOption(name="parentRelationField", value="parent"), |
| 52 | + * @Gedmo\SlugHandlerOption(name="separator", value="/") |
| 53 | + * }), |
| 54 | + * @Gedmo\SlugHandler(class="Gedmo\Sluggable\Handler\InversedRelativeSlugHandler", options={ |
| 55 | + * @Gedmo\SlugHandlerOption(name="relationClass", value="Gedmo\Tests\Sluggable\Fixture\Handler\People\UrilizedPerson"), |
| 56 | + * @Gedmo\SlugHandlerOption(name="mappedBy", value="occupation"), |
| 57 | + * @Gedmo\SlugHandlerOption(name="inverseSlugField", value="slug") |
| 58 | + * }) |
| 59 | + * }, fields={"title"}) |
| 60 | + * |
| 61 | + * @ORM\Column(length=64, unique=true) |
| 62 | + */ |
| 63 | + #[Gedmo\Slug(fields: ['title'])] |
| 64 | + #[Gedmo\SlugHandler(class: TreeSlugHandler::class, options: ['parentRelationField' => 'parent', 'separator' => '/'])] |
| 65 | + #[Gedmo\SlugHandler(class: InversedRelativeSlugHandler::class, options: ['relationClass' => UrilizedPerson::class, 'mappedBy' => 'occupation', 'inverseSlugField' => 'slug'])] |
| 66 | + #[ORM\Column(length: 64, unique: true)] |
| 67 | + private ?string $slug = null; |
| 68 | + |
| 69 | + /** |
| 70 | + * @Gedmo\TreeParent |
| 71 | + * |
| 72 | + * @ORM\ManyToOne(targetEntity="UrilizedOccupation") |
| 73 | + * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE") |
| 74 | + */ |
| 75 | + #[ORM\ManyToOne(targetEntity: self::class)] |
| 76 | + #[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'id', onDelete: 'CASCADE')] |
| 77 | + #[Gedmo\TreeParent] |
| 78 | + private ?UrilizedOccupation $parent = null; |
| 79 | + |
| 80 | + /** |
| 81 | + * @var Collection<int, self> |
| 82 | + */ |
| 83 | + private Collection $children; |
| 84 | + |
| 85 | + /** |
| 86 | + * @Gedmo\TreeLeft |
| 87 | + * |
| 88 | + * @ORM\Column(type="integer") |
| 89 | + */ |
| 90 | + #[ORM\Column(type: Types::INTEGER)] |
| 91 | + #[Gedmo\TreeLeft] |
| 92 | + private ?int $lft = null; |
| 93 | + |
| 94 | + /** |
| 95 | + * @Gedmo\TreeRight |
| 96 | + * |
| 97 | + * @ORM\Column(type="integer") |
| 98 | + */ |
| 99 | + #[ORM\Column(type: Types::INTEGER)] |
| 100 | + #[Gedmo\TreeRight] |
| 101 | + private ?int $rgt = null; |
| 102 | + |
| 103 | + /** |
| 104 | + * @Gedmo\TreeRoot |
| 105 | + * |
| 106 | + * @ORM\Column(type="integer") |
| 107 | + */ |
| 108 | + #[ORM\Column(type: Types::INTEGER)] |
| 109 | + #[Gedmo\TreeRoot] |
| 110 | + private ?int $root = null; |
| 111 | + |
| 112 | + /** |
| 113 | + * @Gedmo\TreeLevel |
| 114 | + * |
| 115 | + * @ORM\Column(name="lvl", type="integer") |
| 116 | + */ |
| 117 | + #[ORM\Column(name: 'lvl', type: Types::INTEGER)] |
| 118 | + #[Gedmo\TreeLevel] |
| 119 | + private ?int $level = null; |
| 120 | + |
| 121 | + public function __construct() |
| 122 | + { |
| 123 | + $this->children = new ArrayCollection(); |
| 124 | + } |
| 125 | + |
| 126 | + public function setParent(?self $parent = null): void |
| 127 | + { |
| 128 | + $this->parent = $parent; |
| 129 | + } |
| 130 | + |
| 131 | + /** |
| 132 | + * @return Collection<int, self> |
| 133 | + */ |
| 134 | + public function getChildren(): Collection |
| 135 | + { |
| 136 | + return $this->children; |
| 137 | + } |
| 138 | + |
| 139 | + public function getParent(): ?self |
| 140 | + { |
| 141 | + return $this->parent; |
| 142 | + } |
| 143 | + |
| 144 | + public function getRoot(): ?int |
| 145 | + { |
| 146 | + return $this->root; |
| 147 | + } |
| 148 | + |
| 149 | + public function getLeft(): ?int |
| 150 | + { |
| 151 | + return $this->lft; |
| 152 | + } |
| 153 | + |
| 154 | + public function getRight(): ?int |
| 155 | + { |
| 156 | + return $this->rgt; |
| 157 | + } |
| 158 | + |
| 159 | + public function getLevel(): ?int |
| 160 | + { |
| 161 | + return $this->level; |
| 162 | + } |
| 163 | + |
| 164 | + public function getId(): ?int |
| 165 | + { |
| 166 | + return $this->id; |
| 167 | + } |
| 168 | + |
| 169 | + public function setTitle(?string $title): void |
| 170 | + { |
| 171 | + $this->title = $title; |
| 172 | + } |
| 173 | + |
| 174 | + public function getTitle(): ?string |
| 175 | + { |
| 176 | + return $this->title; |
| 177 | + } |
| 178 | + |
| 179 | + public function getSlug(): ?string |
| 180 | + { |
| 181 | + return $this->slug; |
| 182 | + } |
| 183 | +} |
0 commit comments