|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace App\Entity; |
|
6
|
|
|
|
|
7
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
8
|
|
|
use Doctrine\Common\Collections\Collection; |
|
9
|
|
|
use Doctrine\ORM\Mapping as ORM; |
|
10
|
|
|
use Gedmo\Mapping\Annotation as Gedmo; |
|
11
|
|
|
use Gedmo\Timestampable\Traits\TimestampableEntity; |
|
12
|
|
|
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; |
|
13
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @ORM\Entity(repositoryClass="App\Repository\ArticleRepository") |
|
17
|
|
|
* @ORM\Table(name="rw_article") |
|
18
|
|
|
* |
|
19
|
|
|
* @UniqueEntity("slug") |
|
20
|
|
|
*/ |
|
21
|
|
|
class Article |
|
22
|
|
|
{ |
|
23
|
|
|
use TimestampableEntity; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @ORM\Id() |
|
27
|
|
|
* @ORM\GeneratedValue() |
|
28
|
|
|
* @ORM\Column(type="integer") |
|
29
|
|
|
*/ |
|
30
|
|
|
private ?int $id = null; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @ORM\Column(type="string", length=255) |
|
34
|
|
|
* @Assert\NotBlank(message="article.title.not_blank") |
|
35
|
|
|
*/ |
|
36
|
|
|
private ?string $title = null; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @ORM\Column(type="string", length=255, unique=true) |
|
40
|
|
|
* @Gedmo\Slug(fields={"title"}, updatable=true, unique=true) |
|
41
|
|
|
*/ |
|
42
|
|
|
private ?string $slug = null; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @ORM\Column(type="text") |
|
46
|
|
|
* @Assert\NotBlank(message="article.description.not_blank") |
|
47
|
|
|
*/ |
|
48
|
|
|
private ?string $description = null; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @ORM\Column(type="text") |
|
52
|
|
|
* @Assert\NotBlank(message="article.body.not_blank") |
|
53
|
|
|
*/ |
|
54
|
|
|
private ?string $body = null; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @ORM\ManyToOne(targetEntity="App\Entity\User") |
|
58
|
|
|
*/ |
|
59
|
|
|
private ?User $author = null; |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* @var Collection|Tag[] |
|
63
|
|
|
* |
|
64
|
|
|
* @ORM\ManyToMany(targetEntity="App\Entity\Tag", cascade={"persist"}) |
|
65
|
|
|
* @ORM\JoinTable(name="rw_article_tag") |
|
66
|
|
|
*/ |
|
67
|
|
|
private Collection $tags; |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @var Collection|User[] |
|
71
|
|
|
* |
|
72
|
|
|
* @ORM\ManyToMany(targetEntity="App\Entity\User", mappedBy="favorites", fetch="EXTRA_LAZY") |
|
73
|
|
|
*/ |
|
74
|
|
|
private Collection $favoritedBy; |
|
75
|
|
|
|
|
76
|
3 |
|
public function __construct() |
|
77
|
|
|
{ |
|
78
|
3 |
|
$this->tags = new ArrayCollection(); |
|
79
|
3 |
|
$this->favoritedBy = new ArrayCollection(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function __toString(): string |
|
83
|
|
|
{ |
|
84
|
|
|
return sprintf('%s', $this->title); |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
public function getId(): ?int |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->id; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
14 |
|
public function getTitle(): ?string |
|
93
|
|
|
{ |
|
94
|
14 |
|
return $this->title; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
3 |
|
public function setTitle(?string $title): void |
|
98
|
|
|
{ |
|
99
|
3 |
|
$this->title = $title; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
12 |
|
public function getSlug(): ?string |
|
103
|
|
|
{ |
|
104
|
12 |
|
return $this->slug; |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function setSlug(?string $slug): void |
|
108
|
|
|
{ |
|
109
|
|
|
$this->slug = $slug; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
14 |
|
public function getDescription(): ?string |
|
113
|
|
|
{ |
|
114
|
14 |
|
return $this->description; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
2 |
|
public function setDescription(?string $description): void |
|
118
|
|
|
{ |
|
119
|
2 |
|
$this->description = $description; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
14 |
|
public function getBody(): ?string |
|
123
|
|
|
{ |
|
124
|
14 |
|
return $this->body; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
1 |
|
public function setBody(?string $body): void |
|
128
|
|
|
{ |
|
129
|
1 |
|
$this->body = $body; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
16 |
|
public function getAuthor(): ?User |
|
133
|
|
|
{ |
|
134
|
16 |
|
return $this->author; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
2 |
|
public function setAuthor(?User $author): void |
|
138
|
|
|
{ |
|
139
|
2 |
|
$this->author = $author; |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* @return Collection|Tag[] |
|
144
|
|
|
*/ |
|
145
|
14 |
|
public function getTags(): Collection |
|
146
|
|
|
{ |
|
147
|
14 |
|
return $this->tags; |
|
148
|
|
|
} |
|
149
|
|
|
|
|
150
|
|
|
/** |
|
151
|
|
|
* @param Collection|Tag[] $tags |
|
152
|
|
|
*/ |
|
153
|
2 |
|
public function setTags(Collection $tags): void |
|
154
|
|
|
{ |
|
155
|
2 |
|
$this->tags = $tags; |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* @return Collection|User[] |
|
160
|
|
|
*/ |
|
161
|
|
|
public function getFavoritedBy(): Collection |
|
162
|
|
|
{ |
|
163
|
|
|
return $this->favoritedBy; |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
12 |
|
public function getFavoritedByCount(): int |
|
167
|
|
|
{ |
|
168
|
12 |
|
return $this->favoritedBy->count(); |
|
169
|
|
|
} |
|
170
|
|
|
} |
|
171
|
|
|
|