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\Common\Collections\Collection
;
15 use Doctrine\Common\Collections\ArrayCollection
;
16 use Doctrine\ORM\Event\PreUpdateEventArgs
;
30 private \DateTime
$created;
35 private \DateTime
$updated;
38 * @var \Rapsys\BlogBundle\Entity\User
43 * @var \Doctrine\Common\Collections\Collection
45 private Collection
$article_translations;
48 * @var \Doctrine\Common\Collections\Collection
50 private Collection
$keywords;
55 * @param \Rapsys\BlogBundle\Entity\User $user
57 public function __construct(User
$user) {
58 $this->created
= new \
DateTime('now');
59 $this->updated
= new \
DateTime('now');
61 $this->article_translations
= new ArrayCollection();
62 $this->keywords
= new ArrayCollection();
70 public function getId(): ?int {
77 * @param \DateTime $created
81 public function setCreated(\DateTime
$created): Article
{
82 $this->created
= $created;
92 public function getCreated(): \DateTime
{
93 return $this->created
;
99 * @param \DateTime $updated
103 public function setUpdated(\DateTime
$updated): Article
{
104 $this->updated
= $updated;
114 public function getUpdated(): \DateTime
{
115 return $this->updated
;
121 * @param \Rapsys\BlogBundle\Entity\User $user
125 public function setUser(User
$user): Article
{
134 * @return \Rapsys\BlogBundle\Entity\User
136 public function getUser(): User
{
141 * Add article translation
143 * @param \Rapsys\BlogBundle\Entity\ArticleTranslation $articleTranslation
147 public function addArticleTranslation(ArticleTranslation
$articleTranslation): Article
{
148 $this->article_translations
[] = $articleTranslation;
154 * Remove article translation
156 * @param \Rapsys\BlogBundle\Entity\ArticleTranslation $articleTranslation
158 * @return \Doctrine\Common\Collections\Collection
160 public function removeArticleTranslation(ArticleTranslation
$articleTranslation): Collection
{
161 return $this->article_translations
->removeElement($articleTranslation);
165 * Get article translations
167 * @return \Doctrine\Common\Collections\Collection
169 public function getArticleTranslations(): Collection
{
170 return $this->article_translations
;
176 * @param \Rapsys\BlogBundle\Entity\Keyword $keyword
180 public function addKeyword(Keyword
$keyword): Article
{
181 $this->keywords
[] = $keyword;
189 * @param \Rapsys\BlogBundle\Entity\Keyword $keyword
191 * @return \Doctrine\Common\Collections\Collection
193 public function removeKeyword(Keyword
$keyword): Collection
{
194 return $this->keywords
->removeElement($keyword);
200 * @return \Doctrine\Common\Collections\Collection
202 public function getKeywords(): Collection
{
203 return $this->keywords
;
209 public function preUpdate(PreUpdateEventArgs
$eventArgs): ?Article
{
210 //Check that we have an snippet instance
211 if (($entity = $eventArgs->getEntity()) instanceof Article
) {
213 return $entity->setUpdated(new \
DateTime('now'));