]> Raphaël G. Git Repositories - blogbundle/blob - Entity/KeywordTranslation.php
Add user translation entity
[blogbundle] / Entity / KeywordTranslation.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 * KeywordTranslation
18 */
19 class KeywordTranslation {
20 /**
21 * @var int
22 */
23 private int $keyword_id;
24
25 /**
26 * @var string
27 */
28 private string $locale;
29
30 /**
31 * @var ?string
32 */
33 private ?string $description;
34
35 /**
36 * @var ?string
37 */
38 private ?string $slug;
39
40 /**
41 * @var ?string
42 */
43 private ?string $title;
44
45 /**
46 * @var \DateTime
47 */
48 private \DateTime $created;
49
50 /**
51 * @var \DateTime
52 */
53 private \DateTime $updated;
54
55 /**
56 * @var \Rapsys\BlogBundle\Entity\Keyword
57 */
58 private Keyword $keyword;
59
60 /**
61 * Constructor
62 */
63 public function __construct(Keyword $keyword, string $locale, ?string $description = null, ?string $slug = null, ?string $title = null) {
64 //Set defaults
65 $this->locale = $locale;
66 $this->description = $description;
67 $this->slug = $slug;
68 $this->title = $title;
69 $this->created = new \DateTime('now');
70 $this->updated = new \DateTime('now');
71 $this->setKeyword($keyword);
72 }
73
74 /**
75 * Get locale
76 *
77 * @return string
78 */
79 public function getLocale(): string {
80 return $this->locale;
81 }
82
83 /**
84 * Set locale
85 *
86 * @param string $locale
87 *
88 * @return KeywordTranslation
89 */
90 public function setLocale(string $locale): KeywordTranslation {
91 $this->locale = $locale;
92
93 return $this;
94 }
95
96 /**
97 * Get description
98 *
99 * @return ?string
100 */
101 public function getDescription(): ?string {
102 return $this->description;
103 }
104
105 /**
106 * Set description
107 *
108 * @param ?string $description
109 *
110 * @return KeywordTranslation
111 */
112 public function setDescription(?string $description): KeywordTranslation {
113 $this->description = $description;
114
115 return $this;
116 }
117
118 /**
119 * Get slug
120 *
121 * @return ?string
122 */
123 public function getSlug(): ?string {
124 return $this->slug;
125 }
126
127 /**
128 * Set slug
129 *
130 * @param ?string $slug
131 *
132 * @return KeywordTranslation
133 */
134 public function setSlug(?string $slug): KeywordTranslation {
135 $this->slug = $slug;
136
137 return $this;
138 }
139
140 /**
141 * Get title
142 *
143 * @return ?string
144 */
145 public function getTitle(): ?string {
146 return $this->title;
147 }
148
149 /**
150 * Set title
151 *
152 * @param ?string $title
153 *
154 * @return KeywordTranslation
155 */
156 public function setTitle(?string $title): KeywordTranslation {
157 $this->title = $title;
158
159 return $this;
160 }
161
162 /**
163 * Get created
164 *
165 * @return \DateTime
166 */
167 public function getCreated(): \DateTime {
168 return $this->created;
169 }
170
171 /**
172 * Set created
173 *
174 * @param \DateTime $created
175 *
176 * @return KeywordTranslation
177 */
178 public function setCreated(\DateTime $created): KeywordTranslation {
179 $this->created = $created;
180
181 return $this;
182 }
183
184 /**
185 * Get updated
186 *
187 * @return \DateTime
188 */
189 public function getUpdated(): \DateTime {
190 return $this->updated;
191 }
192
193 /**
194 * Set updated
195 *
196 * @param \DateTime $updated
197 *
198 * @return KeywordTranslation
199 */
200 public function setUpdated(\DateTime $updated): KeywordTranslation {
201 $this->updated = $updated;
202
203 return $this;
204 }
205
206 /**
207 * Get keyword
208 *
209 * @return \Rapsys\BlogBundle\Entity\Keyword
210 */
211 public function getKeyword(): Keyword {
212 return $this->keyword;
213 }
214
215 /**
216 * Set keyword
217 *
218 * @param \Rapsys\BlogBundle\Entity\Keyword $keyword
219 *
220 * @return KeywordTranslation
221 */
222 public function setKeyword(Keyword $keyword): KeywordTranslation {
223 $this->keyword = $keyword;
224 $this->keyword_id = $keyword->getId();
225
226 return $this;
227 }
228
229 /**
230 * {@inheritdoc}
231 */
232 public function preUpdate(PreUpdateEventArgs $eventArgs): ?KeywordTranslation {
233 //Check that we have an snippet instance
234 if (($entity = $eventArgs->getEntity()) instanceof KeywordTranslation) {
235 //Set updated value
236 return $entity->setUpdated(new \DateTime('now'));
237 }
238 }
239 }