]> Raphaël G. Git Repositories - blogbundle/blob - Entity/ArticleTranslation.php
Cleanup flash message
[blogbundle] / Entity / ArticleTranslation.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys BlogBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Rapsys\BlogBundle\Entity;
13
14 use Doctrine\ORM\Event\PreUpdateEventArgs;
15
16 /**
17 * ArticleTranslation
18 */
19 class ArticleTranslation {
20 /**
21 * @var int
22 */
23 private int $article_id;
24
25 /**
26 * @var string
27 */
28 private string $locale;
29
30 /**
31 * @var ?string
32 */
33 private ?string $body;
34
35 /**
36 * @var ?string
37 */
38 private ?string $description;
39
40 /**
41 * @var ?string
42 */
43 private ?string $slug;
44
45 /**
46 * @var ?string
47 */
48 private ?string $title;
49
50 /**
51 * @var \DateTime
52 */
53 private \DateTime $created;
54
55 /**
56 * @var \DateTime
57 */
58 private \DateTime $updated;
59
60 /**
61 * @var \Rapsys\BlogBundle\Entity\Article
62 */
63 private Article $article;
64
65 /**
66 * Constructor
67 */
68 public function __construct(Article $article, string $locale, ?string $body = null, ?string $description = null, ?string $slug = null, ?string $title = null) {
69 //Set defaults
70 $this->locale = $locale;
71 $this->body = $body;
72 $this->description = $description;
73 $this->slug = $slug;
74 $this->title = $title;
75 $this->created = new \DateTime('now');
76 $this->updated = new \DateTime('now');
77 $this->setArticle($article);
78 }
79
80 /**
81 * Get locale
82 *
83 * @return string
84 */
85 public function getLocale(): string {
86 return $this->locale;
87 }
88
89 /**
90 * Set locale
91 *
92 * @param string $locale
93 *
94 * @return ArticleTranslation
95 */
96 public function setLocale(string $locale): ArticleTranslation {
97 $this->locale = $locale;
98
99 return $this;
100 }
101
102 /**
103 * Get body
104 *
105 * @return ?string
106 */
107 public function getBody(): ?string {
108 return $this->body;
109 }
110
111 /**
112 * Set body
113 *
114 * @param ?string $body
115 *
116 * @return ArticleTranslation
117 */
118 public function setBody(?string $body): ArticleTranslation {
119 $this->body = $body;
120
121 return $this;
122 }
123
124 /**
125 * Get description
126 *
127 * @return ?string
128 */
129 public function getDescription(): ?string {
130 return $this->description;
131 }
132
133 /**
134 * Set description
135 *
136 * @param ?string $description
137 *
138 * @return ArticleTranslation
139 */
140 public function setDescription(?string $description): ArticleTranslation {
141 $this->description = $description;
142
143 return $this;
144 }
145
146 /**
147 * Get slug
148 *
149 * @return ?string
150 */
151 public function getSlug(): ?string {
152 return $this->slug;
153 }
154
155 /**
156 * Set slug
157 *
158 * @param ?string $slug
159 *
160 * @return ArticleTranslation
161 */
162 public function setSlug(?string $slug): ArticleTranslation {
163 $this->slug = $slug;
164
165 return $this;
166 }
167
168 /**
169 * Get title
170 *
171 * @return ?string
172 */
173 public function getTitle(): ?string {
174 return $this->title;
175 }
176
177 /**
178 * Set title
179 *
180 * @param ?string $title
181 *
182 * @return ArticleTranslation
183 */
184 public function setTitle(?string $title): ArticleTranslation {
185 $this->title = $title;
186
187 return $this;
188 }
189
190 /**
191 * Get created
192 *
193 * @return \DateTime
194 */
195 public function getCreated(): \DateTime {
196 return $this->created;
197 }
198
199 /**
200 * Set created
201 *
202 * @param \DateTime $created
203 *
204 * @return ArticleTranslation
205 */
206 public function setCreated(\DateTime $created): ArticleTranslation {
207 $this->created = $created;
208
209 return $this;
210 }
211
212 /**
213 * Get updated
214 *
215 * @return \DateTime
216 */
217 public function getUpdated(): \DateTime {
218 return $this->updated;
219 }
220
221 /**
222 * Set updated
223 *
224 * @param \DateTime $updated
225 *
226 * @return ArticleTranslation
227 */
228 public function setUpdated(\DateTime $updated): ArticleTranslation {
229 $this->updated = $updated;
230
231 return $this;
232 }
233
234 /**
235 * Get article
236 *
237 * @return \Rapsys\BlogBundle\Entity\Article
238 */
239 public function getArticle(): Article {
240 return $this->article;
241 }
242
243 /**
244 * Set article
245 *
246 * @param \Rapsys\BlogBundle\Entity\Article $article
247 *
248 * @return ArticleTranslation
249 */
250 public function setArticle(Article $article): ArticleTranslation {
251 $this->article = $article;
252 $this->article_id = $article->getId();
253
254 return $this;
255 }
256
257 /**
258 * {@inheritdoc}
259 */
260 public function preUpdate(PreUpdateEventArgs $eventArgs): ?ArticleTranslation {
261 //Check that we have an snippet instance
262 if (($entity = $eventArgs->getEntity()) instanceof ArticleTranslation) {
263 //Set updated value
264 return $entity->setUpdated(new \DateTime('now'));
265 }
266 }
267 }