1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Entity; |
4
|
|
|
|
5
|
|
|
use DateTimeInterface; |
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
7
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
8
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\CommentRepository") |
12
|
|
|
*/ |
13
|
|
|
class Comment extends AbstractAppEntity |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
const NUMBER_OF_DISPLAYED_COMMENTS = 8; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @ORM\Id() |
20
|
|
|
* @ORM\GeneratedValue() |
21
|
|
|
* @ORM\Column(type="integer") |
22
|
|
|
*/ |
23
|
|
|
private $id; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @ORM\Column(type="text") |
27
|
|
|
* @Assert\NotBlank |
28
|
|
|
* @Assert\NotNull |
29
|
|
|
*/ |
30
|
|
|
private $comment; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @ORM\Column(type="datetime") |
34
|
|
|
* @Gedmo\Timestampable(on="create") |
35
|
|
|
*/ |
36
|
|
|
private $createdAt; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\Trick", inversedBy="comments") |
40
|
|
|
* @ORM\JoinColumn(onDelete="CASCADE") |
41
|
|
|
*/ |
42
|
|
|
private $trick; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="comments") |
46
|
|
|
* @ORM\JoinColumn(onDelete="CASCADE") |
47
|
|
|
*/ |
48
|
|
|
private $user; |
49
|
|
|
|
50
|
|
|
public function getId(): ?int |
51
|
|
|
{ |
52
|
|
|
return $this->id; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function getComment(): ?string |
56
|
|
|
{ |
57
|
|
|
return $this->comment; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function setComment(string $comment): self |
61
|
|
|
{ |
62
|
|
|
$this->comment = $comment; |
63
|
|
|
|
64
|
|
|
return $this; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function getCreatedAt(): ?DateTimeInterface |
68
|
|
|
{ |
69
|
|
|
return $this->createdAt; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function setCreatedAt(DateTimeInterface $createdAt): self |
73
|
|
|
{ |
74
|
|
|
$this->createdAt = $createdAt; |
75
|
|
|
|
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function getTrick(): ?Trick |
80
|
|
|
{ |
81
|
|
|
return $this->trick; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function setTrick(?Trick $trick): self |
85
|
|
|
{ |
86
|
|
|
$this->trick = $trick; |
87
|
|
|
|
88
|
|
|
return $this; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
public function getUser(): ?User |
92
|
|
|
{ |
93
|
|
|
return $this->user; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function setUser(?User $user): self |
97
|
|
|
{ |
98
|
|
|
$this->user = $user; |
99
|
|
|
|
100
|
|
|
return $this; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
public function getCommentExcerpt(){ |
104
|
|
|
return implode(' ', array_slice(explode(' ', $this->getComment()), 0, 10))." ..."; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function __toString() |
108
|
|
|
{ |
109
|
|
|
return $this->getCommentExcerpt(); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
} |
113
|
|
|
|