Issues (964)

src/Entity/WikiArticle.php (3 issues)

Severity
1
<?php
2
3
namespace App\Entity;
4
5
use DateTime;
6
use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\ORM\Mapping as ORM;
10
use Gedmo\Loggable\Loggable;
11
use Gedmo\Mapping\Annotation as Gedmo;
12
use Ramsey\Uuid\Uuid;
13
use Symfony\Component\Validator\Constraints as Assert;
14
15
#[Auditable]
16
#[Gedmo\Tree(type: 'nested')]
17
#[Gedmo\Loggable]
18
#[ORM\Entity]
19
#[ORM\Table(name: 'wiki')]
20
#[ORM\Index(columns: ['title'], flags: ['fulltext'])]
21
#[ORM\Index(columns: ['content'], flags: ['fulltext'])]
22
class WikiArticle {
23
24
    use IdTrait;
25
    use UuidTrait;
26
27
    #[Gedmo\Versioned]
28
    #[Assert\NotBlank]
29
    #[ORM\Column(type: 'string')]
30
    private ?string $title = null;
31
32
    #[Assert\NotBlank(allowNull: true)]
33
    #[ORM\Column(type: 'string', nullable: true)]
34
    private ?string $icon = null;
35
36
    #[ORM\Column(type: 'boolean')]
37
    private bool $isOnline = true;
38
39
    #[Gedmo\Timestampable(on: 'create')]
40
    #[ORM\Column(type: 'datetime')]
41
    private ?DateTime $createdAt = null;
42
43
    #[Gedmo\Timestampable(on: 'update')]
44
    #[ORM\Column(type: 'datetime')]
45
    private ?DateTime $updatedAt = null;
46
47
    #[Gedmo\Versioned]
48
    #[Assert\NotBlank]
49
    #[ORM\Column(type: 'text')]
50
    private ?string $content = null;
51
52
    /**
53
     * @var ArrayCollection<UserTypeEntity>
54
     */
55
    #[ORM\JoinTable(name: 'wiki_article_visibilities')]
56
    #[ORM\JoinColumn(onDelete: 'CASCADE')]
57
    #[ORM\InverseJoinColumn(onDelete: 'CASCADE')]
58
    #[ORM\ManyToMany(targetEntity: UserTypeEntity::class)]
59
    private $visibilities;
60
61
    #[Gedmo\TreeLeft]
62
    #[ORM\Column(type: 'integer')]
63
    private int $left;
0 ignored issues
show
The private property $left is not used, and could be removed.
Loading history...
64
65
    #[Gedmo\TreeLevel]
66
    #[ORM\Column(type: 'integer')]
67
    private int $level;
0 ignored issues
show
The private property $level is not used, and could be removed.
Loading history...
68
69
    #[Gedmo\TreeRight]
70
    #[ORM\Column(type: 'integer')]
71
    private int $right;
0 ignored issues
show
The private property $right is not used, and could be removed.
Loading history...
72
73
    #[Gedmo\TreeRoot]
74
    #[ORM\ManyToOne(targetEntity: WikiArticle::class)]
75
    #[ORM\JoinColumn(onDelete: 'CASCADE')]
76
    private ?WikiArticle $root = null;
77
78
    #[Gedmo\TreeParent]
79
    #[ORM\ManyToOne(targetEntity: WikiArticle::class, inversedBy: 'children')]
80
    #[ORM\JoinColumn(name: 'parent', onDelete: 'CASCADE')]
81
    private ?WikiArticle $parent = null;
82
83
    /**
84
     * @var Collection<WikiArticle>
85
     */
86
    #[ORM\OneToMany(mappedBy: 'parent', targetEntity: WikiArticle::class)]
87
    #[ORM\OrderBy(['title' => 'ASC'])]
88
    private $children;
89
90
    public function __construct() {
91
        $this->uuid = Uuid::uuid4();
92
93
        $this->visibilities = new ArrayCollection();
94
        $this->children = new ArrayCollection();
95
    }
96
97
    public function getTitle(): ?string {
98
        return $this->title;
99
    }
100
101
    public function setTitle(?string $title): WikiArticle {
102
        $this->title = $title;
103
        return $this;
104
    }
105
106
    public function getIcon(): ?string {
107
        return $this->icon;
108
    }
109
110
    public function setIcon(?string $icon): WikiArticle {
111
        $this->icon = $icon;
112
        return $this;
113
    }
114
115
    public function isOnline(): bool {
116
        return $this->isOnline;
117
    }
118
119
    public function setIsOnline(bool $isOnline): WikiArticle {
120
        $this->isOnline = $isOnline;
121
        return $this;
122
    }
123
124
    public function getCreatedAt(): ?DateTime {
125
        return $this->createdAt;
126
    }
127
128
    public function getUpdatedAt(): ?DateTime {
129
        return $this->updatedAt;
130
    }
131
132
    public function getContent(): ?string {
133
        return $this->content;
134
    }
135
136
    public function setContent(?string $content): WikiArticle {
137
        $this->content = $content;
138
        return $this;
139
    }
140
141
    public function addVisibility(UserTypeEntity $visibility) {
142
        $this->visibilities->add($visibility);
143
    }
144
145
    public function removeVisibility(UserTypeEntity $visibility) {
146
        $this->visibilities->removeElement($visibility);
147
    }
148
149
    public function getVisibilities(): Collection {
150
        return $this->visibilities;
151
    }
152
153
    public function getRoot(): ?WikiArticle {
154
        return $this->root;
155
    }
156
157
    public function getParent(): ?WikiArticle {
158
        return $this->parent;
159
    }
160
161
    public function setParent(?WikiArticle $parent): WikiArticle {
162
        $this->parent = $parent;
163
        return $this;
164
    }
165
166
    /**
167
     * @return Collection<WikiArticle>
168
     */
169
    public function getChildren(): Collection {
170
        return $this->children;
171
    }
172
}