X-Git-Url: https://git.rapsys.eu/blogbundle/blobdiff_plain/9ad367710337f576ffa541975db98b0ace80bbce..c86e0d71f9c86536280d1706208e28f2346a0688:/Entity/ArticleTranslation.php diff --git a/Entity/ArticleTranslation.php b/Entity/ArticleTranslation.php index 8ca5c02..9d7b868 100644 --- a/Entity/ArticleTranslation.php +++ b/Entity/ArticleTranslation.php @@ -1,300 +1,267 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace Rapsys\BlogBundle\Entity; +use Doctrine\ORM\Event\PreUpdateEventArgs; + /** * ArticleTranslation */ -class ArticleTranslation -{ - /** - * @var integer - */ - private $article_id; - - /** - * @var integer - */ - private $language_id; - - /** - * @var string - */ - private $title; - - /** - * @var string - */ - private $description; - - /** - * @var string - */ - private $body; - - /** - * @var \DateTime - */ - private $created; - - /** - * @var \DateTime - */ - private $updated; - - /** - * @var \Rapsys\BlogBundle\Entity\Article - */ - private $article; - - /** - * @var \Rapsys\BlogBundle\Entity\Language - */ - private $language; - - - /** - * Set articleId - * - * @param integer $articleId - * - * @return ArticleTranslation - */ - public function setArticleId($articleId) - { - $this->article_id = $articleId; - - return $this; - } - - /** - * Get articleId - * - * @return integer - */ - public function getArticleId() - { - return $this->article_id; - } - - /** - * Set languageId - * - * @param integer $languageId - * - * @return ArticleTranslation - */ - public function setLanguageId($languageId) - { - $this->language_id = $languageId; - - return $this; - } - - /** - * Get languageId - * - * @return integer - */ - public function getLanguageId() - { - return $this->language_id; - } - - /** - * Set title - * - * @param string $title - * - * @return ArticleTranslation - */ - public function setTitle($title) - { - $this->title = $title; - - return $this; - } - - /** - * Get title - * - * @return string - */ - public function getTitle() - { - return $this->title; - } - - /** - * Set description - * - * @param string $description - * - * @return ArticleTranslation - */ - public function setDescription($description) - { - $this->description = $description; - - return $this; - } - - /** - * Get description - * - * @return string - */ - public function getDescription() - { - return $this->description; - } - - /** - * Set body - * - * @param string $body - * - * @return ArticleTranslation - */ - public function setBody($body) - { - $this->body = $body; - - return $this; - } - - /** - * Get body - * - * @return string - */ - public function getBody() - { - return $this->body; - } - - /** - * Set created - * - * @param \DateTime $created - * - * @return ArticleTranslation - */ - public function setCreated($created) - { - $this->created = $created; - - return $this; - } - - /** - * Get created - * - * @return \DateTime - */ - public function getCreated() - { - return $this->created; - } - - /** - * Set updated - * - * @param \DateTime $updated - * - * @return ArticleTranslation - */ - public function setUpdated($updated) - { - $this->updated = $updated; - - return $this; - } - - /** - * Get updated - * - * @return \DateTime - */ - public function getUpdated() - { - return $this->updated; - } - - /** - * Set article - * - * @param \Rapsys\BlogBundle\Entity\Article $article - * - * @return ArticleTranslation - */ - public function setArticle(\Rapsys\BlogBundle\Entity\Article $article = null) - { - $this->article = $article; - - return $this; - } - - /** - * Get article - * - * @return \Rapsys\BlogBundle\Entity\Article - */ - public function getArticle() - { - return $this->article; - } - - /** - * Set language - * - * @param \Rapsys\BlogBundle\Entity\Language $language - * - * @return ArticleTranslation - */ - public function setLanguage(\Rapsys\BlogBundle\Entity\Language $language = null) - { - $this->language = $language; - - return $this; - } - - /** - * Get language - * - * @return \Rapsys\BlogBundle\Entity\Language - */ - public function getLanguage() - { - return $this->language; - } - /** - * @var string - */ - private $slug; - - - /** - * Set slug - * - * @param string $slug - * - * @return ArticleTranslation - */ - public function setSlug($slug) - { - $this->slug = $slug; - - return $this; - } - - /** - * Get slug - * - * @return string - */ - public function getSlug() - { - return $this->slug; - } +class ArticleTranslation { + /** + * @var int + */ + private int $article_id; + + /** + * @var string + */ + private string $locale; + + /** + * @var ?string + */ + private ?string $body; + + /** + * @var ?string + */ + private ?string $description; + + /** + * @var ?string + */ + private ?string $slug; + + /** + * @var ?string + */ + private ?string $title; + + /** + * @var \DateTime + */ + private \DateTime $created; + + /** + * @var \DateTime + */ + private \DateTime $updated; + + /** + * @var \Rapsys\BlogBundle\Entity\Article + */ + private Article $article; + + /** + * Constructor + */ + public function __construct(Article $article, string $locale, ?string $body = null, ?string $description = null, ?string $slug = null, ?string $title = null) { + //Set defaults + $this->locale = $locale; + $this->body = $body; + $this->description = $description; + $this->slug = $slug; + $this->title = $title; + $this->created = new \DateTime('now'); + $this->updated = new \DateTime('now'); + $this->setArticle($article); + } + + /** + * Get locale + * + * @return string + */ + public function getLocale(): string { + return $this->locale; + } + + /** + * Set locale + * + * @param string $locale + * + * @return ArticleTranslation + */ + public function setLocale(string $locale): ArticleTranslation { + $this->locale = $locale; + + return $this; + } + + /** + * Get body + * + * @return ?string + */ + public function getBody(): ?string { + return $this->body; + } + + /** + * Set body + * + * @param ?string $body + * + * @return ArticleTranslation + */ + public function setBody(?string $body): ArticleTranslation { + $this->body = $body; + + return $this; + } + + /** + * Get description + * + * @return ?string + */ + public function getDescription(): ?string { + return $this->description; + } + + /** + * Set description + * + * @param ?string $description + * + * @return ArticleTranslation + */ + public function setDescription(?string $description): ArticleTranslation { + $this->description = $description; + + return $this; + } + + /** + * Get slug + * + * @return ?string + */ + public function getSlug(): ?string { + return $this->slug; + } + + /** + * Set slug + * + * @param ?string $slug + * + * @return ArticleTranslation + */ + public function setSlug(?string $slug): ArticleTranslation { + $this->slug = $slug; + + return $this; + } + + /** + * Get title + * + * @return ?string + */ + public function getTitle(): ?string { + return $this->title; + } + + /** + * Set title + * + * @param ?string $title + * + * @return ArticleTranslation + */ + public function setTitle(?string $title): ArticleTranslation { + $this->title = $title; + + return $this; + } + + /** + * Get created + * + * @return \DateTime + */ + public function getCreated(): \DateTime { + return $this->created; + } + + /** + * Set created + * + * @param \DateTime $created + * + * @return ArticleTranslation + */ + public function setCreated(\DateTime $created): ArticleTranslation { + $this->created = $created; + + return $this; + } + + /** + * Get updated + * + * @return \DateTime + */ + public function getUpdated(): \DateTime { + return $this->updated; + } + + /** + * Set updated + * + * @param \DateTime $updated + * + * @return ArticleTranslation + */ + public function setUpdated(\DateTime $updated): ArticleTranslation { + $this->updated = $updated; + + return $this; + } + + /** + * Get article + * + * @return \Rapsys\BlogBundle\Entity\Article + */ + public function getArticle(): Article { + return $this->article; + } + + /** + * Set article + * + * @param \Rapsys\BlogBundle\Entity\Article $article + * + * @return ArticleTranslation + */ + public function setArticle(Article $article): ArticleTranslation { + $this->article = $article; + $this->article_id = $article->getId(); + + return $this; + } + + /** + * {@inheritdoc} + */ + public function preUpdate(PreUpdateEventArgs $eventArgs): ?ArticleTranslation { + //Check that we have an snippet instance + if (($entity = $eventArgs->getEntity()) instanceof ArticleTranslation) { + //Set updated value + return $entity->setUpdated(new \DateTime('now')); + } + } }