Passed
Push — master ( 241b61...cc68cc )
by Julito
09:18
created

ResourceComment::getChildren()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Entity;
6
7
use ApiPlatform\Core\Annotation\ApiResource;
8
use Chamilo\CoreBundle\Traits\TimestampableAgoTrait;
9
use Doctrine\Common\Collections\ArrayCollection;
10
use Doctrine\ORM\Mapping as ORM;
11
use Gedmo\Mapping\Annotation as Gedmo;
12
use Gedmo\Timestampable\Traits\TimestampableEntity;
13
use Gedmo\Tree\Traits\NestedSetEntity;
14
use Symfony\Component\Serializer\Annotation\Groups;
15
use Symfony\Component\Validator\Constraints as Assert;
16
17
/**
18
 * @ApiResource(
19
 *      attributes={"security"="is_granted('ROLE_ADMIN')"},
20
 *      normalizationContext={"groups"={"comment:read"}}
21
 * )
22
 *
23
 * @Gedmo\Tree(type="nested")
24
 * @ORM\Entity(repositoryClass="Gedmo\Tree\Entity\Repository\NestedTreeRepository")
25
 * @ORM\Table(name="resource_comment")
26
 */
27
class ResourceComment
28
{
29
    use TimestampableEntity;
30
    use TimestampableAgoTrait;
31
    use NestedSetEntity;
32
33
    /**
34
     * @ORM\Id
35
     * @ORM\Column(type="integer")
36
     * @ORM\GeneratedValue(strategy="AUTO")
37
     * @Groups({"comment:read"})
38
     */
39
    protected $id;
40
41
    /**
42
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\ResourceNode", inversedBy="comments")
43
     * @ORM\JoinColumn(name="resource_node_id", referencedColumnName="id", onDelete="SET NULL")
44
     */
45
    protected $resourceNode;
46
47
    /**
48
     * @var User
49
     *
50
     * @Groups({"comment:read"})
51
     * @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\User")
52
     * @ORM\JoinColumn(name="author_id", referencedColumnName="id", onDelete="SET NULL")
53
     */
54
    protected $author;
55
56
    /**
57
     * @var string
58
     *
59
     * @Groups({"comment:read"})
60
     * @Assert\NotBlank()
61
     *
62
     * @ORM\Column(name="content", type="string", nullable=false)
63
     */
64
    protected $content;
65
66
    /**
67
     * @Gedmo\TreeParent
68
     *
69
     * @ORM\ManyToOne(
70
     *     targetEntity="ResourceComment",
71
     *     inversedBy="children"
72
     * )
73
     * @ORM\JoinColumns({@ORM\JoinColumn(onDelete="CASCADE")})
74
     */
75
    protected $parent;
76
77
    /**
78
     * @var \DateTime
79
     * @Groups({"comment:read"})
80
     * @Gedmo\Timestampable(on="create")
81
     * @ORM\Column(type="datetime")
82
     */
83
    protected $createdAt;
84
85
    /**
86
     * @var \DateTime
87
     *
88
     * @Groups({"comment:read"})
89
     * @Gedmo\Timestampable(on="update")
90
     * @ORM\Column(type="datetime")
91
     */
92
    protected $updatedAt;
93
94
    /**
95
     * @var ResourceComment[]
96
     *
97
     * @ORM\OneToMany(
98
     *     targetEntity="ResourceComment",
99
     *     mappedBy="parent"
100
     * )
101
     * @ORM\OrderBy({"id" = "ASC"})
102
     */
103
    protected $children;
104
105
    public function __construct()
106
    {
107
        $this->createdAt = new \DateTimeImmutable();
0 ignored issues
show
Documentation Bug introduced by
It seems like new DateTimeImmutable() of type DateTimeImmutable is incompatible with the declared type DateTime of property $createdAt.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
108
        $this->content = '';
109
        $this->children = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new Doctrine\Common\Collections\ArrayCollection() of type Doctrine\Common\Collections\ArrayCollection is incompatible with the declared type Chamilo\CoreBundle\Entity\ResourceComment[] of property $children.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
110
    }
111
112
    public function getId()
113
    {
114
        return $this->id;
115
    }
116
117
    public function getContent(): string
118
    {
119
        return $this->content;
120
    }
121
122
    public function setContent(string $content): self
123
    {
124
        $this->content = $content;
125
126
        return $this;
127
    }
128
129
    public function getResourceNode()
130
    {
131
        return $this->resourceNode;
132
    }
133
134
    public function setResourceNode($resourceNode): self
135
    {
136
        $this->resourceNode = $resourceNode;
137
138
        return $this;
139
    }
140
141
    public function getAuthor(): User
142
    {
143
        return $this->author;
144
    }
145
146
    public function setAuthor(User $author): self
147
    {
148
        $this->author = $author;
149
150
        return $this;
151
    }
152
153
    public function getParent()
154
    {
155
        return $this->parent;
156
    }
157
158
    public function setParent($parent): self
159
    {
160
        $this->parent = $parent;
161
162
        return $this;
163
    }
164
165
    /**
166
     * @return ResourceComment[]
167
     */
168
    public function getChildren()
169
    {
170
        return $this->children;
171
    }
172
173
    /**
174
     * @param ResourceComment[] $children
175
     */
176
    public function setChildren(array $children): self
177
    {
178
        $this->children = $children;
179
180
        return $this;
181
    }
182
}
183