1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Odiseo\BlogBundle\Model; |
6
|
|
|
|
7
|
|
|
use DateTime; |
8
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
9
|
|
|
use Sylius\Component\Resource\Model\TimestampableTrait; |
10
|
|
|
use Sylius\Component\Resource\Model\ToggleableTrait; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @author Diego D'amico <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class ArticleComment implements ArticleCommentInterface |
16
|
|
|
{ |
17
|
|
|
use TimestampableTrait; |
18
|
|
|
use ToggleableTrait; |
19
|
|
|
|
20
|
|
|
/** @var integer */ |
21
|
|
|
private $id; |
22
|
|
|
|
23
|
|
|
/** @var string|null */ |
24
|
|
|
private $comment; |
25
|
|
|
|
26
|
|
|
/** @var string|null */ |
27
|
|
|
private $name; |
28
|
|
|
|
29
|
|
|
/** @var string|null */ |
30
|
|
|
private $email; |
31
|
|
|
|
32
|
|
|
/** @var ArticleInterface|null */ |
33
|
|
|
protected $article; |
34
|
|
|
|
35
|
|
|
/** @var ArrayCollection|ArticleCommentInterface[] */ |
36
|
|
|
protected $children; |
37
|
|
|
|
38
|
|
|
/** @var ArticleCommentInterface|null */ |
39
|
|
|
protected $parent; |
40
|
|
|
|
41
|
|
|
public function __construct() |
42
|
|
|
{ |
43
|
|
|
$this->enabled = false; |
44
|
|
|
$this->children = new ArrayCollection(); |
45
|
|
|
$this->createdAt = new DateTime(); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
|
|
public function getId() |
52
|
|
|
{ |
53
|
|
|
return $this->id; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritdoc} |
58
|
|
|
*/ |
59
|
|
|
public function getComment(): ?string |
60
|
|
|
{ |
61
|
|
|
return $this->comment; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
|
|
public function setComment(?string $comment): void |
68
|
|
|
{ |
69
|
|
|
$this->comment = $comment; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritdoc} |
74
|
|
|
*/ |
75
|
|
|
public function getName(): ?string |
76
|
|
|
{ |
77
|
|
|
return $this->name; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* {@inheritdoc} |
82
|
|
|
*/ |
83
|
|
|
public function setName(?string $name): void |
84
|
|
|
{ |
85
|
|
|
$this->name = $name; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* {@inheritdoc} |
90
|
|
|
*/ |
91
|
|
|
public function getEmail(): ?string |
92
|
|
|
{ |
93
|
|
|
return $this->email; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* {@inheritdoc} |
98
|
|
|
*/ |
99
|
|
|
public function setEmail(?string $email): void |
100
|
|
|
{ |
101
|
|
|
$this->email = $email; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* {@inheritdoc} |
106
|
|
|
*/ |
107
|
|
|
public function getArticle(): ?ArticleInterface |
108
|
|
|
{ |
109
|
|
|
return $this->article; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* {@inheritdoc} |
114
|
|
|
*/ |
115
|
|
|
public function setArticle(?ArticleInterface $article): void |
116
|
|
|
{ |
117
|
|
|
$this->article = $article; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* {@inheritdoc} |
122
|
|
|
*/ |
123
|
|
|
public function getChildren(): iterable |
124
|
|
|
{ |
125
|
|
|
return $this->children; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* {@inheritdoc} |
130
|
|
|
*/ |
131
|
|
|
public function getEnabledChildren(): iterable |
132
|
|
|
{ |
133
|
|
|
return $this->children->filter(function(ArticleCommentInterface $comment) { |
134
|
|
|
return $comment->isEnabled(); |
135
|
|
|
}); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* {@inheritdoc} |
140
|
|
|
*/ |
141
|
|
|
public function hasChildren(ArticleCommentInterface $comment): bool |
142
|
|
|
{ |
143
|
|
|
return $this->children->contains($comment); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* {@inheritdoc} |
148
|
|
|
*/ |
149
|
|
|
public function addChildren(ArticleCommentInterface $comment): void |
150
|
|
|
{ |
151
|
|
|
if (!$this->hasChildren($comment)) { |
152
|
|
|
$comment->setParent($this); |
153
|
|
|
$this->children->add($comment); |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* {@inheritdoc} |
159
|
|
|
*/ |
160
|
|
|
public function removeChildren(ArticleCommentInterface $comment): void |
161
|
|
|
{ |
162
|
|
|
if ($this->hasChildren($comment)) { |
163
|
|
|
$this->children->removeElement($comment); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* {@inheritdoc} |
169
|
|
|
*/ |
170
|
|
|
public function getParent(): ?ArticleCommentInterface |
171
|
|
|
{ |
172
|
|
|
return $this->parent; |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* {@inheritdoc} |
177
|
|
|
*/ |
178
|
|
|
public function setParent(?ArticleCommentInterface $parent): void |
179
|
|
|
{ |
180
|
|
|
$this->parent = $parent; |
181
|
|
|
} |
182
|
|
|
} |
183
|
|
|
|