zend-blog-3-backend

Форк
0
411 строк · 7.3 Кб
1
<?php
2

3
namespace App\Entity;
4

5
use App\Entity\Embedded\NestedSet;
6
use App\Entity\Traits\ModifyEntityTrait;
7
use DateTime;
8
use Doctrine\Common\Collections\ArrayCollection;
9
use Doctrine\Common\Collections\Collection;
10
use Doctrine\ORM\Mapping as ORM;
11

12
/**
13
 * @ORM\Table(name="comments", indexes={
14
 *   @ORM\Index(name="left_key_idx", columns={"tree_left_key"}),
15
 *   @ORM\Index(name="right_key_idx", columns={"tree_right_key"})
16
 * })
17
 * @ORM\Entity(repositoryClass="App\Repository\CommentRepository")
18
 * @ORM\HasLifecycleCallbacks()
19
 */
20
class Comment implements CommentInterface
21
{
22
    use ModifyEntityTrait;
23

24
    /**
25
     * @var int
26
     *
27
     * @ORM\Id
28
     * @ORM\Column(type="integer")
29
     * @ORM\GeneratedValue(strategy="AUTO")
30
     */
31
    protected $id;
32

33
    /**
34
     * @var Collection
35
     *
36
     * @ORM\OneToMany(targetEntity="Comment", mappedBy="parent")
37
     **/
38
    protected $children;
39

40
    /**
41
     * @ORM\ManyToOne(targetEntity="Comment", inversedBy="children")
42
     * @ORM\JoinColumn(onDelete="SET NULL")
43
     **/
44
    protected $parent;
45

46
    /**
47
     * @var Post
48
     *
49
     * @ORM\ManyToOne(targetEntity="Post", inversedBy="comments")
50
     * @ORM\JoinColumn(nullable=false)
51
     */
52
    protected $post;
53

54
    /**
55
     * @var Commentator
56
     *
57
     * @ORM\ManyToOne(targetEntity="Commentator", inversedBy="comments")
58
     */
59
    protected $commentator;
60

61
    /**
62
     * @var User
63
     *
64
     * @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="comments")
65
     */
66
    protected $user;
67

68
    /**
69
     * @var string
70
     *
71
     * @ORM\Column(type="text")
72
     */
73
    protected $text;
74

75
    /**
76
     * @var bool
77
     *
78
     * @ORM\Column(type="boolean", options={"default": false})
79
     */
80
    protected $deleted = false;
81

82
    /**
83
     * @var TrackingAgent
84
     *
85
     * @ORM\ManyToOne(targetEntity="TrackingAgent")
86
     * @ORM\JoinColumn(name="user_agent_id", referencedColumnName="id", onDelete="SET NULL")
87
     */
88
    protected $trackingAgent;
89

90
    /**
91
     * @var string|null
92
     *
93
     * @ORM\Column(name="ip_addr", type="string", length=15, nullable=true)
94
     */
95
    protected $ipAddress;
96

97
    /**
98
     * @var GeoLocation
99
     *
100
     * @ORM\ManyToOne(targetEntity="GeoLocation")
101
     * @ORM\JoinColumn(name="ip_long", referencedColumnName="ip_long", onDelete="SET NULL")
102
     */
103
    private $geoLocation;
104

105
    /**
106
     * @var NestedSet
107
     *
108
     * @ORM\Embedded(class="App\Entity\Embedded\NestedSet", columnPrefix = "tree_")
109
     */
110
    private $nestedSet;
111

112
    public function __construct()
113
    {
114
        $this->children = new ArrayCollection();
115
        $this->timeCreated = new DateTime();
116
        $this->nestedSet = new NestedSet();
117
    }
118

119
    /**
120
     * Get id
121
     *
122
     * @return int
123
     */
124
    public function getId(): ?int
125
    {
126
        return $this->id;
127
    }
128

129
    /**
130
     * @return string
131
     */
132
    public function getAvatarHash(): string
133
    {
134
        $hash = '';
135
        if ($this->getCommentator()) {
136
            $hash = $this->getCommentator()->getAvatarHash();
137
        } elseif ($this->getUser()) {
138
            $hash = $this->getUser()->getAvatarHash();
139
        }
140

141
        return $hash;
142
    }
143

144
    /**
145
     * Add children
146
     *
147
     * @param Comment $children
148
     *
149
     * @return Comment
150
     */
151
    public function addChild(self $children)
152
    {
153
        $this->children[] = $children;
154

155
        return $this;
156
    }
157

158
    /**
159
     * Remove children
160
     *
161
     * @param Comment $children
162
     */
163
    public function removeChild(self $children)
164
    {
165
        $this->children->removeElement($children);
166
    }
167

168
    /**
169
     * Get children
170
     *
171
     * @return Collection
172
     */
173
    public function getChildren()
174
    {
175
        return $this->children;
176
    }
177

178
    /**
179
     * Set parent
180
     *
181
     * @param Comment|null $parent
182
     *
183
     * @return Comment
184
     */
185
    public function setParent(self $parent = null)
186
    {
187
        $this->parent = $parent;
188

189
        return $this;
190
    }
191

192
    /**
193
     * Get parent
194
     *
195
     * @return Comment|null
196
     */
197
    public function getParent(): ?Comment
198
    {
199
        return $this->parent;
200
    }
201

202
    /**
203
     * Set commentator
204
     *
205
     * @param Commentator|null $commentator
206
     *
207
     * @return Comment
208
     */
209
    public function setCommentator(Commentator $commentator = null)
210
    {
211
        $this->commentator = $commentator;
212

213
        return $this;
214
    }
215

216
    /**
217
     * Get commentator
218
     *
219
     * @return Commentator|null
220
     */
221
    public function getCommentator(): ?Commentator
222
    {
223
        return $this->commentator;
224
    }
225

226
    /**
227
     * Set user
228
     *
229
     * @param User|null $user
230
     *
231
     * @return Comment
232
     */
233
    public function setUser(User $user = null)
234
    {
235
        $this->user = $user;
236

237
        return $this;
238
    }
239

240
    /**
241
     * Get user
242
     *
243
     * @return User|null
244
     */
245
    public function getUser(): ?User
246
    {
247
        return $this->user;
248
    }
249

250
    /**
251
     * Set text
252
     *
253
     * @param string $text
254
     *
255
     * @return Comment
256
     */
257
    public function setText($text)
258
    {
259
        $this->text = $text;
260

261
        return $this;
262
    }
263

264
    /**
265
     * Get text
266
     *
267
     * @return string
268
     */
269
    public function getText(): string
270
    {
271
        return $this->text;
272
    }
273

274
    /**
275
     * Set deleted
276
     *
277
     * @param bool $deleted
278
     *
279
     * @return Comment
280
     */
281
    public function setDeleted($deleted)
282
    {
283
        $this->deleted = $deleted;
284

285
        return $this;
286
    }
287

288
    /**
289
     * Is deleted
290
     *
291
     * @return bool
292
     */
293
    public function isDeleted(): bool
294
    {
295
        return $this->deleted;
296
    }
297

298
    /**
299
     * Set ipAddress
300
     *
301
     * @param string|null $ipAddress
302
     *
303
     * @return Comment
304
     */
305
    public function setIpAddress($ipAddress)
306
    {
307
        $this->ipAddress = $ipAddress;
308

309
        return $this;
310
    }
311

312
    /**
313
     * Get ipAddress
314
     *
315
     * @return string|null
316
     */
317
    public function getIpAddress()
318
    {
319
        return $this->ipAddress;
320
    }
321

322
    /**
323
     * Set post
324
     *
325
     * @param Post $post
326
     *
327
     * @return Comment
328
     */
329
    public function setPost(Post $post = null)
330
    {
331
        $this->post = $post;
332

333
        return $this;
334
    }
335

336
    /**
337
     * Get post
338
     *
339
     * @return Post
340
     */
341
    public function getPost()
342
    {
343
        return $this->post;
344
    }
345

346
    /**
347
     * Set trackingAgent
348
     *
349
     * @param TrackingAgent $trackingAgent
350
     *
351
     * @return Comment
352
     */
353
    public function setTrackingAgent(TrackingAgent $trackingAgent = null)
354
    {
355
        $this->trackingAgent = $trackingAgent;
356

357
        return $this;
358
    }
359

360
    /**
361
     * Get trackingAgent
362
     *
363
     * @return TrackingAgent
364
     */
365
    public function getTrackingAgent()
366
    {
367
        return $this->trackingAgent;
368
    }
369

370
    /**
371
     * Get geoLocation
372
     *
373
     * @return GeoLocation|null
374
     */
375
    public function getGeoLocation(): ?GeoLocation
376
    {
377
        return $this->geoLocation;
378
    }
379

380
    /**
381
     * @param GeoLocation|null $location
382
     *
383
     * @return $this
384
     */
385
    public function setGeoLocation(GeoLocation $location = null): self
386
    {
387
        $this->geoLocation = $location;
388

389
        return $this;
390
    }
391

392
    /**
393
     * @return NestedSet
394
     */
395
    public function getNestedSet(): NestedSet
396
    {
397
        return $this->nestedSet;
398
    }
399

400
    /**
401
     * @param NestedSet $nestedSet
402
     *
403
     * @return $this
404
     */
405
    public function setNestedSet(NestedSet $nestedSet): self
406
    {
407
        $this->nestedSet = $nestedSet;
408

409
        return $this;
410
    }
411
}
412

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.