-
Notifications
You must be signed in to change notification settings - Fork 467
/
ResourceComment.php
157 lines (126 loc) · 3.79 KB
/
ResourceComment.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Entity;
use Chamilo\CoreBundle\Traits\TimestampableAgoTrait;
use Chamilo\CoreBundle\Traits\TimestampableTypedEntity;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Gedmo\Tree\Entity\Repository\NestedTreeRepository;
use Gedmo\Tree\Traits\NestedSetEntity;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* ApiResource(
* attributes={"security"="is_granted('ROLE_ADMIN')"},
* normalizationContext={"groups"={"comment:read"}}
* ).
*/
#[ORM\Table(name: 'resource_comment')]
#[Gedmo\Tree(type: 'nested')]
#[ORM\Entity(repositoryClass: NestedTreeRepository::class)]
class ResourceComment
{
use NestedSetEntity;
use TimestampableAgoTrait;
use TimestampableTypedEntity;
#[ORM\Id]
#[ORM\Column(type: 'integer')]
#[ORM\GeneratedValue(strategy: 'AUTO')]
#[Groups(['comment:read'])]
protected ?int $id = null;
#[ORM\ManyToOne(targetEntity: ResourceNode::class, inversedBy: 'comments')]
#[ORM\JoinColumn(name: 'resource_node_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
protected ResourceNode $resourceNode;
#[Groups(['comment:read'])]
#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'author_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
protected User $author;
#[Assert\NotBlank]
#[Groups(['comment:read'])]
#[ORM\Column(name: 'content', type: 'string', nullable: false)]
protected string $content;
#[ORM\JoinColumn(onDelete: 'CASCADE')]
#[Gedmo\TreeParent]
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'children')]
protected ?ResourceComment $parent = null;
#[Groups(['comment:read'])]
#[Gedmo\Timestampable(on: 'create')]
#[ORM\Column(type: 'datetime')]
protected DateTime $createdAt;
#[Groups(['comment:read'])]
#[Gedmo\Timestampable(on: 'update')]
#[ORM\Column(type: 'datetime')]
protected DateTime $updatedAt;
/**
* @var Collection<int, ResourceComment>
*/
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: self::class)]
#[ORM\OrderBy(['id' => 'ASC'])]
protected Collection $children;
public function __construct()
{
$this->createdAt = new DateTime();
$this->content = '';
$this->children = new ArrayCollection();
}
public function getId(): int
{
return $this->id;
}
public function getContent(): string
{
return $this->content;
}
public function setContent(string $content): self
{
$this->content = $content;
return $this;
}
public function getResourceNode(): ResourceNode
{
return $this->resourceNode;
}
public function setResourceNode(ResourceNode $resourceNode): self
{
$this->resourceNode = $resourceNode;
return $this;
}
public function getAuthor(): User
{
return $this->author;
}
public function setAuthor(User $author): self
{
$this->author = $author;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parent): self
{
$this->parent = $parent;
return $this;
}
/**
* @return Collection<int, ResourceComment>
*/
public function getChildren(): Collection
{
return $this->children;
}
public function setChildren(Collection $children): self
{
$this->children = $children;
return $this;
}
public function getRoot(): int
{
return $this->root;
}
}