]> Raphaël G. Git Repositories - blogbundle/blob - Entity/UserTranslation.php
Add validators translations
[blogbundle] / Entity / UserTranslation.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 * UserTranslation
18 */
19 class UserTranslation {
20 /**
21 * @var int
22 */
23 private int $user_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 \DateTime
37 */
38 private \DateTime $created;
39
40 /**
41 * @var \DateTime
42 */
43 private \DateTime $updated;
44
45 /**
46 * @var \Rapsys\BlogBundle\Entity\User
47 */
48 private User $user;
49
50 /**
51 * Constructor
52 */
53 public function __construct(User $user, string $locale, ?string $description = null) {
54 //Set defaults
55 $this->locale = $locale;
56 $this->description = $description;
57 $this->created = new \DateTime('now');
58 $this->updated = new \DateTime('now');
59 $this->setUser($user);
60 }
61
62 /**
63 * Get locale
64 *
65 * @return string
66 */
67 public function getLocale(): string {
68 return $this->locale;
69 }
70
71 /**
72 * Set locale
73 *
74 * @param string $locale
75 *
76 * @return UserTranslation
77 */
78 public function setLocale(string $locale): UserTranslation {
79 $this->locale = $locale;
80
81 return $this;
82 }
83
84 /**
85 * Get description
86 *
87 * @return ?string
88 */
89 public function getDescription(): ?string {
90 return $this->description;
91 }
92
93 /**
94 * Set description
95 *
96 * @param ?string $description
97 *
98 * @return UserTranslation
99 */
100 public function setDescription(?string $description): UserTranslation {
101 $this->description = $description;
102
103 return $this;
104 }
105
106 /**
107 * Get created
108 *
109 * @return \DateTime
110 */
111 public function getCreated(): \DateTime {
112 return $this->created;
113 }
114
115 /**
116 * Set created
117 *
118 * @param \DateTime $created
119 *
120 * @return UserTranslation
121 */
122 public function setCreated(\DateTime $created): UserTranslation {
123 $this->created = $created;
124
125 return $this;
126 }
127
128 /**
129 * Get updated
130 *
131 * @return \DateTime
132 */
133 public function getUpdated(): \DateTime {
134 return $this->updated;
135 }
136
137 /**
138 * Set updated
139 *
140 * @param \DateTime $updated
141 *
142 * @return UserTranslation
143 */
144 public function setUpdated(\DateTime $updated): UserTranslation {
145 $this->updated = $updated;
146
147 return $this;
148 }
149
150 /**
151 * Get user
152 *
153 * @return \Rapsys\BlogBundle\Entity\User
154 */
155 public function getUser(): User {
156 return $this->user;
157 }
158
159 /**
160 * Set user
161 *
162 * @param \Rapsys\BlogBundle\Entity\User $user
163 *
164 * @return UserTranslation
165 */
166 public function setUser(User $user): UserTranslation {
167 $this->user = $user;
168 $this->user_id = $user->getId();
169
170 return $this;
171 }
172
173 /**
174 * {@inheritdoc}
175 */
176 public function preUpdate(PreUpdateEventArgs $eventArgs): ?UserTranslation {
177 //Check that we have an snippet instance
178 if (($entity = $eventArgs->getEntity()) instanceof UserTranslation) {
179 //Set updated value
180 return $entity->setUpdated(new \DateTime('now'));
181 }
182 }
183 }