Passed
Push — master ( e23eb9...dbf2ad )
by Angel Fernando Quiroz
07:02
created

ResourceComment::getRoot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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