Completed
Push — master ( c58ed8...556108 )
by Julito
10:31
created

ResourceComment::getAuthor()   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_USER')"},
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
    /**
118
     * @return ResourceComment
119
     */
120
    public function setId($id)
121
    {
122
        $this->id = $id;
123
124
        return $this;
125
    }
126
127
    public function getContent(): string
128
    {
129
        return $this->content;
130
    }
131
132
    public function setContent(string $content): self
133
    {
134
        $this->content = $content;
135
136
        return $this;
137
    }
138
139
    public function getResourceNode()
140
    {
141
        return $this->resourceNode;
142
    }
143
144
    /**
145
     * @return ResourceComment
146
     */
147
    public function setResourceNode($resourceNode)
148
    {
149
        $this->resourceNode = $resourceNode;
150
151
        return $this;
152
    }
153
154
    public function getAuthor(): User
155
    {
156
        return $this->author;
157
    }
158
159
    /**
160
     * @return ResourceComment
161
     */
162
    public function setAuthor(User $author)
163
    {
164
        $this->author = $author;
165
166
        return $this;
167
    }
168
169
    public function getParent()
170
    {
171
        return $this->parent;
172
    }
173
174
    /**
175
     * @return ResourceComment
176
     */
177
    public function setParent($parent)
178
    {
179
        $this->parent = $parent;
180
181
        return $this;
182
    }
183
184
    /**
185
     * @return ResourceComment[]
186
     */
187
    public function getChildren(): array
188
    {
189
        return $this->children;
190
    }
191
192
    /**
193
     * @param ResourceComment[] $children
194
     */
195
    public function setChildren(array $children): self
196
    {
197
        $this->children = $children;
198
199
        return $this;
200
    }
201
}
202