1 <?php
declare(strict_types
=1);
4 * This file is part of the Rapsys BlogBundle package.
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Rapsys\BlogBundle\Entity
;
14 use Doctrine\ORM\Event\PreUpdateEventArgs
;
19 class ArticleTranslation
{
23 private int $article_id;
28 private string $locale;
33 private ?string $body;
38 private ?string $description;
43 private ?string $slug;
48 private ?string $title;
53 private \DateTime
$created;
58 private \DateTime
$updated;
61 * @var \Rapsys\BlogBundle\Entity\Article
63 private Article
$article;
68 public function __construct(Article
$article, string $locale, ?string $body = null, ?string $description = null, ?string $slug = null, ?string $title = null) {
70 $this->locale
= $locale;
72 $this->description
= $description;
74 $this->title
= $title;
75 $this->created
= new \
DateTime('now');
76 $this->updated
= new \
DateTime('now');
77 $this->setArticle($article);
85 public function getLocale(): string {
92 * @param string $locale
94 * @return ArticleTranslation
96 public function setLocale(string $locale): ArticleTranslation
{
97 $this->locale
= $locale;
107 public function getBody(): ?string {
114 * @param ?string $body
116 * @return ArticleTranslation
118 public function setBody(?string $body): ArticleTranslation
{
129 public function getDescription(): ?string {
130 return $this->description
;
136 * @param ?string $description
138 * @return ArticleTranslation
140 public function setDescription(?string $description): ArticleTranslation
{
141 $this->description
= $description;
151 public function getSlug(): ?string {
158 * @param ?string $slug
160 * @return ArticleTranslation
162 public function setSlug(?string $slug): ArticleTranslation
{
173 public function getTitle(): ?string {
180 * @param ?string $title
182 * @return ArticleTranslation
184 public function setTitle(?string $title): ArticleTranslation
{
185 $this->title
= $title;
195 public function getCreated(): \DateTime
{
196 return $this->created
;
202 * @param \DateTime $created
204 * @return ArticleTranslation
206 public function setCreated(\DateTime
$created): ArticleTranslation
{
207 $this->created
= $created;
217 public function getUpdated(): \DateTime
{
218 return $this->updated
;
224 * @param \DateTime $updated
226 * @return ArticleTranslation
228 public function setUpdated(\DateTime
$updated): ArticleTranslation
{
229 $this->updated
= $updated;
237 * @return \Rapsys\BlogBundle\Entity\Article
239 public function getArticle(): Article
{
240 return $this->article
;
246 * @param \Rapsys\BlogBundle\Entity\Article $article
248 * @return ArticleTranslation
250 public function setArticle(Article
$article): ArticleTranslation
{
251 $this->article
= $article;
252 $this->article_id
= $article->getId();
260 public function preUpdate(PreUpdateEventArgs
$eventArgs): ?ArticleTranslation
{
261 //Check that we have an snippet instance
262 if (($entity = $eventArgs->getEntity()) instanceof ArticleTranslation
) {
264 return $entity->setUpdated(new \
DateTime('now'));