zend-blog-3-backend

Форк
0
547 строк · 8.9 Кб
1
<?php
2

3
namespace App\Entity;
4

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

12
/**
13
 * @ORM\Table(name="posts")
14
 * @ORM\Entity(repositoryClass="App\Repository\PostRepository")
15
 * @ORM\HasLifecycleCallbacks()
16
 */
17
class Post
18
{
19
    use ModifyEntityTrait;
20

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

30
    /**
31
     * @var string
32
     *
33
     * @ORM\Column(type="string", length=128)
34
     */
35
    protected $title;
36

37
    /**
38
     * @var string
39
     *
40
     * @ORM\Column(type="string", length=255, unique=true)
41
     */
42
    protected $url;
43

44
    /**
45
     * @var bool
46
     *
47
     * @ORM\Column(type="boolean")
48
     */
49
    protected $hide = false;
50

51
    /**
52
     * @var string
53
     *
54
     * @ORM\Column(type="text", name="text_post")
55
     */
56
    protected $text;
57

58
    /**
59
     * @var string
60
     *
61
     * @ORM\Column(type="text")
62
     */
63
    protected $preview;
64

65
    /**
66
     * @var string
67
     *
68
     * @ORM\Column(type="text")
69
     */
70
    protected $rawText;
71

72
    /**
73
     * @var string
74
     *
75
     * @ORM\Column(type="string", length=255, nullable=true)
76
     */
77
    protected $description;
78

79
    /**
80
     * @var Category
81
     *
82
     * @ORM\ManyToOne(targetEntity="Category", inversedBy="posts")
83
     * @ORM\JoinColumn(nullable=false)
84
     */
85
    protected $category;
86

87
    /**
88
     * @var Collection
89
     *
90
     * @ORM\ManyToMany(targetEntity="Tag", inversedBy="posts")
91
     * @ORM\JoinTable(name="relation_topictag")
92
     */
93
    protected $tags;
94

95
    /**
96
     * @var int
97
     *
98
     * @ORM\Column(type="integer")
99
     */
100
    protected $commentsCount = 0;
101

102
    /**
103
     * @var int
104
     *
105
     * @ORM\Column(type="integer")
106
     */
107
    protected $viewsCount = 0;
108

109
    /**
110
     * @var Collection
111
     *
112
     * @ORM\OneToMany(targetEntity="Comment", mappedBy="post")
113
     */
114
    protected $comments;
115

116
    /**
117
     * @var Collection
118
     *
119
     * @ORM\OneToMany(targetEntity="MediaFile", mappedBy="post")
120
     */
121
    protected $mediaFiles;
122

123
    /**
124
     * @var DateTime
125
     *
126
     * @ORM\Column(type="datetime", options={
127
     *   "default": "CURRENT_TIMESTAMP",
128
     *   "comment": "updated if article content changes"})
129
     */
130
    private $updatedAt;
131

132
    /**
133
     * @var bool
134
     *
135
     * @ORM\Column(type="boolean", options={"default": false})
136
     */
137
    private $disableComments = false;
138

139
    public function __construct()
140
    {
141
        $this->tags = new ArrayCollection();
142
        $this->comments = new ArrayCollection();
143
        $this->mediaFiles = new ArrayCollection();
144

145
        $this->timeCreated = new DateTime();
146
        $this->updatedAt = new DateTime();
147
    }
148

149
    /**
150
     * Get id
151
     *
152
     * @return int
153
     */
154
    public function getId()
155
    {
156
        return $this->id;
157
    }
158

159
    /**
160
     * Set title
161
     *
162
     * @param string $title
163
     *
164
     * @return Post
165
     */
166
    public function setTitle($title)
167
    {
168
        $this->title = $title;
169

170
        return $this;
171
    }
172

173
    /**
174
     * Get title
175
     *
176
     * @return string
177
     */
178
    public function getTitle()
179
    {
180
        return $this->title;
181
    }
182

183
    /**
184
     * Set url
185
     *
186
     * @param string $url
187
     *
188
     * @return Post
189
     */
190
    public function setUrl($url)
191
    {
192
        $this->url = $url;
193

194
        return $this;
195
    }
196

197
    /**
198
     * Get url
199
     *
200
     * @return string
201
     */
202
    public function getUrl()
203
    {
204
        return $this->url;
205
    }
206

207
    /**
208
     * Set hide
209
     *
210
     * @param bool $hide
211
     *
212
     * @return Post
213
     */
214
    public function setHide($hide)
215
    {
216
        $this->hide = $hide;
217

218
        return $this;
219
    }
220

221
    /**
222
     * Get hide
223
     *
224
     * @return bool
225
     */
226
    public function isHide()
227
    {
228
        return $this->hide;
229
    }
230

231
    /**
232
     * Set text
233
     *
234
     * @param string $text
235
     *
236
     * @return Post
237
     */
238
    public function setText($text)
239
    {
240
        $this->text = $text;
241

242
        return $this;
243
    }
244

245
    /**
246
     * Get text
247
     *
248
     * @return string
249
     */
250
    public function getText()
251
    {
252
        return $this->text;
253
    }
254

255
    /**
256
     * Set description
257
     *
258
     * @param string $description
259
     *
260
     * @return Post
261
     */
262
    public function setDescription($description)
263
    {
264
        $this->description = $description;
265

266
        return $this;
267
    }
268

269
    /**
270
     * Get description
271
     *
272
     * @return string
273
     */
274
    public function getDescription()
275
    {
276
        return $this->description;
277
    }
278

279
    /**
280
     * Set category
281
     *
282
     * @param Category $category
283
     *
284
     * @return Post
285
     */
286
    public function setCategory(Category $category = null)
287
    {
288
        $this->category = $category;
289

290
        return $this;
291
    }
292

293
    /**
294
     * Get category
295
     *
296
     * @return Category
297
     */
298
    public function getCategory()
299
    {
300
        return $this->category;
301
    }
302

303
    /**
304
     * Add tag
305
     *
306
     * @param Tag $tag
307
     *
308
     * @return Post
309
     */
310
    public function addTag(Tag $tag)
311
    {
312
        if (!$this->tags->contains($tag)) {
313
            $this->tags->add($tag);
314
        }
315

316
        return $this;
317
    }
318

319
    /**
320
     * Remove tag
321
     *
322
     * @param Tag $tag
323
     */
324
    public function removeTag(Tag $tag)
325
    {
326
        $this->tags->removeElement($tag);
327
    }
328

329
    /**
330
     * Get tags
331
     *
332
     * @return Collection
333
     */
334
    public function getTags()
335
    {
336
        return $this->tags;
337
    }
338

339
    /**
340
     * Add comments
341
     *
342
     * @param Comment $comments
343
     *
344
     * @return Post
345
     */
346
    public function addComment(Comment $comments)
347
    {
348
        $this->comments[] = $comments;
349

350
        return $this;
351
    }
352

353
    /**
354
     * Remove comments
355
     *
356
     * @param Comment $comments
357
     */
358
    public function removeComment(Comment $comments)
359
    {
360
        $this->comments->removeElement($comments);
361
    }
362

363
    /**
364
     * Get comments
365
     *
366
     * @return Collection
367
     */
368
    public function getComments()
369
    {
370
        return $this->comments;
371
    }
372

373
    /**
374
     * Add mediaFile
375
     *
376
     * @param MediaFile $mediaFile
377
     *
378
     * @return Post
379
     */
380
    public function addMediaFile(MediaFile $mediaFile)
381
    {
382
        $this->mediaFiles[] = $mediaFile;
383

384
        return $this;
385
    }
386

387
    /**
388
     * Remove mediaFile
389
     *
390
     * @param MediaFile $mediaFile
391
     */
392
    public function removeMediaFile(MediaFile $mediaFile)
393
    {
394
        $this->mediaFiles->removeElement($mediaFile);
395
    }
396

397
    /**
398
     * Get mediaFiles
399
     *
400
     * @return Collection
401
     */
402
    public function getMediaFiles()
403
    {
404
        return $this->mediaFiles;
405
    }
406

407
    public function getDefaultImage(): ?MediaFile
408
    {
409
        $criteria = Criteria::create()
410
            ->andWhere(Criteria::expr()->eq('defaultImage', true))
411
        ;
412

413
        return $this->mediaFiles->matching($criteria)->first() ?: null;
414
    }
415

416
    /**
417
     * Set rawText
418
     *
419
     * @param string $rawText
420
     *
421
     * @return Post
422
     */
423
    public function setRawText($rawText)
424
    {
425
        $this->rawText = $rawText;
426

427
        return $this;
428
    }
429

430
    /**
431
     * Get rawText
432
     *
433
     * @return string
434
     */
435
    public function getRawText()
436
    {
437
        return $this->rawText;
438
    }
439

440
    /**
441
     * Set commentsCount
442
     *
443
     * @param int $commentsCount
444
     *
445
     * @return Post
446
     */
447
    public function setCommentsCount($commentsCount)
448
    {
449
        $this->commentsCount = $commentsCount;
450

451
        return $this;
452
    }
453

454
    /**
455
     * Get commentsCount
456
     *
457
     * @return int
458
     */
459
    public function getCommentsCount()
460
    {
461
        return $this->commentsCount;
462
    }
463

464
    /**
465
     * Set viewsCount
466
     *
467
     * @param int $viewsCount
468
     *
469
     * @return Post
470
     */
471
    public function setViewsCount($viewsCount)
472
    {
473
        $this->viewsCount = $viewsCount;
474

475
        return $this;
476
    }
477

478
    /**
479
     * Get viewsCount
480
     *
481
     * @return int
482
     */
483
    public function getViewsCount()
484
    {
485
        return $this->viewsCount;
486
    }
487

488
    /**
489
     * @return string
490
     */
491
    public function getPreview()
492
    {
493
        return $this->preview;
494
    }
495

496
    /**
497
     * @param string $preview
498
     *
499
     * @return Post
500
     */
501
    public function setPreview($preview): Post
502
    {
503
        $this->preview = $preview;
504

505
        return $this;
506
    }
507

508
    /**
509
     * @return DateTime
510
     */
511
    public function getUpdatedAt(): DateTime
512
    {
513
        return $this->updatedAt;
514
    }
515

516
    /**
517
     * @param DateTime $updatedAt
518
     *
519
     * @return Post
520
     */
521
    public function setUpdatedAt(DateTime $updatedAt): self
522
    {
523
        $this->updatedAt = $updatedAt;
524

525
        return $this;
526
    }
527

528
    /**
529
     * @return bool
530
     */
531
    public function isDisableComments(): bool
532
    {
533
        return $this->disableComments;
534
    }
535

536
    /**
537
     * @param bool $disableComments
538
     *
539
     * @return Post
540
     */
541
    public function setDisableComments(bool $disableComments): self
542
    {
543
        $this->disableComments = $disableComments;
544

545
        return $this;
546
    }
547
}
548

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

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

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

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